Search in sources :

Example 6 with InvocationContext

use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.

the class CommandInvocationContext method performNext.

protected void performNext() {
    AtomicOperationInvocation nextInvocation = queuedInvocations.get(0);
    if (nextInvocation.operation.isAsyncCapable() && isExecuting) {
        // will be picked up by while loop below
        return;
    }
    ProcessApplicationReference targetProcessApplication = getTargetProcessApplication(nextInvocation.execution);
    if (requiresContextSwitch(targetProcessApplication)) {
        Context.executeWithinProcessApplication(new Callable<Void>() {

            public Void call() throws Exception {
                performNext();
                return null;
            }
        }, targetProcessApplication, new InvocationContext(nextInvocation.execution));
    } else {
        if (!nextInvocation.operation.isAsyncCapable()) {
            // if operation is not async capable, perform right away.
            invokeNext();
        } else {
            try {
                isExecuting = true;
                while (!queuedInvocations.isEmpty()) {
                    // assumption: all operations are executed within the same process application...
                    nextInvocation = queuedInvocations.get(0);
                    invokeNext();
                }
            } finally {
                isExecuting = false;
            }
        }
    }
}
Also used : ProcessApplicationReference(org.camunda.bpm.application.ProcessApplicationReference) InvocationContext(org.camunda.bpm.application.InvocationContext) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException)

Example 7 with InvocationContext

use of org.camunda.bpm.application.InvocationContext in project camunda-bpm-platform by camunda.

the class InvocationContextTest method testInvokeProcessApplicationWithContextOnStart.

@Test
@OperateOnDeployment("app")
public void testInvokeProcessApplicationWithContextOnStart() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("messageProcess");
    InvocationContext invocationContext = ProcessApplicationWithInvocationContext.getInvocationContext();
    assertThat(invocationContext, is(notNullValue()));
    assertThat(invocationContext.getExecution(), is(notNullValue()));
    assertThat(invocationContext.getExecution().getId(), is(pi.getId()));
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) InvocationContext(org.camunda.bpm.application.InvocationContext) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Aggregations

InvocationContext (org.camunda.bpm.application.InvocationContext)7 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)4 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)4 Test (org.junit.Test)4 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 Date (java.util.Date)1 Callable (java.util.concurrent.Callable)1 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)1 TestApplicationWithoutEngine (org.camunda.bpm.application.impl.embedded.TestApplicationWithoutEngine)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 BaseDelegateExecution (org.camunda.bpm.engine.delegate.BaseDelegateExecution)1 EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 Job (org.camunda.bpm.engine.runtime.Job)1