/**
  * {@inheritDoc}
  */
 public function sendAndWait($command)
 {
     $message = $this->createCommandMessage($command);
     $callback = new ResultCallback();
     $this->commandBus->dispatch($message, $callback);
     return $callback->getResult();
 }
 public function processCommand()
 {
     $data = $this->template->dequeueCommand();
     if (null === $data) {
         $this->logger->info('Timeout while waiting for commands, re-entering loop');
         return;
     }
     $dispatchMessage = DispatchMessage::fromBytes($this->serializer, $data[1]);
     $self = $this;
     $successCallback = function ($result) use($dispatchMessage, $self) {
         $message = new ReplyMessage($dispatchMessage->getCommandIdentifier(), $self->serializer, $result);
         $self->template->writeCommandReply($dispatchMessage->getCommandIdentifier(), $message->toBytes());
     };
     $failureCallback = function (\Exception $cause) use($dispatchMessage, $self) {
         $message = new ReplyMessage($dispatchMessage->getCommandIdentifier(), $self->serializer, $cause, false);
         $self->template->writeCommandReply($dispatchMessage->getCommandIdentifier(), $message->toBytes());
     };
     $this->localSegment->dispatch($dispatchMessage->getCommandMessage(), $dispatchMessage->isExpectReply() ? new ClosureCommandCallback($successCallback, $failureCallback) : null);
 }
 /**
  *
  */
 public function clearSubscriptions()
 {
     foreach ($this->localSegment->getSubscriptions() as $command => $handler) {
         $this->template->unsubscribe($command);
     }
 }
 /**
  * @param $className
  * @param RepositoryInterface $repository
  * @param CommandBusInterface $commandBus
  * @param ParameterResolverFactoryInterface $parameterResolver
  * @param CommandTargetResolverInterface $targetResolver
  * @param AnnotationReaderFactoryInterface $annotationReaderFactory
  */
 public static function subscribe($className, RepositoryInterface $repository, CommandBusInterface $commandBus, ParameterResolverFactoryInterface $parameterResolver, CommandTargetResolverInterface $targetResolver = null, AnnotationReaderFactoryInterface $annotationReaderFactory = null)
 {
     $inspector = new MethodMessageHandlerInspector($annotationReaderFactory, new \ReflectionClass($className), CommandHandler::class);
     foreach ($inspector->getHandlerDefinitions() as $handlerDefinition) {
         $handler = new AnnotatedAggregateCommandHandler($className, $handlerDefinition->getMethod()->name, $parameterResolver, $repository, $targetResolver, $annotationReaderFactory);
         $commandBus->getCommandHandlerRegistry()->subscribe($handlerDefinition->getPayloadType(), $handler);
     }
 }