Ejemplo n.º 1
0
 /**
  * @param RuntimeInterface $runtime
  * @param ChannelBaseInterface $channel
  * @param string|null $receiver
  */
 public function __construct(RuntimeInterface $runtime, ChannelBaseInterface $channel, $receiver = null)
 {
     $this->runtime = $runtime;
     $this->channel = $channel;
     $this->receiver = $receiver !== null ? $receiver : $runtime->parent();
 }
Ejemplo n.º 2
0
 /**
  * @param RuntimeInterface $runtime
  * @param ChannelCompositeInterface $composite
  */
 private function applySimpleRouting(RuntimeInterface $runtime, ChannelCompositeInterface $composite)
 {
     $master = $composite->bus('master');
     $slave = $composite->bus('slave');
     $router = $composite->input();
     $router->addAnchor(new RuleHandler(function ($params) {
         return true;
     }));
     $router = $composite->output();
     $router->addAnchor(function ($receiver, ChannelProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0) use($runtime, $slave, $master) {
         if ($runtime->manager()->existsRuntime($receiver) || $slave->isConnected($receiver)) {
             $slave->push($receiver, $protocol, $flags, $success, $failure, $cancel, $timeout);
         } else {
             $master->push($runtime->parent(), $protocol, $flags, $success, $failure, $cancel, $timeout);
         }
     });
     $router = $master->input();
     $router->addRule(new RuleMatchDestination($master->name()), new RuleHandler(function ($params) use($composite) {
         $this->executeProtocol($composite, $params['protocol']);
     }));
     $router->addAnchor(new RuleHandler(function ($params) use($slave) {
         $slave->push($slave->getConnected(), $params['protocol'], $params['flags']);
     }));
     $router = $slave->input();
     $router->addRule(new RuleMatchDestination($slave->name()), new RuleHandler(function ($params) use($composite) {
         $this->executeProtocol($composite, $params['protocol']);
     }));
     $router->addAnchor(new RuleHandler(function ($params) use($runtime, $slave, $master) {
         $master->push($runtime->parent(), $params['protocol'], $params['flags']);
     }));
     $router = $master->output();
     $router->addAnchor(function ($sender, ChannelProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0) use($master) {
         $master->push($sender, $protocol, $flags, $success, $failure, $cancel, $timeout);
     });
     $router = $slave->output();
     $router->addAnchor(function ($sender, ChannelProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0) use($slave) {
         $slave->push($sender, $protocol, $flags, $success, $failure, $cancel, $timeout);
     });
 }