05-12-2016 03:46 AM
05-12-2016 07:47 AM
ServiceTask task = new ServiceTask();
task.setAsynchronous( true);
task.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
task.setImplementation( "application.ShellTask");
List<FieldExtension> fields = new ArrayList<>();
FieldExtension field = new FieldExtension();
field.setFieldName( "shellCommand");
field.setStringValue( "notepad.exe");
fields.add( field);
task.setFieldExtensions( fields);
package application;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;
public class ShellTask implements JavaDelegate {
Expression shellCommand;
public void execute(DelegateExecution execution) throws Exception {
String command = (String) shellCommand.getValue( execution);
Runtime.getRuntime().exec( command);
}
}
05-15-2016 12:31 PM
05-16-2016 01:30 AM
05-16-2016 09:07 AM
05-17-2016 01:34 AM
05-17-2016 03:19 AM
05-20-2016 07:31 AM
public class MyCustomTask implements SignallableActivityBehavior {
public static String MY_CUSTOM_TASK_SIGNAL = "TaskFinishedSignal";
@Override
public void execute(ActivityExecution execution) throws Exception {
Thread thread = new Thread( new MyRunnable());
thread.start();
}
@Override
public void signal(ActivityExecution execution, String signalEvent, Object signalData) throws Exception {
if( !MY_CUSTOM_TASK_SIGNAL.equals( signalEvent))
return;
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get( 0);
execution.take( transition);
}
}
public class MyRunnable implements Runnable {
@Override
public void run() {
try {
System.out.println( "Start MyRunnable");
Thread.sleep( 10000);
System.out.println( "Stop MyRunnable");
} catch( InterruptedException e) {
e.printStackTrace();
} finally {
Map<String,Object> map = new HashMap<>();
processEngine.getRuntimeService().signal( MY_CUSTOM_TASK_SIGNAL, map);
}
}
}
05-20-2016 08:58 AM
05-21-2016 03:07 AM
public class ProcessManager {
public static Map<Integer,String> registry = new HashMap<>();
public static void register( Integer processId, String executionId) {
registry.put( processId, executionId);
}
public static void unregister( Integer processId) {
registry.remove( processId);
}
}
public class ShellTask implements SignallableActivityBehavior {
@Override
public void execute(ActivityExecution execution) throws Exception {
Thread thread = new Thread( new ProcessExecutor( execution.getId()));
thread.start();
}
@Override
public void signal(ActivityExecution execution, String signalEvent, Object signalData) throws Exception {
Map<String,Object> map = execution.getVariables();
System.out.println( "EXECUTION_RESULT = " + map.get( "EXECUTION_RESULT"));
if( !map.containsKey( "EXECUTION_RESULT")
return;
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get( 0);
execution.take( transition);
}
}
public class ProcessExecutor implements Runnable {
private Integer processId;
private String executionId;
public ProcessExecutor( String executionId) {
this.executionId = executionId;
}
@Override
public void run() {
try {
Process process = Runtime.getRuntime().exec( "notepad.exe");
processId = process.getId();
ProcessManager.register( processId, executionId);
process.waitFor(); // just for testing; the actual process will run asynchronously
} catch( IOException | InterruptedException e) {
e.printStackTrace();
} finally {
// send signal after process finishes
// just for testing; this block will be executed in a process monitor which checks if the async process has completed
Map<String,Object> map = new HashMap<>();
map.put( "EXECUTION_RESULT", "SUCCESS");
processEngine.getRuntimeService().signal( executionId, map);
ProcessManager.unregister( processId);
}
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.