public void executeAction(Action action, ExecutionContext executionContext) {
Token token = executionContext.getToken();
// create action log
ActionLog actionLog = new ActionLog(action);
token.startCompositeLog(actionLog);
// if this is an action being executed in an event,
// the token needs to be locked. if this is an action
// being executed as the node behaviour or if the token
// is already locked, the token doesn't need to be locked.
boolean actionMustBeLocked = (executionContext.getEvent() != null) && (!token.isLocked());
try {
// update the execution context
executionContext.setAction(action);
// execute the action
log.debug("executing " + action);
String lockOwnerId = "token[" + token.getId() + "]";
try {
if (actionMustBeLocked) {
token.lock(lockOwnerId);
}
if (UserCodeInterceptorConfig.userCodeInterceptor != null) {
UserCodeInterceptorConfig.userCodeInterceptor.executeAction(action, executionContext);
} else {
action.execute(executionContext);
}
} finally {
if (actionMustBeLocked) {
token.unlock(lockOwnerId);
}
}
} catch (Exception exception) {
// NOTE that Errors are not caught because that might halt the JVM and mask the original Error
log.error("action threw exception: " + exception.getMessage(), exception);
// log the action exception
actionLog.setException(exception);
// if an exception handler is available
raiseException(exception, executionContext);
} finally {
executionContext.setAction(null);