use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class DefaultContextAssociationManager method setExecution.
@Override
public void setExecution(Execution execution) {
if (execution == null) {
throw new ActivitiCdiException("Cannot associate with execution: null");
}
if (Context.getCommandContext() != null) {
throw new ActivitiCdiException("Cannot work with scoped associations inside command context.");
}
ScopedAssociation scopedAssociation = getScopedAssociation();
Execution associatedExecution = scopedAssociation.getExecution();
if (associatedExecution != null && !associatedExecution.getId().equals(execution.getId())) {
throw new ActivitiCdiException("Cannot associate " + execution + ", already associated with " + associatedExecution + ". Disassociate first!");
}
if (log.isTraceEnabled()) {
log.trace("Associating {} (@{})", execution, scopedAssociation.getClass().getAnnotations()[0].annotationType().getSimpleName());
}
scopedAssociation.setExecution(execution);
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class AsyncPingTest method testRunProcess.
@Deployment(resources = { "process/asyncPing.bpmn20.xml" })
public void testRunProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncPingProcess");
List<Execution> executionList = runtimeService.createExecutionQuery().list();
Assert.assertEquals(1, executionList.size());
managementService.executeJob(managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult().getId());
Thread.sleep(1500);
executionList = runtimeService.createExecutionQuery().list();
Assert.assertEquals(0, executionList.size());
Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class AsyncProcessTest method testRunProcess.
@Deployment(resources = { "process/async.bpmn20.xml" })
public void testRunProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncCamelProcess");
List<Execution> executionList = runtimeService.createExecutionQuery().list();
assertEquals(3, executionList.size());
Thread.sleep(4000);
assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ActivitiProducer method signal.
protected void signal(Exchange exchange) {
String processInstanceId = findProcessInstanceId(exchange);
String executionId = exchange.getProperty(EXECUTION_ID_PROPERTY, String.class);
boolean firstTime = true;
long initialTime = System.currentTimeMillis();
Execution execution = null;
while (firstTime || (timeout > 0 && (System.currentTimeMillis() - initialTime < timeout))) {
try {
Thread.sleep(timeResolution);
} catch (InterruptedException e) {
throw new ActivitiException("error occured while waiting for activiti=" + activity + " for processInstanceId=" + processInstanceId);
}
firstTime = false;
if (executionId != null) {
execution = runtimeService.createExecutionQuery().executionId(executionId).activityId(activity).singleResult();
} else {
execution = runtimeService.createExecutionQuery().processDefinitionKey(processKey).processInstanceId(processInstanceId).activityId(activity).singleResult();
}
if (execution != null) {
break;
}
}
if (execution == null) {
throw new ActivitiException("Couldn't find activity " + activity + " for processId " + processInstanceId + " in defined timeout.");
}
runtimeService.setVariables(execution.getId(), ExchangeUtils.prepareVariables(exchange, getActivitiEndpoint()));
runtimeService.signal(execution.getId());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class EventSubscriptionQueryTest method testQueryByExecutionId.
@Deployment
public void testQueryByExecutionId() {
// starting two instances:
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
runtimeService.startProcessInstanceByKey("catchSignal");
// test query by process instance id
EventSubscriptionEntity subscription = newEventSubscriptionQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(subscription);
Execution executionWaitingForSignal = runtimeService.createExecutionQuery().activityId("signalEvent").processInstanceId(processInstance.getId()).singleResult();
// test query by execution id
EventSubscriptionEntity signalSubscription = newEventSubscriptionQuery().executionId(executionWaitingForSignal.getId()).singleResult();
assertNotNull(signalSubscription);
assertEquals(signalSubscription, subscription);
cleanDb();
}
Aggregations