상속: extends Kraken\Channel\ChannelInterface
예제 #1
0
 /**
  * @param RuntimeContainerInterface $runtime
  * @param ChannelCompositeInterface $composite
  */
 private function applyConsoleRouting(RuntimeContainerInterface $runtime, ChannelCompositeInterface $composite)
 {
     $master = $composite->getBus('master');
     $slave = $composite->getBus('slave');
     $router = $composite->getInput();
     $router->addDefault(new RuleHandler(function ($params) {
         return true;
     }));
     $router = $composite->getOutput();
     $router->addDefault(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->getInput();
     $router->addRule(new RuleMatchDestination($master->getName()), new RuleHandler(function ($params) use($composite) {
         $this->executeProtocol($composite, $params['protocol']);
     }));
     $router->addDefault(new RuleHandler(function ($params) use($slave) {
         $slave->push($slave->getConnected(), $params['protocol'], $params['flags']);
     }));
     $router = $slave->getInput();
     $router->addDefault(new RuleHandler(function ($params) use($runtime, $slave, $master) {
         $master->push(Runtime::RESERVED_CONSOLE_CLIENT, $params['protocol'], $params['flags']);
     }));
     $router = $master->getOutput();
     $router->addDefault(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->getOutput();
     $router->addDefault(new RuleHandler(function ($params) use($slave) {
         $protocol = $params['protocol'];
         $slave->push($protocol->getDestination(), $protocol, $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']);
     }));
 }
 /**
  * @param ChannelCompositeInterface $channel
  * @param ChannelInterface $console
  */
 private function applyConsoleRouting(ChannelCompositeInterface $channel, ChannelInterface $console)
 {
     $master = $channel->getBus('master');
     $router = $console->getInput();
     $router->addDefault(new RuleHandler(function ($params) use($master) {
         $master->receive($params['alias'], $params['protocol']);
     }));
     $router = $console->getOutput();
     $router->addDefault(new RuleHandler(function ($params) use($channel) {
         $channel->push($params['alias'], $params['protocol'], $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']);
     }));
 }
 /**
  * @param RuntimeContainerInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ConfigInterface $config
  */
 private function registerRuntimeSupervision(RuntimeContainerInterface $runtime, ChannelCompositeInterface $composite, ConfigInterface $config)
 {
     $timerCollection = new TimerCollection();
     $channel = $composite->getBus('slave');
     $keepalive = $config->get('project.tolerance.child.keepalive');
     $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
         if ($keepalive <= 0) {
             return;
         }
         $timer = $runtime->getLoop()->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->getBus('master');
     $keepalive = $config->get('project.tolerance.parent.keepalive');
     $channel->on('disconnect', function ($alias) use($runtime, $keepalive, $timerCollection) {
         if ($keepalive <= 0) {
             return;
         }
         $timer = $runtime->getLoop()->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);
         }
     });
 }
예제 #4
0
 /**
  * @param RuntimeContainerInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ChannelInterface $console
  */
 private function applyRootRouting(RuntimeContainerInterface $runtime, ChannelCompositeInterface $composite, ChannelInterface $console)
 {
     $master = $composite->getBus('master');
     $slave = $composite->getBus('slave');
     $router = $composite->getInput();
     $router->addDefault(new RuleHandler(function ($params) {
         return true;
     }));
     $router = $composite->getOutput();
     $router->addDefault(function ($receiver, ProtocolInterface $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->getManager()->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->getInput();
     $router->addRule(new RuleMatchDestination($master->getName()), new RuleHandler(function ($params) use($runtime, $composite) {
         $this->executeProtocol($runtime, $composite, $params['protocol']);
     }));
     $router->addDefault(new RuleHandler(function ($params) use($slave) {
         $slave->push($slave->getConnected(), $params['protocol'], $params['flags']);
     }));
     $router = $slave->getInput();
     $router->addRule(new RuleMatchDestination($slave->getName()), new RuleHandler(function ($params) use($runtime, $composite) {
         $this->executeProtocol($runtime, $composite, $params['protocol']);
     }));
     $router->addDefault(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->getOutput();
     $router->addDefault(function ($sender, ProtocolInterface $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->getOutput();
     $router->addDefault(function ($sender, ProtocolInterface $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);
     });
 }