Class MessageCorrelationBuilderImpl
- java.lang.Object
-
- org.camunda.bpm.engine.impl.MessageCorrelationBuilderImpl
-
- All Implemented Interfaces:
MessageCorrelationBuilder
public class MessageCorrelationBuilderImpl extends Object implements MessageCorrelationBuilder
- Author:
- Daniel Meyer, Christopher Zell
-
-
Field Summary
Fields Modifier and Type Field Description protected String
businessKey
protected CommandContext
commandContext
protected CommandExecutor
commandExecutor
protected VariableMap
correlationLocalVariables
protected VariableMap
correlationProcessInstanceVariables
protected boolean
executionsOnly
protected boolean
isExclusiveCorrelation
protected boolean
isTenantIdSet
protected String
messageName
protected VariableMap
payloadProcessInstanceVariables
protected VariableMap
payloadProcessInstanceVariablesLocal
protected String
processDefinitionId
protected String
processInstanceId
protected boolean
startMessagesOnly
protected String
tenantId
-
Constructor Summary
Constructors Constructor Description MessageCorrelationBuilderImpl(CommandContext commandContext, String messageName)
MessageCorrelationBuilderImpl(CommandExecutor commandExecutor, String messageName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
correlate()
Executes the message correlation.void
correlateAll()
Executes the message correlation for multiple messages.List<MessageCorrelationResult>
correlateAllWithResult()
Executes the message correlation for multiple messages and returns a list of message correlation results.List<MessageCorrelationResultWithVariables>
correlateAllWithResultAndVariables(boolean deserializeValues)
Executes the message correlation.void
correlateExclusively()
Behaves likeMessageCorrelationBuilder.correlate()
, however uses pessimistic locking for correlating a waiting execution, meaning that two threads correlating a message to the same execution in parallel do not end up continuing the process in parallel until the next wait state is reachedProcessInstance
correlateStartMessage()
Executes the message correlation.MessageCorrelationResult
correlateWithResult()
Executes the message correlation and returns aMessageCorrelationResult
object.MessageCorrelationResultWithVariables
correlateWithResultAndVariables(boolean deserializeValues)
Executes the message correlation.protected void
ensureCorrelationLocalVariablesInitialized()
protected void
ensureCorrelationProcessInstanceVariablesInitialized()
protected void
ensureCorrelationVariablesNotSet()
protected void
ensurePayloadProcessInstanceVariablesInitialized()
protected void
ensurePayloadProcessInstanceVariablesLocalInitialized()
protected void
ensureProcessDefinitionAndTenantIdNotSet()
protected void
ensureProcessDefinitionIdNotSet()
protected void
ensureProcessInstanceAndTenantIdNotSet()
protected <T> T
execute(Command<T> command)
MessageCorrelationBuilder
executionsOnly()
String
getBusinessKey()
CommandContext
getCommandContext()
CommandExecutor
getCommandExecutor()
Map<String,Object>
getCorrelationLocalVariables()
Map<String,Object>
getCorrelationProcessInstanceVariables()
String
getMessageName()
Map<String,Object>
getPayloadProcessInstanceVariables()
VariableMap
getPayloadProcessInstanceVariablesLocal()
String
getProcessDefinitionId()
String
getProcessInstanceId()
String
getTenantId()
boolean
isExclusiveCorrelation()
boolean
isExecutionsOnly()
boolean
isTenantIdSet()
MessageCorrelationBuilder
localVariableEquals(String variableName, Object variableValue)
Correlate the message such that the execution has a local variable with the given name and value.MessageCorrelationBuilder
localVariablesEqual(Map<String,Object> variables)
Correlate the message such that the execution has the given variables as local variables.MessageCorrelationBuilder
processDefinitionId(String processDefinitionId)
Correlate the message such that a process definition with the given id is selected.MessageCorrelationBuilder
processInstanceBusinessKey(String businessKey)
Correlate the message such that the process instance has a business key with the given name.MessageCorrelationBuilder
processInstanceId(String id)
Correlate the message such that a process instance with the given id is selected.MessageCorrelationBuilder
processInstanceVariableEquals(String variableName, Object variableValue)
Correlate the message such that the process instance has a variable with the given name and value.MessageCorrelationBuilder
processInstanceVariablesEqual(Map<String,Object> variables)
Correlate the message such that the process instance has the given variables.MessageCorrelationBuilder
setVariable(String variableName, Object variableValue)
Pass a variable to the execution waiting on the message.MessageCorrelationBuilder
setVariableLocal(String variableName, Object variableValue)
Pass a local variable to the execution waiting on the message.MessageCorrelationBuilder
setVariables(Map<String,Object> variables)
Pass a map of variables to the execution waiting on the message.MessageCorrelationBuilder
setVariablesLocal(Map<String,Object> variables)
Pass a map of local variables to the execution waiting on the message.MessageCorrelationBuilder
startMessageOnly()
Specify that only start message can be correlated.MessageCorrelationBuilder
tenantId(String tenantId)
Specify a tenant to deliver the message to.MessageCorrelationBuilder
withoutTenantId()
Specify that the message can only be received on executions or process definitions which belongs to no tenant.
-
-
-
Field Detail
-
commandExecutor
protected CommandExecutor commandExecutor
-
commandContext
protected CommandContext commandContext
-
isExclusiveCorrelation
protected boolean isExclusiveCorrelation
-
messageName
protected String messageName
-
businessKey
protected String businessKey
-
processInstanceId
protected String processInstanceId
-
processDefinitionId
protected String processDefinitionId
-
correlationProcessInstanceVariables
protected VariableMap correlationProcessInstanceVariables
-
correlationLocalVariables
protected VariableMap correlationLocalVariables
-
payloadProcessInstanceVariables
protected VariableMap payloadProcessInstanceVariables
-
payloadProcessInstanceVariablesLocal
protected VariableMap payloadProcessInstanceVariablesLocal
-
tenantId
protected String tenantId
-
isTenantIdSet
protected boolean isTenantIdSet
-
startMessagesOnly
protected boolean startMessagesOnly
-
executionsOnly
protected boolean executionsOnly
-
-
Constructor Detail
-
MessageCorrelationBuilderImpl
public MessageCorrelationBuilderImpl(CommandExecutor commandExecutor, String messageName)
-
MessageCorrelationBuilderImpl
public MessageCorrelationBuilderImpl(CommandContext commandContext, String messageName)
-
-
Method Detail
-
processInstanceBusinessKey
public MessageCorrelationBuilder processInstanceBusinessKey(String businessKey)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that the process instance has a business key with the given name. If the message is correlated to a message start event then the given business key is set on the created process instance.
- Specified by:
processInstanceBusinessKey
in interfaceMessageCorrelationBuilder
- Parameters:
businessKey
- the businessKey to correlate on.- Returns:
- the builder
-
processInstanceVariableEquals
public MessageCorrelationBuilder processInstanceVariableEquals(String variableName, Object variableValue)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that the process instance has a variable with the given name and value.
- Specified by:
processInstanceVariableEquals
in interfaceMessageCorrelationBuilder
- Parameters:
variableName
- the name of the process instance variable to correlate on.variableValue
- the value of the process instance variable to correlate on.- Returns:
- the builder
-
processInstanceVariablesEqual
public MessageCorrelationBuilder processInstanceVariablesEqual(Map<String,Object> variables)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that the process instance has the given variables.
- Specified by:
processInstanceVariablesEqual
in interfaceMessageCorrelationBuilder
- Parameters:
variables
- the variables of the process instance to correlate on.- Returns:
- the builder
-
localVariableEquals
public MessageCorrelationBuilder localVariableEquals(String variableName, Object variableValue)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that the execution has a local variable with the given name and value.
- Specified by:
localVariableEquals
in interfaceMessageCorrelationBuilder
- Parameters:
variableName
- the name of the local variable to correlate on.variableValue
- the value of the local variable to correlate on.- Returns:
- the builder
-
localVariablesEqual
public MessageCorrelationBuilder localVariablesEqual(Map<String,Object> variables)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that the execution has the given variables as local variables.
- Specified by:
localVariablesEqual
in interfaceMessageCorrelationBuilder
- Parameters:
variables
- the local variables of the execution to correlate on.- Returns:
- the builder
-
ensureCorrelationProcessInstanceVariablesInitialized
protected void ensureCorrelationProcessInstanceVariablesInitialized()
-
ensureCorrelationLocalVariablesInitialized
protected void ensureCorrelationLocalVariablesInitialized()
-
processInstanceId
public MessageCorrelationBuilder processInstanceId(String id)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that a process instance with the given id is selected.
- Specified by:
processInstanceId
in interfaceMessageCorrelationBuilder
- Parameters:
id
- the id of the process instance to correlate on.- Returns:
- the builder
-
processDefinitionId
public MessageCorrelationBuilder processDefinitionId(String processDefinitionId)
Description copied from interface:MessageCorrelationBuilder
Correlate the message such that a process definition with the given id is selected. Is only supported for
MessageCorrelationBuilder.correlateStartMessage()
orMessageCorrelationBuilder.startMessageOnly()
flag.- Specified by:
processDefinitionId
in interfaceMessageCorrelationBuilder
- Parameters:
processDefinitionId
- the id of the process definition to correlate on.- Returns:
- the builder
-
setVariable
public MessageCorrelationBuilder setVariable(String variableName, Object variableValue)
Description copied from interface:MessageCorrelationBuilder
Pass a variable to the execution waiting on the message. Use this method for passing the message's payload.
Invoking this method multiple times allows passing multiple variables.
- Specified by:
setVariable
in interfaceMessageCorrelationBuilder
- Parameters:
variableName
- the name of the variable to setvariableValue
- the value of the variable to set- Returns:
- the builder
-
setVariableLocal
public MessageCorrelationBuilder setVariableLocal(String variableName, Object variableValue)
Description copied from interface:MessageCorrelationBuilder
Pass a local variable to the execution waiting on the message. Use this method for passing the message's payload.
Invoking this method multiple times allows passing multiple variables.
- Specified by:
setVariableLocal
in interfaceMessageCorrelationBuilder
- Parameters:
variableName
- the name of the variable to setvariableValue
- the value of the variable to set- Returns:
- the builder
-
setVariables
public MessageCorrelationBuilder setVariables(Map<String,Object> variables)
Description copied from interface:MessageCorrelationBuilder
Pass a map of variables to the execution waiting on the message. Use this method for passing the message's payload
- Specified by:
setVariables
in interfaceMessageCorrelationBuilder
- Parameters:
variables
- the map of variables- Returns:
- the builder
-
setVariablesLocal
public MessageCorrelationBuilder setVariablesLocal(Map<String,Object> variables)
Description copied from interface:MessageCorrelationBuilder
Pass a map of local variables to the execution waiting on the message. Use this method for passing the message's payload
- Specified by:
setVariablesLocal
in interfaceMessageCorrelationBuilder
- Parameters:
variables
- the map of local variables- Returns:
- the builder
-
ensurePayloadProcessInstanceVariablesInitialized
protected void ensurePayloadProcessInstanceVariablesInitialized()
-
ensurePayloadProcessInstanceVariablesLocalInitialized
protected void ensurePayloadProcessInstanceVariablesLocalInitialized()
-
tenantId
public MessageCorrelationBuilder tenantId(String tenantId)
Description copied from interface:MessageCorrelationBuilder
Specify a tenant to deliver the message to. The message can only be received on executions or process definitions which belongs to the given tenant. Cannot be used in combination withMessageCorrelationBuilder.processInstanceId(String)
orMessageCorrelationBuilder.processDefinitionId(String)
.- Specified by:
tenantId
in interfaceMessageCorrelationBuilder
- Parameters:
tenantId
- the id of the tenant- Returns:
- the builder
-
withoutTenantId
public MessageCorrelationBuilder withoutTenantId()
Description copied from interface:MessageCorrelationBuilder
Specify that the message can only be received on executions or process definitions which belongs to no tenant. Cannot be used in combination withMessageCorrelationBuilder.processInstanceId(String)
orMessageCorrelationBuilder.processDefinitionId(String)
.- Specified by:
withoutTenantId
in interfaceMessageCorrelationBuilder
- Returns:
- the builder
-
startMessageOnly
public MessageCorrelationBuilder startMessageOnly()
Description copied from interface:MessageCorrelationBuilder
Specify that only start message can be correlated.- Specified by:
startMessageOnly
in interfaceMessageCorrelationBuilder
- Returns:
- the builder
-
executionsOnly
public MessageCorrelationBuilder executionsOnly()
-
correlate
public void correlate()
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation.- Specified by:
correlate
in interfaceMessageCorrelationBuilder
-
correlateWithResult
public MessageCorrelationResult correlateWithResult()
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation and returns aMessageCorrelationResult
object.The call of this method will result in either:
- Exactly one waiting execution is notified to continue. The notification is performed synchronously. The result contains the execution id.
- Exactly one Process Instance is started in case the message name matches a message start event of a process. The instantiation is performed synchronously. The result contains the start event activity id and process definition.
- MismatchingMessageCorrelationException is thrown. This means that either too many executions / process definitions match the correlation or that no execution and process definition matches the correlation.
MessageCorrelationResult.getResultType()
.- Specified by:
correlateWithResult
in interfaceMessageCorrelationBuilder
- Returns:
- The result of the message correlation. Result contains either the execution id or the start event activity id and the process definition.
-
correlateWithResultAndVariables
public MessageCorrelationResultWithVariables correlateWithResultAndVariables(boolean deserializeValues)
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation. If you do not need access to the process variables, useMessageCorrelationBuilder.correlateWithResult()
to avoid unnecessary variable access.- Specified by:
correlateWithResultAndVariables
in interfaceMessageCorrelationBuilder
- Parameters:
deserializeValues
- if false, returnedSerializableValue
s will not be deserialized (unless they are passed into this method as a deserialized value or if the BPMN process triggers deserialization)- Returns:
- The result of the message correlation. Result contains either the execution id or the start event activity id, the process definition, and the process variables.
-
correlateExclusively
public void correlateExclusively()
Description copied from interface:MessageCorrelationBuilder
Behaves like
MessageCorrelationBuilder.correlate()
, however uses pessimistic locking for correlating a waiting execution, meaning that two threads correlating a message to the same execution in parallel do not end up continuing the process in parallel until the next wait state is reachedCAUTION: Wherever there are pessimistic locks, there is a potential for deadlocks to occur. This can either happen when multiple messages are correlated in parallel, but also with other race conditions such as a message boundary event on a user task. The process engine is not able to detect such a potential. In consequence, the user of this API should investigate this potential in his/her use case and implement countermeasures if needed.
A less error-prone alternative to this method is to set appropriate async boundaries in the process model such that parallel message correlation is solved by optimistic locking.
- Specified by:
correlateExclusively
in interfaceMessageCorrelationBuilder
-
correlateAll
public void correlateAll()
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation for multiple messages.- Specified by:
correlateAll
in interfaceMessageCorrelationBuilder
-
correlateAllWithResult
public List<MessageCorrelationResult> correlateAllWithResult()
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation for multiple messages and returns a list of message correlation results.This will result in any number of the following:
- Any number of waiting executions are notified to continue. The notification is performed synchronously. The result list contains the execution ids of the notified executions.
- Any number of process instances are started which have a message start event that matches the message name. The instantiation is performed synchronously. The result list contains the start event activity ids and process definitions from all activities on that the messages was correlated to.
Note that the message correlates to all tenants if no tenant is specified using
MessageCorrelationBuilder.tenantId(String)
orMessageCorrelationBuilder.withoutTenantId()
.- Specified by:
correlateAllWithResult
in interfaceMessageCorrelationBuilder
- Returns:
- The result list of the message correlations. Each result contains either the execution id or the start event activity id and the process definition.
-
correlateAllWithResultAndVariables
public List<MessageCorrelationResultWithVariables> correlateAllWithResultAndVariables(boolean deserializeValues)
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation. If you do not need access to the process variables, useMessageCorrelationBuilder.correlateAllWithResult()
to avoid unnecessary variable access.- Specified by:
correlateAllWithResultAndVariables
in interfaceMessageCorrelationBuilder
- Parameters:
deserializeValues
- if false, returnedSerializableValue
s will not be deserialized (unless they are passed into this method as a deserialized value or if the BPMN process triggers deserialization)- Returns:
- The result list of the message correlations. Each result contains either the execution id or the start event activity id, the process definition, and the process variables.
-
correlateStartMessage
public ProcessInstance correlateStartMessage()
Description copied from interface:MessageCorrelationBuilder
Executes the message correlation.This will result in either:
- Exactly one Process Instance is started in case the message name matches a message start event of a process. The instantiation is performed synchronously.
- MismatchingMessageCorrelationException is thrown. This means that either no process definition or more than one process definition matches the correlation.
- Specified by:
correlateStartMessage
in interfaceMessageCorrelationBuilder
- Returns:
- the newly created process instance
-
ensureProcessDefinitionIdNotSet
protected void ensureProcessDefinitionIdNotSet()
-
ensureProcessInstanceAndTenantIdNotSet
protected void ensureProcessInstanceAndTenantIdNotSet()
-
ensureCorrelationVariablesNotSet
protected void ensureCorrelationVariablesNotSet()
-
ensureProcessDefinitionAndTenantIdNotSet
protected void ensureProcessDefinitionAndTenantIdNotSet()
-
execute
protected <T> T execute(Command<T> command)
-
getCommandExecutor
public CommandExecutor getCommandExecutor()
-
getCommandContext
public CommandContext getCommandContext()
-
getMessageName
public String getMessageName()
-
getBusinessKey
public String getBusinessKey()
-
getProcessInstanceId
public String getProcessInstanceId()
-
getProcessDefinitionId
public String getProcessDefinitionId()
-
getCorrelationProcessInstanceVariables
public Map<String,Object> getCorrelationProcessInstanceVariables()
-
getPayloadProcessInstanceVariablesLocal
public VariableMap getPayloadProcessInstanceVariablesLocal()
-
isExclusiveCorrelation
public boolean isExclusiveCorrelation()
-
getTenantId
public String getTenantId()
-
isTenantIdSet
public boolean isTenantIdSet()
-
isExecutionsOnly
public boolean isExecutionsOnly()
-
-