Esempio n. 1
0
 /**
  * @param ChannelCompositeInterface $channel
  * @param ChannelBaseInterface $console
  */
 private function applyConsoleRouting(ChannelCompositeInterface $channel, ChannelBaseInterface $console)
 {
     $master = $channel->bus('master');
     $router = $console->input();
     $router->addAnchor(new RuleHandler(function ($params) use($master) {
         $master->receive($params['alias'], $params['protocol']);
     }));
     $router = $console->output();
     $router->addAnchor(new RuleHandler(function ($params) use($channel) {
         $channel->push($params['alias'], $params['protocol'], $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']);
     }));
 }
Esempio n. 2
0
 /**
  * @param RuntimeInterface $runtime
  * @param ChannelCompositeInterface $composite
  */
 private function applyConsoleRouting(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(new RuleHandler(function ($params) use($slave, $master) {
         $ch = $params['alias'] === Runtime::RESERVED_CONSOLE_CLIENT ? $master : $slave;
         $ch->push($params['alias'], $params['protocol'], $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['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::RESERVED_CONSOLE_CLIENT, $params['protocol'], $params['flags']);
     }));
     $router = $master->output();
     $router->addAnchor(new RuleHandler(function ($params) use($master) {
         $protocol = $params['protocol'];
         $master->push($protocol->getDestination(), $protocol, $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']);
     }));
     $router = $slave->output();
     $router->addAnchor(new RuleHandler(function ($params) use($slave) {
         $protocol = $params['protocol'];
         $slave->push($protocol->getDestination(), $protocol, $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']);
     }));
 }
Esempio n. 3
0
 /**
  * @param RuntimeInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ConfigInterface $config
  */
 private function registerRuntimeSupervision(RuntimeInterface $runtime, ChannelCompositeInterface $composite, ConfigInterface $config)
 {
     $timerCollection = new TimerCollection();
     $channel = $composite->bus('slave');
     $keepalive = $config->get('core.tolerance.child.keepalive');
     $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
         if ($keepalive <= 0) {
             return;
         }
         $timer = $runtime->loop()->addTimer($keepalive, function () use($alias, $runtime, $timerCollection) {
             $timerCollection->removeTimer($alias);
             $runtime->fail(new ChildUnresponsiveException("Child runtime [{$alias}] is unresponsive."), ['origin' => $alias]);
         });
         $timerCollection->addTimer($alias, $timer);
     });
     $channel->on('connect', function ($alias) use($timerCollection) {
         if (($timer = $timerCollection->getTimer($alias)) !== null) {
             $timer->cancel();
             $timerCollection->removeTimer($alias);
         }
     });
     $channel = $composite->bus('master');
     $keepalive = $config->get('core.tolerance.parent.keepalive');
     $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
         if ($keepalive <= 0) {
             return;
         }
         $timer = $runtime->loop()->addTimer($keepalive, function () use($alias, $runtime, $timerCollection) {
             $timerCollection->removeTimer($alias);
             $runtime->fail(new ParentUnresponsiveException("Parent runtime [{$alias}] is unresponsive."), ['origin' => $alias]);
         });
         $timerCollection->addTimer($alias, $timer);
     });
     $channel->on('connect', function ($alias) use($timerCollection) {
         if (($timer = $timerCollection->getTimer($alias)) !== null) {
             $timer->cancel();
             $timerCollection->removeTimer($alias);
         }
     });
 }
Esempio n. 4
0
 /**
  * @param RuntimeInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ChannelBaseInterface $console
  */
 private function applyRootRouting(RuntimeInterface $runtime, ChannelCompositeInterface $composite, ChannelBaseInterface $console)
 {
     $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, $console) {
         if ($receiver === Runtime::RESERVED_CONSOLE_CLIENT || $protocol->getDestination() === Runtime::RESERVED_CONSOLE_CLIENT) {
             $console->push(Runtime::RESERVED_CONSOLE_CLIENT, $protocol, $flags, $success, $failure, $cancel, $timeout);
         } else {
             if ($runtime->manager()->existsRuntime($receiver) || $slave->isConnected($receiver)) {
                 $slave->push($receiver, $protocol, $flags, $success, $failure, $cancel, $timeout);
             } else {
                 $slave->push($slave->getConnected(), $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, $console) {
         $receiver = $params['alias'];
         $protocol = $params['protocol'];
         if ($receiver === Runtime::RESERVED_CONSOLE_CLIENT || $protocol->getDestination() === Runtime::RESERVED_CONSOLE_CLIENT) {
             $console->push(Runtime::RESERVED_CONSOLE_CLIENT, $protocol, $params['flags']);
         } else {
             $slave->push($slave->getConnected(), $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);
     });
 }
Esempio n. 5
0
 /**
  * @param string $name
  * @param ChannelBaseInterface|ChannelCompositeInterface $channel
  * @return ChannelCompositeInterface
  */
 public function setBus($name, $channel)
 {
     $this->bus[$name] = $channel;
     $this->events[$name] = $channel->copyEvents($this, ['connect', 'disconnect']);
     // TODO handle start
     // TODO handle stop
     $this->events[$name][] = $channel->on('input', function ($sender, ChannelProtocolInterface $protocol) {
         $this->handleInput($sender, $protocol);
     });
     return $this;
 }