Search in sources :

Example 1 with TransactionListener

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);
            }
        });
    }
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext)

Example 2 with TransactionListener

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);
    }
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener)

Example 3 with TransactionListener

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;
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) TransactionContext(org.camunda.bpm.engine.impl.cfg.TransactionContext)

Example 4 with TransactionListener

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);
}
Also used : TransactionListener(org.camunda.bpm.engine.impl.cfg.TransactionListener)

Aggregations

TransactionListener (org.camunda.bpm.engine.impl.cfg.TransactionListener)4 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)2 TransactionContext (org.camunda.bpm.engine.impl.cfg.TransactionContext)1