Наследование: extends Thruway\Peer\AbstractPeer, implements Evenement\EventEmitterInterface, use trait Evenement\EventEmitterTrait
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         echo "Making a go at starting a Thruway worker.\n";
         $name = $input->getArgument('name');
         $config = $this->getContainer()->getParameter('voryx_thruway');
         $loop = $this->getContainer()->get('voryx.thruway.loop');
         $kernel = $this->getContainer()->get('wamp_kernel');
         $workerAnnotation = $kernel->getResourceMapper()->getWorkerAnnotation($name);
         if ($workerAnnotation) {
             $realm = $workerAnnotation->getRealm() ?: $config['realm'];
             $url = $workerAnnotation->getUrl() ?: $config['url'];
         } else {
             $realm = $config['realm'];
             $url = $config['url'];
         }
         $transport = new PawlTransportProvider($url);
         $client = new Client($realm, $loop);
         $client->addTransportProvider($transport);
         $kernel->setProcessName($name);
         $kernel->setClient($client);
         $kernel->setProcessInstance($input->getArgument('instance'));
         $client->start();
     } catch (\Exception $e) {
         $logger = $this->getContainer()->get('logger');
         $logger->addCritical("EXCEPTION:" . $e->getMessage());
         $output->writeln("EXCEPTION:" . $e->getMessage());
     }
 }
Пример #2
0
 function __construct($realm = null)
 {
     if ($realm) {
         $this->realm = $realm;
     }
     parent::__construct($this->realm);
 }
Пример #3
0
 protected function createTestRouter()
 {
     $this->assertNull($this->router);
     $this->router = new Router(\EventLoop\getLoop());
     // create a client that records all publish events
     $this->recordedEvents = [];
     $this->eventClient = new Client("test_realm", \EventLoop\getLoop());
     $this->eventClient->on('open', function (ClientSession $session) {
         $session->subscribe("wamppost.tests.", function ($args, $argsKw, $details, $pubId) {
             $eventMessage = new EventMessage(0, $pubId, $details, $args, $argsKw, $details->topic);
             array_push($this->recordedEvents, $eventMessage);
         }, (object) ["match" => "prefix"]);
     });
     $this->router->addInternalClient($this->eventClient);
     return $this->router;
 }
Пример #4
0
 /**
  * @param string $realm
  * @param null $loop
  */
 function __construct($realm, $loop = null)
 {
     parent::__construct($realm, $loop);
     $this->setReady(false);
     $this->rules = [];
     $this->flushAuthorizationRules();
 }
Пример #5
0
 /**
  * Start the transport
  *
  * @param boolean $startLoop
  * @throws \Exception
  */
 public function start($debug = false, $startLoop = true)
 {
     if (!$debug) {
         Logger::set(new NullLogger());
     }
     parent::start($startLoop);
 }
Пример #6
0
 /**
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('add_command', [$this, 'addCommand']);
     $session->register('status', [$this, 'status']);
     $session->register('start_process', [$this, 'startProcess']);
     $session->register('stop_process', [$this, 'stopProcess']);
     $session->register('restart_process', [$this, 'restartProcess']);
     $session->register('add_instance', [$this, 'addInstance']);
     //Congestion Manager Client.  This needs to be a separate client because it needs to listen on the main realm and not `process_manager`.
     $config = $this->container->getParameter('voryx_thruway');
     $congestionManager = new Client($config['realm'], $session->getLoop());
     $congestionManager->addTransportProvider(new PawlTransportProvider($config['trusted_url']));
     $congestionManager->on('open', function (ClientSession $session) {
         $session->subscribe("thruway.metaevent.procedure.congestion", [$this, "onCongestion"]);
     });
     $congestionManager->start(false);
 }
Пример #7
0
 /**
  * TODO doc block
  */
 public function __construct()
 {
     Logger::set(new NullLogger());
     parent::__construct('realm1');
     $ip = Configure::read('Websockets.ip');
     $port = Configure::read('Websockets.port');
     $this->addTransportProvider(new PawlTransportProvider("ws://" . $ip . ":" . $port . "/"));
 }
 /**
  * Constructor
  *
  * @param array $authRealms
  * @param \React\EventLoop\LoopInterface $loop
  */
 public function __construct(array $authRealms, LoopInterface $loop = null)
 {
     $this->authRealms = $authRealms;
     /*
      * Set authorization the realm. Defaults to "thruway.auth"
      *
      * This realm is only used between the Authentication Provider Client and the Authentication Manager Client on the server.
      *
      */
     parent::__construct('thruway.auth', $loop);
 }
Пример #9
0
 /**
  * Setup the onChallenge callback
  */
 private function handleOnChallenge()
 {
     $options = $this->options;
     if (isset($options['onChallenge']) && is_callable($options['onChallenge']) && isset($options['authmethods']) && is_array($options['authmethods'])) {
         $this->client->setAuthMethods($options['authmethods']);
         $this->client->on('challenge', function (ClientSession $session, ChallengeMessage $msg) use($options) {
             $token = call_user_func_array($options['onChallenge'], [$session, $msg->getAuthMethod(), $msg]);
             $session->sendMessage(new AuthenticateMessage($token));
         });
     }
 }
Пример #10
0
 /**
  * @return Client
  * @throws \Exception
  */
 private function getShortClient()
 {
     $client = new Client($this->config['realm']);
     $client->setAttemptRetry(false);
     $client->addTransportProvider(new PawlTransportProvider($this->config['trusted_url']));
     return $client;
 }
Пример #11
0
 /**
  * Constructor
  * 
  * @param string $realm
  * @param \React\EventLoop\LoopInterface $loop
  * @param int $number
  */
 public function __construct($realm, $loop, $number)
 {
     parent::__construct($realm, $loop);
     $this->number = $number;
     $this->registeredDeferred = new \React\Promise\Deferred();
 }
Пример #12
0
 /**
  * Starts the close sequence
  */
 public function close()
 {
     $this->client->setAttemptRetry(false);
     $this->transport->close();
 }
Пример #13
0
 /**
  * @inheritDoc
  */
 public function onClose($reason)
 {
     $this->socket->shutdown();
     parent::onClose($reason);
 }
Пример #14
0
 /**
  * Constructor.
  */
 public function __construct(Application $app, $realm = 'realm1')
 {
     $this->app = $app;
     parent::__construct($realm);
 }
Пример #15
0
 /**
  * @param string $token
  * @param \React\EventLoop\LoopInterface $realm
  * @param null $loop
  */
 function __construct($token, $realm, $loop = null)
 {
     $this->token = $token;
     parent::__construct($realm, $loop);
 }
Пример #16
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct('thruway.auth');
     $this->authMethods = [];
     $this->ready = false;
 }
Пример #17
0
 /**
  * @param Client $client
  */
 public function setClient(Client $client)
 {
     $this->client = $client;
     $this->client->on('open', [$this, 'onOpen']);
 }
Пример #18
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;
$client = new Client("realm1");
$client->addTransportProvider(new PawlTransportProvider("ws://127.0.0.1:8080/ws"));
$title = $_GET['title'];
$message = $_GET['message'];
$type = $_GET['type'];
$notification['title'] = $title;
$notification['message'] = $message;
$notification['type'] = $type;
$notification = json_encode($notification);
echo "\n {$notification} \n";
//die();
$client->on('open', function (ClientSession $session) {
    global $notification;
    $session->publish('pcaudit.broadcastmessage', [$notification], [], ["acknowledge" => true])->then(function () {
        echo "Publish Acknowledged!\n";
        die;
    }, function ($error) {
        // publish failed
        echo "Publish Error {$error}\n";
        die;
    });
});
$client->start();
Пример #19
0
 /**
  * Constructor
  * 
  * @param string $realm
  * @param \React\EventLoop\LoopInterface $loop
  * @param \React\Promise\Promise $thePromise
  */
 public function __construct($realm, $loop, $thePromise)
 {
     parent::__construct($realm, $loop);
     $this->thePromise = $thePromise;
 }
Пример #20
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct("manager");
     $this->callables = [];
     $this->setLogger(new NullLogger());
 }
Пример #21
0
 /**
  * Call
  *
  * @param string $procedureName
  * @param array|mixed $arguments
  * @param array|mixed $argumentsKw
  * @param array|mixed $options
  * @return \React\Promise\Promise
  */
 public function call($procedureName, $arguments = null, $argumentsKw = null, $options = null)
 {
     return $this->peer->getCaller()->call($this, $procedureName, $arguments, $argumentsKw, $options);
 }
Пример #22
0
<?php

require 'bootstrap.php';
use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;
$client = new Client("realm1");
$client->addTransportProvider(new PawlTransportProvider("ws://127.0.0.1:9090/"));
$client->on('open', function (ClientSession $session) {
    // 1) subscribe to a topic
    $onevent = function ($args) {
        echo "Event {$args[0]}\n";
    };
    $session->subscribe('com.myapp.hello', $onevent);
    // 2) publish an event
    $session->publish('com.myapp.hello', ['Hello, world from PHP!!!'], [], ["acknowledge" => true])->then(function () {
        echo "Publish Acknowledged!\n";
    }, function ($error) {
        // publish failed
        echo "Publish Error {$error}\n";
    });
    // 3) register a procedure for remoting
    $add2 = function ($args) {
        return $args[0] + $args[1];
    };
    $session->register('com.myapp.add2', $add2);
    // 4) call a remote procedure
    $session->call('com.myapp.add2', [2, 3])->then(function ($res) {
        echo "Result: {$res}\n";
    }, function ($error) {
        echo "Call Error: {$error}\n";