public Object execute(JbpmContext jbpmContext)
{
final boolean isDebugEnabled = logger.isDebugEnabled() ;
try {
PortReference portRef = callbackEpr.getAddr();
long nodeId = Long.parseLong(portRef.getExtensionValue(Constants.NODE_ID));
long tokenId = Long.parseLong(portRef.getExtensionValue(Constants.TOKEN_ID));
long processInstanceId = Long.parseLong(portRef.getExtensionValue(Constants.PROCESS_INSTANCE_ID));
String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId + '_' + tokenId;
long processNodeVersion = Long.parseLong(portRef.getExtensionValue(counterName));
if (isDebugEnabled) logger.debug("Expected nodeId=" + nodeId + ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
//get update on current state of things.
final Token token = jbpmContext.getToken(tokenId) ;
if (token == null) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer active") ;
}
final ProcessInstance instance = token.getProcessInstance() ;
if (instance == null) {
throw new CallbackException("Process instance " + processInstanceId + " is no longer active") ;
}
if (instance.getId() != processInstanceId) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " now attached to process instance " + instance.getId()) ;
}
if (nodeId != token.getNode().getId()) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is no longer on expected node, expected " + nodeId + " but discovered " + token.getNode().getId()) ;
}
if (token.hasEnded()) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " has already terminated") ;
}
if (token.isLocked()) {
throw new CallbackException("Token id " + tokenId + " from process instance " + processInstanceId + " is already locked, another thread is active") ;
}
final ContextInstance contextInstance = instance.getContextInstance() ;
final long currentProcessNodeVersion = Long.parseLong(String.valueOf(contextInstance.getVariableLocally(counterName, token)));
if (isDebugEnabled) logger.debug("ProcessNodeVersion=" + currentProcessNodeVersion);
if (processNodeVersion!=currentProcessNodeVersion) {
throw new CallbackException("The current processNodeVersion (id=" + currentProcessNodeVersion + ") is not the expected version (version=" + processNodeVersion + ").");
}
final String globalProcessScopeVal = portRef.getExtensionValue(Constants.PROCESS_SCOPE_ATTR) ;
// Default to global scope as that matches the previous functionality
// N.B. This is different from retrieving variables!!
final boolean globalProcessScope = (globalProcessScopeVal == null ? true : Boolean.parseBoolean(globalProcessScopeVal));
Map<Mapping, Object> variablesMap = getVariablesMapFromMessage(token.getNode(), message);