phpmqmsgque 9.0
Loading...
Searching...
No Matches
Example: Filter6

Documentation of the Filter6 tool used for trans2.test.

INTRODUCTION

The Filer6 tool is used to test the filter-feature of phpmqmsgque.

To run the filter test, a first client, one or more filters and a final server are created. All are connected to the phpmqmsgque protocol.

The trans2.test carries out common filter tests and special stress tests. A stress test is performed by exiting one or more filters or servers and observing the response and behavior when reconnecting.

The GOAL for this test is:

CODE filter

<?php
#+
#:   @file         example/php/Filter6.php
#:   @brief        Filter6.php - 20 Oct 2022 - aotto1968
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permissions to copy,
#:                 please contact AUTHOR for additional information
#:   @version      eca2a2ee05f368470d4127d36503bd9e26063147
#:   @date         Thu Oct 20 14:18:44 2022 +0200
#:   @author       aotto1968 <aotto1968@t-online.de>
#:

#$stderr = fopen("php://stderr", "w");
use PhpMsgque\MqMsgque as mq;
use PhpMsgque\MkKernel as mk;

class Filter6 extends mq\MqContextC implements mq\iServerSetup, mq\iServerCleanup, mq\iEvent {
  private $fh = NULL;

  public function __construct($tmpl=NULL) {
    parent::__construct($tmpl);
    $this->ConfigSetIgnoreExit(TRUE);
  }
  ## [filter_service_example]
  public function ServerSetup() {
    $ftr = $this->SlaveGetFilter();
    $this->ServiceCreate(   "LOGF", 'LOGF');
    $this->ServiceCreate(   "EXIT", 'EXITx');
    $this->ServiceCreate(   "SOEX", 'SOEX');
    $this->ServiceCreate(   "+ALL", 'FilterIn');
    $this->ServiceStorage(  "PRNT");
    $this->ServiceStorage(  "PRN2");
    $ftr->ServiceCreate(    "WRIT", array("Filter6" , 'WRIT'));
    $this->ServiceCreate(   "WRIT", array("Filter6" , 'WRIT'));
    $ftr->ServiceProxy(     "WRT2", mq\MqSlaveE::MASTER->value);
  }
  ## [filter_service_example]
  public function ServerCleanup() {
    if ($this->fh != NULL) {
      $this->fh->Dispose();
    }
    $this->fh = NULL;
  }
  public function ErrorWrite() {
    $err = $this->ErrorDEFAULT();
    $this->fh->WriteC("ERROR: " . $err->GetText());
    $err->Reset();
  }
  public function LOGF() {
    $ftr = $this->SlaveGetFilter();
    if (preg_match("/^(?:Filter6-1|Filter6|fs1.*)$/",$ftr->ConfigGetName())) {
      $this->fh = mk\MkLogFileC::Open($this,$this->ReadC());
    } else {
      $this->ProxyForward($ftr);
    }
    $this->SendRETURN();
  }
  public static function WRIT($ctx) {
    $master = $ctx->SlaveGetMaster();
    if (preg_match("/^(?:Filter6-1|Filter6|fs1.*)$/",$master->ConfigGetName())) {
      $master->fh->WriteC($ctx->ReadC());
    } else {
      $ctx->ProxyForward($master);
    }
    $ctx->SendRETURN();
  }
  public function EXITx() {
    #exit(1);
    $this->Exit();
  }
  public function SOEX() {
    $this->ErrorDEFAULT()->SetEXIT();
  }
  public function FilterIn() {
    $this->StorageExport();
    $this->SendRETURN();
  }
  public function Event() {
    if ($this->StorageCount() == 0) {
      $this->ErrorDEFAULT()->SetCONTINUE();
    } else {
      $id = 0;
      try {
	$ftr = $this->SlaveGetFilter();
        $ftr->LinkConnect();
	$id = $this->StorageImport();
        try {
          $this->ProxyForward($ftr);
        } catch (mk\MkExceptionC $ex) {
          if ($this->StorageErrCnt($id) < 3) {
            $this->StorageDecrRef($id);
            return;
          } else {
            throw $ex;
          }
        }
      } catch (Throwable $ex) {
        $this->ErrorCatch($ex);
        $this->ErrorWrite();
      }
      $this->StorageDelete($id);
    }
  }
}

# [error_example]
$srv = mq\MqFactoryC::Add('Filter6')->New();
try {
  $srv->LinkCreate($argv);
  $srv->ProcessEvent(mq\MqWaitOnEventE::FOREVER);
} catch (Throwable $ex) {
  $srv->ErrorCatch($ex);
} finally {
  $srv->Exit();
}
# [error_example]

?>