public class ProcessApplicationContext extends Object
A utility to declare the process application in which subsequent engine API calls are executed. Process application context is important for the engine to access custom classes as well as process-application-level entities like script engines or Spin data formats.
By default, the process engine only guarantees to switch into the context of the process application when it executes custom code (e.g. a JavaDelegate). This utility allows to declare a process application into which the process engine then switches as soon as it begins executing a command. Example using a variable that is serialized with a Camunda Spin data format:
try { ProcessApplicationContext.setCurrentProcessApplication("someProcessApplication"); runtimeService.setVariable( "processInstanceId", "variableName", Variables.objectValue(anObject).serializationDataFormat(SerializationDataFormats.JSON).create()); } finally { ProcessApplicationContext.clear(); }
Declaring the process application context allows the engine to access the Spin JSON data format as configured in that process application to serialize the object value. Without declaring the context, the global json data format is used.
Declaring the context process application affects only engine API invocations. It DOES NOT affect the context class loader for subsequent code.
Constructor and Description |
---|
ProcessApplicationContext() |
Modifier and Type | Method and Description |
---|---|
static void |
clear()
Clears the currently declared context process application.
|
static void |
setCurrentProcessApplication(ProcessApplicationInterface processApplication)
Declares the context process application for all subsequent engine API invocations
until
clear() is called. |
static void |
setCurrentProcessApplication(ProcessApplicationReference reference)
Declares the context process application for all subsequent engine API invocations
until
clear() is called. |
static void |
setCurrentProcessApplication(String processApplicationName)
Declares the context process application for all subsequent engine API invocations
until
clear() is called. |
static <T> T |
withProcessApplicationContext(Callable<T> callable,
ProcessApplicationInterface processApplication)
Takes a callable and executes all engine API invocations within that callable in the context
of the given process application
|
static <T> T |
withProcessApplicationContext(Callable<T> callable,
ProcessApplicationReference reference)
Takes a callable and executes all engine API invocations within that callable in the context
of the given process application
|
static <T> T |
withProcessApplicationContext(Callable<T> callable,
String processApplicationName)
Takes a callable and executes all engine API invocations within that callable in the context
of the given process application
|
public static void setCurrentProcessApplication(String processApplicationName)
clear()
is called. The context is bound to the current thread.
This method should always be used in a try-finally block to ensure that clear()
is called under any circumstances.processApplicationName
- the name of the process application to switch intopublic static void setCurrentProcessApplication(ProcessApplicationReference reference)
clear()
is called. The context is bound to the current thread.
This method should always be used in a try-finally block to ensure that clear()
is called under any circumstances.reference
- a reference to the process application to switch intopublic static void setCurrentProcessApplication(ProcessApplicationInterface processApplication)
clear()
is called. The context is bound to the current thread.
This method should always be used in a try-finally block to ensure that clear()
is called under any circumstances.processApplication
- the process application to switch intopublic static void clear()
public static <T> T withProcessApplicationContext(Callable<T> callable, String processApplicationName) throws Exception
Takes a callable and executes all engine API invocations within that callable in the context of the given process application
Equivalent to
try { ProcessApplicationContext.setCurrentProcessApplication("someProcessApplication"); callable.call(); } finally { ProcessApplicationContext.clear(); }
callable
- the callable to executename
- the name of the process application to switch intoException
public static <T> T withProcessApplicationContext(Callable<T> callable, ProcessApplicationReference reference) throws Exception
Takes a callable and executes all engine API invocations within that callable in the context of the given process application
Equivalent to
try { ProcessApplicationContext.setCurrentProcessApplication("someProcessApplication"); callable.call(); } finally { ProcessApplicationContext.clear(); }
callable
- the callable to executereference
- a reference of the process application to switch intoException
public static <T> T withProcessApplicationContext(Callable<T> callable, ProcessApplicationInterface processApplication) throws Exception
Takes a callable and executes all engine API invocations within that callable in the context of the given process application
Equivalent to
try { ProcessApplicationContext.setCurrentProcessApplication("someProcessApplication"); callable.call(); } finally { ProcessApplicationContext.clear(); }
callable
- the callable to executeprocessApplication
- the process application to switch intoException
Copyright © 2020. All rights reserved.