use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class JobQueryTest method createJobWithoutExceptionMsg.
private void createJobWithoutExceptionMsg() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobEntityManager jobManager = commandContext.getJobEntityManager();
timerEntity = new TimerEntity();
timerEntity.setLockOwner(UUID.randomUUID().toString());
timerEntity.setDuedate(new Date());
timerEntity.setRetries(0);
StringWriter stringWriter = new StringWriter();
NullPointerException exception = new NullPointerException();
exception.printStackTrace(new PrintWriter(stringWriter));
timerEntity.setExceptionStacktrace(stringWriter.toString());
jobManager.insert(timerEntity);
assertNotNull(timerEntity.getId());
return null;
}
});
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class EventSubscriptionQueryTest method testQueryByActivityId.
public void testQueryByActivityId() {
processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
messageEventSubscriptionEntity1.setEventName("messageName");
messageEventSubscriptionEntity1.setActivityId("someActivity");
messageEventSubscriptionEntity1.insert();
MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
messageEventSubscriptionEntity2.setEventName("messageName");
messageEventSubscriptionEntity2.setActivityId("someActivity");
messageEventSubscriptionEntity2.insert();
SignalEventSubscriptionEntity signalEventSubscriptionEntity3 = new SignalEventSubscriptionEntity();
signalEventSubscriptionEntity3.setEventName("messageName2");
signalEventSubscriptionEntity3.setActivityId("someOtherActivity");
signalEventSubscriptionEntity3.insert();
return null;
}
});
List<EventSubscriptionEntity> list = newEventSubscriptionQuery().activityId("someOtherActivity").list();
assertEquals(1, list.size());
list = newEventSubscriptionQuery().activityId("someActivity").eventType("message").list();
assertEquals(2, list.size());
cleanDb();
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class JobQueryTest method setUp.
/**
* Setup will create
* - 3 process instances, each with one timer, each firing at t1/t2/t3 + 1 hour (see process)
* - 1 message
*/
protected void setUp() throws Exception {
super.setUp();
this.commandExecutor = processEngineConfiguration.getCommandExecutor();
deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/mgmt/timerOnTask.bpmn20.xml").deploy().getId();
// Create proc inst that has timer that will fire on t1 + 1 hour
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.MILLISECOND, 0);
Date t1 = startTime.getTime();
processEngineConfiguration.getClock().setCurrentTime(t1);
processInstanceIdOne = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
testStartTime = t1;
timerOneFireTime = new Date(t1.getTime() + ONE_HOUR);
// Create proc inst that has timer that will fire on t2 + 1 hour
startTime.add(Calendar.HOUR_OF_DAY, 1);
// t2 = t1 + 1 hour
Date t2 = startTime.getTime();
processEngineConfiguration.getClock().setCurrentTime(t2);
processInstanceIdTwo = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
timerTwoFireTime = new Date(t2.getTime() + ONE_HOUR);
// Create proc inst that has timer that will fire on t3 + 1 hour
startTime.add(Calendar.HOUR_OF_DAY, 1);
// t3 = t2 + 1 hour
Date t3 = startTime.getTime();
processEngineConfiguration.getClock().setCurrentTime(t3);
processInstanceIdThree = runtimeService.startProcessInstanceByKey("timerOnTask").getId();
timerThreeFireTime = new Date(t3.getTime() + ONE_HOUR);
// Create one message
messageId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
MessageEntity message = new MessageEntity();
commandContext.getJobEntityManager().send(message);
return message.getId();
}
});
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class StandaloneMybatisTransactionContext method fireTransactionEvent.
/**
* Fires the event for the provided {@link TransactionState}.
*
* @param transactionState The {@link TransactionState} for which the listeners will be called.
* @param executeInNewContext If true, the listeners will be called in a new command context.
* This is needed for example when firing the {@link TransactionState#COMMITTED}
* event: the transaction is already committed and executing logic in the same
* context could lead to strange behaviour (for example doing a {@link SqlSession#update(String)}
* would actually roll back the update (as the MyBatis context is already committed
* and the internal flags have not been correctly set).
*/
protected void fireTransactionEvent(TransactionState transactionState, boolean executeInNewContext) {
if (stateTransactionListeners == null) {
return;
}
final List<TransactionListener> transactionListeners = stateTransactionListeners.get(transactionState);
if (transactionListeners == null) {
return;
}
if (executeInNewContext) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
public Void execute(CommandContext commandContext) {
executeTransactionListeners(transactionListeners, commandContext);
return null;
}
});
} else {
executeTransactionListeners(transactionListeners, commandContext);
}
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class MessageThrowingEventListener method onEvent.
@Override
public void onEvent(ActivitiEvent event) {
if (isValidEvent(event)) {
if (event.getProcessInstanceId() == null) {
throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped message, since the dispatched event is not part of an ongoing process instance");
}
CommandContext commandContext = Context.getCommandContext();
List<EventSubscriptionEntity> subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, event.getExecutionId());
// Revert to messaging the process instance
if (subscriptionEntities.isEmpty() && event.getProcessInstanceId() != null && !event.getExecutionId().equals(event.getProcessInstanceId())) {
subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, event.getProcessInstanceId());
}
for (EventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
signalEventSubscriptionEntity.eventReceived(null, false);
}
}
}
Aggregations