use of org.camunda.bpm.engine.impl.cfg.TransactionListener in project camunda-bpm-platform by camunda.
the class SignalTestRunListener method notify.
public void notify(final DelegateExecution execution) throws Exception {
final String runId = (String) execution.getVariable(PerfTestConstants.RUN_ID);
CommandContext commandContext = Context.getCommandContext();
if (runId != null && commandContext != null) {
commandContext.getTransactionContext().addTransactionListener(TransactionState.COMMITTED, new TransactionListener() {
public void execute(CommandContext commandContext) {
// signal run after the transaction was committed
PerfTestRunner.signalRun(runId);
}
});
}
}
use of org.camunda.bpm.engine.impl.cfg.TransactionListener in project camunda-bpm-platform by camunda.
the class StandaloneTransactionContext method fireTransactionEvent.
protected void fireTransactionEvent(TransactionState transactionState) {
this.setLastTransactionState(transactionState);
if (stateTransactionListeners == null) {
return;
}
List<TransactionListener> transactionListeners = stateTransactionListeners.get(transactionState);
if (transactionListeners == null) {
return;
}
for (TransactionListener transactionListener : transactionListeners) {
transactionListener.execute(commandContext);
}
}
use of org.camunda.bpm.engine.impl.cfg.TransactionListener in project camunda-bpm-platform by camunda.
the class EntityManagerSessionImpl method getEntityManager.
public EntityManager getEntityManager() {
if (entityManager == null) {
entityManager = getEntityManagerFactory().createEntityManager();
if (handleTransactions) {
// Add transaction listeners, if transactions should be handled
TransactionListener jpaTransactionCommitListener = new TransactionListener() {
public void execute(CommandContext commandContext) {
if (isTransactionActive()) {
entityManager.getTransaction().commit();
}
}
};
TransactionListener jpaTransactionRollbackListener = new TransactionListener() {
public void execute(CommandContext commandContext) {
if (isTransactionActive()) {
entityManager.getTransaction().rollback();
}
}
};
TransactionContext transactionContext = Context.getCommandContext().getTransactionContext();
transactionContext.addTransactionListener(TransactionState.COMMITTED, jpaTransactionCommitListener);
transactionContext.addTransactionListener(TransactionState.ROLLED_BACK, jpaTransactionRollbackListener);
// Also, start a transaction, if one isn't started already
if (!isTransactionActive()) {
entityManager.getTransaction().begin();
}
}
}
return entityManager;
}
use of org.camunda.bpm.engine.impl.cfg.TransactionListener in project camunda-bpm-platform by camunda.
the class JobManager method hintJobExecutor.
protected void hintJobExecutor(JobEntity job) {
JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
if (!jobExecutor.isActive()) {
return;
}
JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
TransactionListener transactionListener = null;
if (!job.isSuspended() && job.isExclusive() && jobExecutorContext != null && jobExecutorContext.isExecutingExclusiveJob() && areInSameProcessInstance(job, jobExecutorContext.getCurrentJob())) {
// lock job & add to the queue of the current processor
Date currentTime = ClockUtil.getCurrentTime();
job.setLockExpirationTime(new Date(currentTime.getTime() + jobExecutor.getLockTimeInMillis()));
job.setLockOwner(jobExecutor.getLockOwner());
transactionListener = new ExclusiveJobAddedNotification(job.getId(), jobExecutorContext);
} else {
// notify job executor:
transactionListener = new MessageAddedNotification(jobExecutor);
}
Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, transactionListener);
}
Aggregations