
org.ow2.bonita.runtime.InternalExecution Maven / Gradle / Ivy
/**
* Copyright (C) 2007 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.runtime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ow2.bonita.definition.InternalProcess;
import org.ow2.bonita.definition.activity.AbstractActivity;
import org.ow2.bonita.facade.runtime.InstanceState;
import org.ow2.bonita.facade.uuid.ActivityInstanceUUID;
import org.ow2.bonita.pvm.Execution;
import org.ow2.bonita.pvm.internal.model.ExecutionImpl;
import org.ow2.bonita.pvm.internal.type.Variable;
import org.ow2.bonita.pvm.model.OpenExecution;
import org.ow2.bonita.services.Recorder;
import org.ow2.bonita.util.EnvTool;
import org.ow2.bonita.util.Misc;
/**
* @author Marc Blachon, Guillaume Porcher, Charles Souillard, Miguel Valdes, Pierre Vigneras
*/
/**
* Variables in internalExecution are handled this way:
* - Process (global) variables are all in one VariableScope. This variable Scope always exists,
* even if it is empty.
* - Activity (local) variables are in a second variableScope. This variable scope only exists
* when there are local variables.
*
* Methods getLocalVariables and getGlobalVariables are provided to have access to global and
* local variables of this execution.
*/
public class InternalExecution extends ExecutionImpl {
private static final long serialVersionUID = 1L;
private static final Logger LOG = Logger.getLogger(InternalExecution.class.getName());
public static final String MAIN_INSTANCE_NAME = "mainInstance";
protected InternalInstance instance;
protected InternalInstance subflowInstance;
protected String iterationId;
protected String activityInstanceId = MAIN_INSTANCE_NAME;
protected int waitingForActivityInstanceNb;
protected ActivityInstanceUUID currentActivityInstanceUUID = null;
// mandatory for persistence
protected InternalExecution() {
super();
}
@Override
public InternalExecution getParent() {
return (InternalExecution) this.parent;
}
@Override
protected InternalExecution newChildExecution() {
final InternalExecution child = new InternalExecution();
child.instance = this.getInstance();
child.iterationId = this.getIterationId();
return child;
}
@Override
public InternalExecution getProcessInstance() {
return (InternalExecution) super.getProcessInstance();
}
@Override
public InternalProcess getProcessDefinition() {
return (InternalProcess) this.processDefinition;
}
@Override
public void begin() {
final InternalInstance instance = getInstance();
instance.setInstanceState(InstanceState.STARTED);
setIterationId(Misc.getUniqueId("it"));
super.begin();
}
/* ITERATORS */
public InternalInstance getInstance() {
return this.instance;
}
public String getIterationId() {
return this.iterationId;
}
public void setIterationId(final String iterationId) {
this.iterationId = iterationId;
}
@SuppressWarnings("unchecked")
public Map getScopeVariables() {
if (this.variables == null) {
return Collections.EMPTY_MAP;
}
return this.variables;
}
public String getActivityInstanceId() {
return this.activityInstanceId;
}
public void setActivityInstanceId(final String activityInstanceId) {
this.activityInstanceId = activityInstanceId;
}
public int getWaitingForActivityInstanceNb() {
return this.waitingForActivityInstanceNb;
}
public void setWaitingForActivityInstanceNb(final int waitingFor) {
this.waitingForActivityInstanceNb = waitingFor;
}
public ActivityInstanceUUID getCurrentActivityInstanceUUID() {
return this.currentActivityInstanceUUID;
}
public void setCurrentActivityInstanceUUID(final ActivityInstanceUUID currentActivityInstanceUUID) {
this.currentActivityInstanceUUID = currentActivityInstanceUUID;
}
public InternalInstance getSubflowInstance() {
return this.subflowInstance;
}
public void setSubflowInstance(final InternalInstance subflowInstance) {
this.subflowInstance = subflowInstance;
}
public void abort() {
if (this.getExecutions() != null) {
for (final OpenExecution child : new ArrayList(this.getExecutions())) {
((InternalExecution) child).abort();
}
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine(this + " aborted.");
}
if (this.getCurrentActivityInstanceUUID() != null) {
final AbstractActivity activity = (AbstractActivity) this.getNode().getBehaviour();
boolean isSubflow = activity.getActivityDefiniton().isSubflow();
if (isSubflow) {
final InternalInstance childInstance = this.getSubflowInstance();
childInstance.getRootExecution().abort();
childInstance.setInstanceState(InstanceState.ABORTED);
childInstance.setExecutionToSignal(null);
final Recorder recorder = EnvTool.getRecorder();
recorder.recordInstanceAborted(childInstance.getUUID(), EnvTool.getUserId());
}
EnvTool.getRecorder().recordBodyAborted(this.getCurrentActivityInstanceUUID());
}
end(Execution.STATE_CANCELLED);
final InternalExecution parent = this.getParent();
if (parent != null) {
parent.removeExecution(this);
}
}
@Override
public void cancel() {
if (this.getExecutions() != null) {
for (final OpenExecution child : new ArrayList(this.getExecutions())) {
((InternalExecution) child).cancel();
}
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine(this + " cancelled.");
}
if (this.getCurrentActivityInstanceUUID() != null) {
final AbstractActivity activity = (AbstractActivity) this.getNode().getBehaviour();
boolean isSubflow = activity.getActivityDefiniton().isSubflow();
if (isSubflow) {
final InternalInstance childInstance = this.getSubflowInstance();
childInstance.cancel();
}
EnvTool.getRecorder().recordBodyCancelled(this.getCurrentActivityInstanceUUID());
}
end(Execution.STATE_CANCELLED);
final InternalExecution parent = this.getParent();
if (parent != null) {
parent.removeExecution(this);
}
}
@Override
public void end() {
super.end();
}
@Override
public void setVariable(final String key, final Object value) {
throw new RuntimeException("1");
}
@Override
public void setVariables(final Map variables) {
throw new RuntimeException("2");
}
/*
@Override
public void createVariable(final String key, final Object value) {
throw new RuntimeException("3");
}
@Override
public void createVariable(final String key, final Object value, final String typeName) {
throw new RuntimeException("4");
}
@Override
public void createVariable(final String key, final Object value, final Type type) {
throw new RuntimeException("5");
}
@Override
public void createVariable(final String key, final Object value, final String typeName, Type type) {
throw new RuntimeException("6");
}
@Override
protected void initializeVariables(final CompositeElementImpl scope, final ExecutionImpl outerExecution) {
throw new RuntimeException("7");
}
*/
public Object getVariable(final String key) {
throw new RuntimeException("8");
}
public Variable getVariableObject(final String key) {
throw new RuntimeException("9");
}
public boolean hasVariable(final String key) {
throw new RuntimeException("10");
}
public Set getVariableKeys() {
throw new RuntimeException("11");
}
public Map getVariablesMap() {
throw new RuntimeException("12");
}
public Map getVariables() {
throw new RuntimeException("13");
}
public boolean hasVariables() {
throw new RuntimeException("14");
}
public boolean removeVariable(final String key) {
throw new RuntimeException("15");
}
public void removeVariables() {
throw new RuntimeException("17");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy