Class ProcessApplicationContext


  • public class ProcessApplicationContext
    extends java.lang.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 Detail

      • ProcessApplicationContext

        public ProcessApplicationContext()
    • Method Detail

      • setCurrentProcessApplication

        public static void setCurrentProcessApplication​(java.lang.String processApplicationName)
        Declares the context process application for all subsequent engine API invocations until 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.
        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 until 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.
        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 until 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.
        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​(java.util.concurrent.Callable<T> callable,
                                                          java.lang.String processApplicationName)
                                                   throws java.lang.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 execute
        name - the name of the process application to switch into
        Throws:
        java.lang.Exception
      • withProcessApplicationContext

        public static <T> T withProcessApplicationContext​(java.util.concurrent.Callable<T> callable,
                                                          ProcessApplicationReference reference)
                                                   throws java.lang.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 execute
        reference - a reference of the process application to switch into
        Throws:
        java.lang.Exception
      • withProcessApplicationContext

        public static <T> T withProcessApplicationContext​(java.util.concurrent.Callable<T> callable,
                                                          ProcessApplicationInterface processApplication)
                                                   throws java.lang.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 execute
        processApplication - the process application to switch into
        Throws:
        java.lang.Exception