Пример #1
0
 /**
  * Constructs a new SagaEntry for the given <code>saga</code>. The given saga must be serializable. The provided
  * saga is not modified by this operation.
  *
  * @param SagaInterface $saga The saga to store
  * @param SerializerInterface $serializer The serialization mechanism to convert the Saga to a byte stream
  */
 public function __construct(SagaInterface $saga, SerializerInterface $serializer)
 {
     $this->sagaId = $saga->getSagaIdentifier();
     $serialized = $serializer->serialize($saga);
     $this->serializedSaga = $serialized->getData();
     $this->sagaType = $serialized->getType()->getName();
     $this->revision = $serialized->getType()->getRevision();
     $this->saga = $saga;
 }
 /**
  * {@inheritdoc}
  */
 public function commit(SagaInterface $saga)
 {
     if (!$saga->isActive()) {
         unset($this->managedSagas[$saga->getSagaIdentifier()]);
     } else {
         $this->managedSagas[$saga->getSagaIdentifier()] = $saga;
     }
     $saga->getAssociationValues()->commit();
 }
Пример #3
0
 /**
  * Constructs a new SagaEntry for the given <code>saga</code>. The given saga must be serializable. The provided
  * saga is not modified by this operation.
  *
  * @param SagaInterface $saga The saga to store
  * @param SerializerInterface $serializer The serialization mechanism to convert the Saga to a byte stream
  */
 public function __construct(SagaInterface $saga, SerializerInterface $serializer)
 {
     $this->sagaId = $saga->getSagaIdentifier();
     $serialized = $serializer->serialize($saga);
     $this->serializedSaga = $serialized->getData();
     $this->sagaType = get_class($saga);
     $this->saga = $saga;
     $this->associationValues = $saga->getAssociationValues()->asArray();
 }
 public function commit(SagaInterface $saga)
 {
     if (!$saga->isActive()) {
         $this->deleteSaga($saga);
     } else {
         $sagaType = $this->typeOf($saga);
         $associationValues = $saga->getAssociationValues();
         foreach ($associationValues->addedAssociations() as $av) {
             $this->storeAssociationValue($av, $sagaType, $saga->getSagaIdentifier());
         }
         foreach ($associationValues->removedAssociations() as $av) {
             $this->removeAssociationValue($av, $sagaType, $saga->getSagaIdentifier());
         }
         $associationValues->commit();
         $this->updateSaga($saga);
     }
 }
 protected function storeSaga(SagaInterface $saga)
 {
     $entry = new SagaEntry($saga, $this->serializer);
     $this->entityManager->persist($entry);
     $this->logger->debug("Storing saga id {id} as {data}", array('id' => $saga->getSagaIdentifier(), 'data' => $entry->getSerializedSaga()));
     if ($this->useExplicitFlush) {
         $this->entityManager->flush();
     }
 }
 protected function preProcessSaga(SagaInterface $saga)
 {
     if (null !== $this->parameterResolverFactory) {
         $saga->registerParameterResolverFactory($this->parameterResolverFactory);
     }
 }
 private function doInvokeSaga(EventMessageInterface $event, SagaInterface $saga)
 {
     try {
         CorrelationDataHolder::setCorrelationData($this->correlationDataProvider->correlationDataFor($event));
         $saga->handle($event);
     } catch (\RuntimeException $ex) {
         $this->handleInvokationException($ex, $event, $saga);
     }
 }
Пример #8
0
 /**
  * Update a stored Saga, by replacing it with the given <code>saga</code> instance.
  *
  * @param SagaInterface $saga The saga that has been modified and needs to be updated in the storage
  */
 protected function updateSaga(SagaInterface $saga)
 {
     $sagaEntry = new SagaEntry($saga, $this->serializer);
     $this->mongoTemplate->sagaCollection()->findAndModify(SagaEntry::queryByIdentifier($saga->getSagaIdentifier()), $sagaEntry->asDBObject());
 }