public function __construct($name, $priority, VirtualExecution $execution = NULL, $documentation = NULL)
 {
     $this->name = (string) $name;
     $this->priority = (int) $priority;
     $this->executionId = $execution === NULL ? NULL : $execution->getId();
     $this->documentation = $documentation === NULL ? NULL : (string) $documentation;
 }
 public function __construct($signal, UUID $executionId = NULL, array $variables = [], VirtualExecution $sourceExecution = NULL)
 {
     $this->signal = (string) $signal;
     $this->variables = serialize($variables);
     $this->executionId = $executionId;
     $this->sourceExecutionId = $sourceExecution === NULL ? NULL : $sourceExecution->getId();
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function interrupt(VirtualExecution $execution, array $transitions = NULL)
 {
     foreach ($execution->findChildExecutions() as $sub) {
         $sub->terminate(false);
     }
     parent::interrupt($execution, $transitions);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $execution->getEngine()->debug('Executing manual task "{task}"', ['task' => $name]);
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
 /**
  * {@inheritdoc}
  */
 public function processSignal(VirtualExecution $execution, $signal, array $variables = [], array $delegation = [])
 {
     $engine = $execution->getEngine();
     $engine->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $engine));
     $node = $execution->getProcessModel()->findNode($delegation['nodeId']);
     $engine->notify(new ActivityStartedEvent($node->getId(), $execution, $engine));
     $this->delegateSignal($execution, $signal, $variables, $delegation);
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $engine->debug('{execution} reached checkpoint "{checkpoint}" ({node})', ['execution' => (string) $execution, 'checkpoint' => $this->name, 'node' => $execution->getNode()->getId()]);
     $engine->notify(new CheckpointReachedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
 /**
  * Create a new persisted event subscription.
  * 
  * @param string $name Name of the subscription type: "signal", "message", etc.
  * @param VirtualExecution $execution Target execution.
  * @param string $activityId ID of the activity that created the event subscription.
  * @param Node $node Target node to receive the delegated signal or NULL in order to use the activity node.
  * @param boolean $boundaryEvent Is this a subscription for a boundary event?
  */
 public function __construct($name, VirtualExecution $execution, $activityId, Node $node = NULL, $boundaryEvent = false)
 {
     $this->name = (string) $name;
     $this->executionId = $execution->getId();
     $this->activityId = (string) $activityId;
     $this->nodeId = $node === NULL ? NULL : (string) $node->getId();
     $this->boundaryEvent = $boundaryEvent ? true : false;
 }
Exemple #8
0
 public function setParentExecution(VirtualExecution $parent = NULL)
 {
     if ($parent !== NULL) {
         $this->parentExecution = $parent;
         $parent->registerChildExecution($this);
     }
     $this->markModified();
 }
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $date = $this->getDateValue($this->date, $execution->getExpressionContext());
     if (!$date instanceof \DateTimeInterface) {
         throw new \RuntimeException(sprintf('Expecting DateTimeInterface, given %s', is_object($date) ? get_class($date) : gettype($date)));
     }
     $execution->getEngine()->executeCommand(new CreateTimerSubscriptionCommand($date, $execution, $activityId, $node === NULL ? $execution->getNode() : $node));
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $typeName = $this->getStringValue($this->typeName, $execution->getExpressionContext());
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $task = $engine->createDelegateTask($typeName);
     if (!$task instanceof DelegateTaskInterface) {
         throw new \RuntimeException('Invalid service task implementation: ' . get_class($task));
     }
     $engine->debug('Execute delegate task "{task}" implemented by <{class}>', ['task' => $name, 'class' => get_class($task)]);
     $task->execute(new DelegateExecution($execution));
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
 /**
  * {@inheritdoc}
  */
 public function executeCommand(ProcessEngine $engine)
 {
     $def = $engine->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionId($this->definitionId)->findOne();
     $definition = $def->getModel();
     $startNode = $definition->findNode($this->startNodeId);
     $process = new VirtualExecution(UUID::createRandom(), $engine, $definition);
     $process->setBusinessKey($this->businessKey);
     $process->setNode($startNode);
     foreach (unserialize($this->variables) as $k => $v) {
         $process->setVariable($k, $v);
     }
     $engine->registerExecution($process);
     $engine->info('Started {process} using process definition "{key}" ({id})', ['process' => (string) $process, 'key' => $def->getKey(), 'id' => (string) $def->getId()]);
     $process->execute($startNode);
     return $process->getId();
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->getEngine()->debug('Reached terminate end event "{name}"', ['name' => $this->getStringValue($this->name, $execution->getExpressionContext())]);
     $engine = $execution->getEngine();
     $engine->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $engine));
     $root = $execution->getScopeRoot();
     $root->setNode($execution->getNode());
     $root->setTransition($execution->getTransition());
     $root->terminate(false);
 }
Exemple #13
0
 /**
  * {@inheritdoc}
  */
 public function executeJob(Job $job, VirtualExecution $execution, ProcessEngine $engine)
 {
     if ($execution->isTerminated()) {
         throw new \RuntimeException(sprintf('%s is terminated', $execution));
     }
     $data = (array) $job->getHandlerData();
     $command = $data[self::PARAM_COMMAND];
     if (!$command instanceof CommandInterface) {
         throw new \RuntimeException(sprintf('Expecting command, given %s', is_object($command) ? get_class($command) : gettype($command)));
     }
     // Move execution to start node if param is set.
     if (array_key_exists(self::PARAM_NODE_ID, $data)) {
         $execution->setNode($execution->getProcessModel()->findNode($data[self::PARAM_NODE_ID]));
         $engine->debug('Moved {execution} to node "{node}"', ['execution' => (string) $execution, 'node' => $execution->getNode()->getId()]);
     }
     $engine->debug('Executing async command {cmd} using {execution}', ['cmd' => get_class($command), 'execution' => (string) $execution]);
     $engine->pushCommand($command);
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  */
 public function interrupt(VirtualExecution $execution, array $transitions = NULL)
 {
     $engine = $execution->getEngine();
     $root = $execution->getScope();
     $params = ['e1' => $root->getId()];
     $i = 1;
     foreach ($root->findChildExecutions() as $child) {
         $params['e' . ++$i] = $child->getId();
     }
     $placeholders = implode(', ', array_map(function ($p) {
         return ':' . $p;
     }, array_keys($params)));
     $stmt = $engine->prepareQuery("SELECT `id` FROM `#__bpmn_user_task` WHERE `execution_id` IN ({$placeholders})");
     $stmt->bindAll($params);
     $stmt->transform('id', new UUIDTransformer());
     $stmt->execute();
     foreach ($stmt->fetchColumns('id') as $taskId) {
         $engine->executeCommand(new RemoveUserTaskCommand($taskId));
     }
     parent::interrupt($execution, $transitions);
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $engine->debug('Evaluate <{language}> script task "{task}"', ['language' => $this->language, 'task' => $name]);
     if ($this->scriptResource !== NULL) {
         $process = $engine->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionId($execution->getProcessModel()->getId())->findOne();
         $deployment = $engine->getRepositoryService()->createDeploymentQuery()->deploymentId($process->getDeploymentId())->findOne();
         $resource = $deployment->findResourceById($process->getResourceId());
         $file = str_replace('./', '', dirname($resource->getName()) . '/' . $this->scriptResource);
         $script = '?>' . $deployment->findResource($file)->getContents();
     } else {
         $script = $this->script;
     }
     // Isolate scope to prevent manipulation of local / instance variables:
     $callback = function (DelegateExecution $execution, $script) {
         return eval($script);
     };
     if (method_exists($callback, 'bindTo')) {
         $callback = $callback->bindTo(NULL, NULL);
     }
     $result = $callback(new DelegateExecution($execution), $script);
     if ($this->resultVariable !== NULL) {
         $execution->setVariable($this->resultVariable, $result);
     }
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
 public function processSignal(VirtualExecution $execution, $signal, array $variables = [], array $delegation = [])
 {
     $startNode = $execution->getProcessModel()->findNode($this->startNodeId);
     $root = $execution->getScope();
     $scope = $this->findScopeActivity($execution);
     if (!$this->isInterrupting()) {
         return $scope->leaveConcurrent($root, $startNode);
     }
     // Kill all remaining concurrent executions within the scope activity:
     foreach ($root->findChildExecutions() as $child) {
         $child->terminate(false);
     }
     $scope->clearEventSubscriptions($root, $scope->getActivityId());
     $root->setNode($this->findScopeNode($root));
     $root->setActive(false);
     $root->waitForSignal();
     $sub = $root->createExecution(false);
     $sub->setNode($startNode);
     $sub->waitForSignal();
     $sub->getEngine()->notify(new ActivityCanceledEvent($this->attachedTo, $sub, $sub->getEngine()));
     // Delegate received signal to event sub process start event.
     $sub->signal($signal, $variables);
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $engine = $execution->getEngine();
     $name = $this->getStringValue($this->name, $execution->getExpressionContext());
     $engine->debug('Execute expression in service task "{task}"', ['task' => $name]);
     $result = $this->getValue($this->expression, $execution->getExpressionContext());
     if ($this->resultVariable !== NULL) {
         $execution->setVariable($this->resultVariable, $result);
     }
     $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine));
     $this->leave($execution);
 }
 /**
  * @param VirtualExecution $execution
  * @return AbstractScopeActivity
  */
 public function findScopeActivity(VirtualExecution $execution)
 {
     return $execution->getProcessModel()->findNode($this->attachedTo)->getBehavior();
 }
 /**
  * Collect all boundary events connected to the activity of the given execution.
  *
  * @param VirtualExecution $execution
  * @return array<Node>
  */
 public function findAttachedBoundaryActivities(VirtualExecution $execution)
 {
     $model = $execution->getProcessModel();
     $activities = [];
     foreach ($model->findNodes() as $node) {
         $behavior = $node->getBehavior();
         if ($behavior instanceof AbstractBoundaryActivity) {
             if ($this->activityId == $behavior->getAttachedTo()) {
                 $activities[] = $node;
             }
         }
     }
     return $activities;
 }
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $execution->getEngine()->pushCommand(new CreateSignalSubscriptionCommand($this->signal, $execution, $activityId, $node === NULL ? $execution->getNode() : $node));
     parent::createEventSubscriptions($execution, $activityId, $node);
 }
 protected function dumpExecution(VirtualExecution $exec)
 {
     $node = $exec->getNode();
     $nodeId = $node === NULL ? NULL : $node->getId();
     printf("%s%s [ %s ]\n", str_repeat('  ', $exec->getExecutionDepth()), $nodeId, $exec->getId());
     foreach ($exec->findChildExecutions() as $child) {
         $this->dumpExecution($child);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $execution->getEngine()->executeCommand(new CreateMessageSubscriptionCommand($this->message, $execution, $activityId, $node === NULL ? $execution->getNode() : $node));
 }
Exemple #23
0
 public function __construct(VirtualExecution $execution)
 {
     $this->executionId = $execution->getId();
 }
Exemple #24
0
 /**
  * Delegate signal to a target node using the same execution.
  * 
  * @param VirtualExecution $execution
  * @param string $signal
  * @param array $variables
  * @param array $delegation
  * @return boolean Returns true if the signal could be delegated.
  */
 protected function delegateSignal(VirtualExecution $execution, $signal, array $variables, array $delegation)
 {
     if (empty($delegation['nodeId'])) {
         return false;
     }
     $node = $execution->getProcessModel()->findNode($delegation['nodeId']);
     $execution->getEngine()->debug('Delegating signal <{signal}> to {node}', ['signal' => $signal === NULL ? 'NULL' : $signal, 'node' => (string) $node]);
     $execution->setNode($node);
     $execution->waitForSignal();
     $execution->signal($signal, $variables);
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->getEngine()->pushCommand(new SignalEventReceivedCommand($this->signalName, NULL, [], $execution));
     $execution->waitForSignal();
 }
Exemple #26
0
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->waitForSignal();
 }
 /**
  * {@inheritdoc}
  */
 public function enter(VirtualExecution $execution)
 {
     $execution->getEngine()->pushCommand(new ThrowMessageCommand($execution));
     $execution->waitForSignal();
 }
 /**
  * {@inheritdoc}
  */
 public function createEventSubscriptions(VirtualExecution $execution, $activityId, Node $node = NULL)
 {
     $execution->getEngine()->executeCommand(new CreateSignalSubscriptionCommand($this->signal, $execution, $activityId, $node, true));
 }