/**
  * @param MessageType $messageType
  * @return bool
  */
 private function canHandleMessageType(MessageType $messageType)
 {
     if ($this->handlerType->isConnector()) {
         if ($messageType->isCollectDataMessage() && $this->dataDirection->isSource()) {
             return true;
         }
         if ($messageType->isProcessDataMessage() && $this->dataDirection->isTarget()) {
             return true;
         }
     } elseif ($this->handlerType->isScript()) {
         if ($messageType->isProcessDataMessage()) {
             return true;
         }
     } else {
         //HandlerType is callback, so handler can handle all message types
         return true;
     }
     //No matching until now, so handler is not able to handle the message type
     return false;
 }
 /**
  * @test
  */
 function it_is_equal_to_another_script()
 {
     $type1 = HandlerType::script();
     $type2 = HandlerType::script();
     $this->assertTrue($type1->equals($type2));
 }
 /**
  * @test
  */
 function it_installs_a_message_handler()
 {
     $messageHandler = ProcessingNode::initializeAs(NodeName::defaultName())->installMessageHandler(MessageHandlerId::generate(), 'Article Exporter', HandlerType::connector(), DataDirection::source(), ProcessingTypes::support([ArticleCollection::prototype()]), ProcessingMetadata::noData(), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', ArticleCollection::prototype(), ProcessingId::fromString('sqlconnector:::example'));
     $this->assertInstanceOf(MessageHandler::class, $messageHandler);
 }
Пример #4
0
 /**
  * @param HandlerType $other
  * @return bool
  */
 public function equals(HandlerType $other)
 {
     return $this->toString() === $other->toString();
 }
Пример #5
0
 /**
  * @param bool $singleItemMode
  * @return MessageHandler
  */
 protected function getArticleImporterMessageHandler($singleItemMode = false)
 {
     $supportedProcessingType = $singleItemMode ? Article::prototype() : ArticleCollection::prototype();
     return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Importer', NodeName::defaultName(), MessageHandler\HandlerType::connector(), MessageHandler\DataDirection::target(), MessageHandler\ProcessingTypes::support([$supportedProcessingType]), ProcessingMetadata::fromArray(['chunk_support' => true]), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon');
 }
 /**
  * @return HandlerType
  */
 public function handlerType()
 {
     return HandlerType::fromString($this->payload['handler_type']);
 }
 /**
  * @param $dataDirection
  * @param null|string $handlerType
  * @param null|array $metadata
  * @return MessageHandler
  */
 private function getMessageHandler($dataDirection, $handlerType = null, array $metadata = null)
 {
     if (!is_null($handlerType)) {
         $handlerType = MessageHandler\HandlerType::fromString($handlerType);
     } else {
         $handlerType = MessageHandler\HandlerType::connector();
     }
     if (!is_null($metadata)) {
         $metadata = ProcessingMetadata::fromArray($metadata);
     } else {
         $metadata = ProcessingMetadata::noData();
     }
     return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Export', NodeName::defaultName(), $handlerType, MessageHandler\DataDirection::fromString($dataDirection), MessageHandler\ProcessingTypes::support([ArticleCollection::prototype(), Article::prototype()]), $metadata, 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', Article::prototype(), MessageHandler\ProcessingId::fromString('sqlconnector:::example'));
 }
 /**
  * @return HandlerType
  */
 public function handlerType()
 {
     if (is_null($this->handlerType)) {
         $this->handlerType = HandlerType::fromString($this->payload['handler_type']);
     }
     return $this->handlerType;
 }