jadex.bpmn.runtime.handler.TaskActivityHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-kernel-bpmn Show documentation
Show all versions of jadex-kernel-bpmn Show documentation
The Jadex BPMN kernel provides a workflow kernel for the standardized business process modeling notation. The kernel relies on annotated BPMN diagrams, which include detailed execution information.
package jadex.bpmn.runtime.handler;
import java.util.List;
import jadex.bpmn.model.MActivity;
import jadex.bpmn.model.task.ITask;
import jadex.bpmn.runtime.IActivityHandler;
import jadex.bpmn.runtime.ProcessThread;
import jadex.bpmn.runtime.exttask.ExternalTaskWrapper;
import jadex.bpmn.runtime.task.PojoTaskWrapper;
import jadex.bridge.IInternalAccess;
import jadex.commons.SUtil;
import jadex.commons.future.IResultListener;
/**
* Handler for (external) tasks.
*/
public class TaskActivityHandler extends DefaultActivityHandler
{
/**
* Execute an activity.
* @param activity The activity to execute.
* @param instance The process instance.
* @param thread The process thread.
*/
public void execute(final MActivity activity, final IInternalAccess instance, final ProcessThread thread)
{
if(thread.isCanceled())
return;
Class> taskimpl = activity.getClazz()!=null? activity.getClazz().getType(instance.getClassLoader(), instance.getModel().getAllImports()) : null;
if(taskimpl!=null)
{
// thread.setWaitingState(ProcessThread.WAITING_FOR_TASK);
thread.setWaiting(true);
try
{
Object tmp = taskimpl.newInstance();
if(!(tmp instanceof ITask))
{
tmp = new PojoTaskWrapper(tmp, instance, thread, activity.getComponentInjections(instance.getClassLoader()),
activity.getArgumentInjections(instance.getClassLoader()), activity.getResultInjections(instance.getClassLoader()));
}
ITask task = (ITask)tmp;
String ext = activity.getPropertyValueString("external");
if(ext!=null && Boolean.parseBoolean(ext))
{
task = new ExternalTaskWrapper(task);
}
thread.setTask(task);
thread.setCanceled(false);
task.execute(thread, instance).addResultListener(new IResultListener()
{
public void resultAvailable(Void result)
{
if(!thread.isCanceled())
getBpmnFeature(instance).notify(activity, thread, null);
}
public void exceptionOccurred(Exception exception)
{
// exception.printStackTrace();
if(!thread.isCanceled())
{
thread.setException(exception);
getBpmnFeature(instance).notify(activity, thread, null);
}
}
});
MActivity timer = null;
List handlers = activity.getEventHandlers();
for(int i=0; timer==null && handlers!=null && i