private function findSuitableNode(CommandMessageInterface $command)
 {
     $nodes = $this->template->getSubscriptions($command->getCommandName());
     if (empty($nodes)) {
         throw new NoHandlerForCommandException(sprintf("No handler in cluster was subscribed for command [%s]", $command->getCommandName()));
     }
     return $nodes[0];
     // TODO temporary something more elaborate :)
 }
 /**
  * @param CommandMessageInterface $command
  * @param CommandHandlerInterface $handler
  * @return mixed
  * @throws \Exception
  */
 protected function doDispatch(CommandMessageInterface $command, CommandHandlerInterface $handler)
 {
     $this->logger->debug("Dispatching command [{name}]", array('name' => $command->getCommandName()));
     $unitOfWork = $this->unitOfWorkFactory->createUnitOfWork();
     $unitOfWork->setLogger($this->logger);
     $chain = new DefaultInterceptorChain($command, $unitOfWork, $handler, $this->handlerInterceptors);
     try {
         $return = $chain->proceed();
     } catch (\Exception $ex) {
         $unitOfWork->rollback($ex);
         throw $ex;
     }
     $unitOfWork->commit();
     return $return;
 }
Пример #3
0
 /**
  * Finds and returns the suitable CommandHandlerInterface for the command message
  * or throws a NoHandlerForCommandException if none exist.
  *
  * @param CommandMessageInterface $message
  * @return CommandHandlerInterface
  * @throws NoHandlerForCommandException
  */
 public function findCommandHandlerFor(CommandMessageInterface $message)
 {
     if (!isset($this->subscriptions[$message->getCommandName()])) {
         throw new NoHandlerForCommandException(sprintf("No handler was subscribed for command [%s]", $message->getCommandName()));
     }
     return $this->subscriptions[$message->getCommandName()];
 }