All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.definition.activity.InitialNodeBehaviour Maven / Gradle / Ivy

package org.ow2.bonita.definition.activity;

import java.util.Map;

import org.ow2.bonita.facade.def.majorElement.ActivityDefinition;
import org.ow2.bonita.facade.runtime.InstanceState;
import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
import org.ow2.bonita.pvm.Execution;
import org.ow2.bonita.pvm.activity.ActivityExecution;
import org.ow2.bonita.runtime.InternalExecution;
import org.ow2.bonita.runtime.InternalInstance;
import org.ow2.bonita.services.Recorder;
import org.ow2.bonita.util.EnvTool;

/**
 * Node behaviour for initial node.
 * Initial node is a "virtual" node added by bonita.
 *
 * The default behaviour is a wait state.
 * The execution waits for a signal to really start the instance. This way,
 * the method that created the instance can update some values in the instance
 * (e.g. execution to signal on completion for a subflow instance) before the
 * execution is really started.
 *
 * The instance is recorded as created only after this activity has been signaled.
 *
 * @author Guillaume Porcher
 *
 */
public class InitialNodeBehaviour extends AbstractActivity {

  /**
   * 
   */
  private static final long serialVersionUID = -3394221261277776050L;

  protected InitialNodeBehaviour() {}
  
  public InitialNodeBehaviour(final ActivityDefinition activityDef) {
    super(activityDef);
  }

  @Override
  protected boolean bodyStartAutomatically() {
    return true;
  }

  @Override
  public void execute(final ActivityExecution execution) {
    final InternalExecution internalExecution = (InternalExecution) execution;
    ProcessInstanceUUID instanceUUID = internalExecution.getInstance().getUUID();
    internalExecution.setCurrentActivityInstanceUUID(getActivityInstanceUUID(instanceUUID));
    execution.waitForSignal();
  }

  @Override
  public void signal(final ActivityExecution execution, final String signal, final Map parameters) {
    final InternalExecution internalExecution = (InternalExecution) execution;
    final InternalInstance instance = internalExecution.getInstance();
    instance.setInstanceState(InstanceState.STARTED);
    final Recorder recorder = EnvTool.getRecorder();
    
    recorder.recordEnterActivity(this.activityDef, internalExecution.getCurrentActivityInstanceUUID(), 
    		internalExecution.getIterationId(),
            internalExecution.getActivityInstanceId(), null);
    
    recorder.recordBodyStarted(internalExecution.getCurrentActivityInstanceUUID());
    recorder.recordBodyEnded(internalExecution.getCurrentActivityInstanceUUID());
    executeSplit(execution, false);
  }

  @Override
  protected boolean executeBusinessLogic(final Execution execution) {
    return false;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy