Class CommandContextInterceptor
- java.lang.Object
-
- org.camunda.bpm.engine.impl.interceptor.CommandInterceptor
-
- org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor
-
- All Implemented Interfaces:
CommandExecutor
public class CommandContextInterceptor extends CommandInterceptor
Interceptor used for opening the
CommandContext
andCommandInvocationContext
.Since 7.1, this interceptor will not always open a new command context but instead reuse an existing command context if possible. This is required for supporting process engine public API access from delegation code (see
ProcessEngineServicesAware
.). However, for every command, a new command invocation context is created. While a command context holds resources that are shared between multiple commands, such as database sessions, a command invocation context holds resources specific for a single command.The interceptor will check whether an open command context exists. If true, it will reuse the command context. If false, it will open a new one. We will always push the context to the
Context
stack. So ins some situations, you will see the same context being pushed to the sack multiple times. The rationale is that the size of the stack should allow you to determine whether you are currently running an 'inner' command or an 'outer' command as well as your current stack size. Existing code may rely on this behavior.The interceptor can be configured using the property
alwaysOpenNew
. If this property is set to true, we will always open a new context regardless whether there already exists an active context or not. This is required for properly supporting REQUIRES_NEW semantics for commands run through theProcessEngineConfigurationImpl.getCommandInterceptorsTxRequiresNew()
chain. In that context the 'inner' command must be able to succeed / fail independently from the 'outer' command.- Author:
- Tom Baeyens, Daniel Meyer, Thorben Lindhauer
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
alwaysOpenNew
if true, we will always open a new command contextprotected CommandContextFactory
commandContextFactory
protected ProcessEngineConfigurationImpl
processEngineConfiguration
-
Fields inherited from class org.camunda.bpm.engine.impl.interceptor.CommandInterceptor
next
-
-
Constructor Summary
Constructors Constructor Description CommandContextInterceptor()
CommandContextInterceptor(CommandContextFactory commandContextFactory, ProcessEngineConfigurationImpl processEngineConfiguration)
CommandContextInterceptor(CommandContextFactory commandContextFactory, ProcessEngineConfigurationImpl processEngineConfiguration, boolean alwaysOpenNew)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
execute(Command<T> command)
CommandContextFactory
getCommandContextFactory()
ProcessEngineConfigurationImpl
getProcessEngineConfiguration()
protected boolean
isFromSameEngine(CommandContext existingCommandContext)
void
setCommandContextFactory(CommandContextFactory commandContextFactory)
void
setProcessEngineContext(ProcessEngineConfigurationImpl processEngineContext)
-
Methods inherited from class org.camunda.bpm.engine.impl.interceptor.CommandInterceptor
getNext, setNext
-
-
-
-
Field Detail
-
commandContextFactory
protected CommandContextFactory commandContextFactory
-
processEngineConfiguration
protected ProcessEngineConfigurationImpl processEngineConfiguration
-
alwaysOpenNew
protected boolean alwaysOpenNew
if true, we will always open a new command context
-
-
Constructor Detail
-
CommandContextInterceptor
public CommandContextInterceptor()
-
CommandContextInterceptor
public CommandContextInterceptor(CommandContextFactory commandContextFactory, ProcessEngineConfigurationImpl processEngineConfiguration)
-
CommandContextInterceptor
public CommandContextInterceptor(CommandContextFactory commandContextFactory, ProcessEngineConfigurationImpl processEngineConfiguration, boolean alwaysOpenNew)
-
-
Method Detail
-
execute
public <T> T execute(Command<T> command)
-
isFromSameEngine
protected boolean isFromSameEngine(CommandContext existingCommandContext)
-
getCommandContextFactory
public CommandContextFactory getCommandContextFactory()
-
setCommandContextFactory
public void setCommandContextFactory(CommandContextFactory commandContextFactory)
-
getProcessEngineConfiguration
public ProcessEngineConfigurationImpl getProcessEngineConfiguration()
-
setProcessEngineContext
public void setProcessEngineContext(ProcessEngineConfigurationImpl processEngineContext)
-
-