Class ProcessApplicationContext
- java.lang.Object
-
- org.camunda.bpm.application.ProcessApplicationContext
-
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.
- Author:
- Thorben Lindhauer
-
-
Constructor Summary
Constructors Constructor Description ProcessApplicationContext()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
clear()
Clears the currently declared context process application.static void
setCurrentProcessApplication(String processApplicationName)
Declares the context process application for all subsequent engine API invocations untilclear()
is called.static void
setCurrentProcessApplication(ProcessApplicationInterface processApplication)
Declares the context process application for all subsequent engine API invocations untilclear()
is called.static void
setCurrentProcessApplication(ProcessApplicationReference reference)
Declares the context process application for all subsequent engine API invocations untilclear()
is called.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 applicationstatic <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 applicationstatic <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
-
-
-
Method Detail
-
setCurrentProcessApplication
public static void setCurrentProcessApplication(String processApplicationName)
Declares the context process application for all subsequent engine API invocations untilclear()
is called. The context is bound to the current thread. This method should always be used in a try-finally block to ensure thatclear()
is called under any circumstances.- Parameters:
processApplicationName
- the name of the process application to switch into
-
setCurrentProcessApplication
public static void setCurrentProcessApplication(ProcessApplicationReference reference)
Declares the context process application for all subsequent engine API invocations untilclear()
is called. The context is bound to the current thread. This method should always be used in a try-finally block to ensure thatclear()
is called under any circumstances.- Parameters:
reference
- a reference to the process application to switch into
-
setCurrentProcessApplication
public static void setCurrentProcessApplication(ProcessApplicationInterface processApplication)
Declares the context process application for all subsequent engine API invocations untilclear()
is called. The context is bound to the current thread. This method should always be used in a try-finally block to ensure thatclear()
is called under any circumstances.- Parameters:
processApplication
- the process application to switch into
-
clear
public static void clear()
Clears the currently declared context process application.
-
withProcessApplicationContext
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(); }
- Parameters:
callable
- the callable to executename
- the name of the process application to switch into- Throws:
Exception
-
withProcessApplicationContext
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(); }
- Parameters:
callable
- the callable to executereference
- a reference of the process application to switch into- Throws:
Exception
-
withProcessApplicationContext
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(); }
- Parameters:
callable
- the callable to executeprocessApplication
- the process application to switch into- Throws:
Exception
-
-