📄 executionserviceimpl.java
字号:
public InvocationLog setVariables(String actorId, Long tokenId, Map variables) throws ExecutionException {
InvocationLogImpl invocationLog = null;
// check the input parameters
if ( tokenId == null ) {
throw new NullPointerException( "tokenId is null in a call to ExecutionServiceImpl.setVariables" );
}
PersistenceSessionTx sessionTx = null;
try {
log.info( "processing set-variables for actor '" + actorId + "' on token '" + tokenId + "' : '" + variables + "'..." );
// get a persistence session with a transaction
sessionTx = persistenceSessionFactory.createPersistenceSessionTx();
// load the token from the database
TokenImpl token = (TokenImpl) sessionTx.load( TokenImpl.class, tokenId );
// create the invocation log
invocationLog = new InvocationLogImpl( ServiceMethod.SET_VARIABLES, actorId, token );
token.add( invocationLog );
// obtain a write-lock for the process instance
// this means we do pessimistic locking on endOfState-calls on the level of the process instance
ProcessInstanceImpl processInstance = (ProcessInstanceImpl) token.getProcessInstance();
sessionTx.lock( processInstance );
// create the execution context
ExecutionContextImpl executionContext = new ExecutionContextImpl( actorId, token, sessionTx, this );
// store the variables
executionContext.setVariables( variables );
// save all changes made in the process instance
sessionTx.save( processInstance );
// commit the transaction
sessionTx.commitAndClose();
sessionTx = null;
} catch ( SerializerException e ) {
throw new DelegationException( e.getMessage(), e.getCause() );
} finally {
if ( sessionTx != null ) {
sessionTx.rollbackAndClose();
}
}
return invocationLog;
}
public InvocationLog delegate(String actorId, Long tokenId, String destinationActorId, boolean transferResponsability) throws ExecutionException {
InvocationLogImpl invocationLog = null;
// check the input parameters
if ( tokenId == null ) {
throw new NullPointerException( "tokenId is null in a call to ExecutionServiceImpl.delegate" );
}
if ( destinationActorId == null ) {
throw new NullPointerException( "destinationActorId is null in a call to ExecutionServiceImpl.delegate" );
}
PersistenceSessionTx sessionTx = null;
try {
log.info( "actor '" + actorId + "' delegates token '" + tokenId + "' to actor '" + destinationActorId + "'..." );
// get a persistence session with a transaction
sessionTx = persistenceSessionFactory.createPersistenceSessionTx();
// get the token and lock the process instance
TokenImpl token = loadToken( tokenId, sessionTx );
// create the invocation log
invocationLog = new InvocationLogImpl( ServiceMethod.DELEGATE, actorId, token );
token.add( invocationLog );
// delegate the actual processing to the domain model object
token.setActorId( destinationActorId );
// save the changes
sessionTx.save( token.getProcessInstance() );
// commit the transaction
sessionTx.commitAndClose();
sessionTx = null;
} catch ( SerializerException e ) {
throw new DelegationException( e.getMessage(), e.getCause() );
} finally {
if ( sessionTx != null ) {
sessionTx.rollbackAndClose();
}
}
return invocationLog;
}
public InvocationLog cancelProcessInstance(String actorId, Long processInstanceId) throws ExecutionException {
InvocationLogImpl invocationLog = null;
// check the input parameters
if ( processInstanceId == null ) {
throw new NullPointerException( "processInstanceId is null in a call to ExecutionServiceImpl.cancelProcessInstance" );
}
PersistenceSessionTx sessionTx = null;
try {
log.info( "cancelling process instance '" + processInstanceId + "' for actor '" + actorId + "'..." );
// get a persistence session with a transaction
sessionTx = persistenceSessionFactory.createPersistenceSessionTx();
// get and lock the process instance
ProcessInstanceImpl processInstance = loadProcessInstance( processInstanceId, sessionTx );
// create the invocation log
TokenImpl root = (TokenImpl) processInstance.getRoot();
invocationLog = new InvocationLogImpl( ServiceMethod.CANCEL_PROCESS_INSTANCE, actorId, root );
root.add( invocationLog );
// end the process instance
processInstance.end( new ExecutionContextImpl(actorId, root, sessionTx, this), true );
// save the changes
sessionTx.save( processInstance );
// commit the transaction
sessionTx.commitAndClose();
sessionTx = null;
} catch ( SerializerException e ) {
throw new DelegationException( e.getMessage(), e.getCause() );
} finally {
if ( sessionTx != null ) {
sessionTx.rollbackAndClose();
}
}
return invocationLog;
}
public InvocationLog cancelToken(String actorId, Long tokenId) throws ExecutionException {
InvocationLogImpl invocationLog = null;
// check the input parameters
if ( tokenId == null ) {
throw new NullPointerException( "tokenId is null in a call to ExecutionServiceImpl.cancelToken" );
}
PersistenceSessionTx sessionTx = null;
try {
log.info( "cancelling token '" + tokenId + "' for actor '" + actorId + "'..." );
// get a persistence session with a transaction
sessionTx = persistenceSessionFactory.createPersistenceSessionTx();
// get the token and lock the process instance
TokenImpl token = loadToken( tokenId, sessionTx );
// create the invocation log
invocationLog = new InvocationLogImpl( ServiceMethod.CANCEL_TOKEN, actorId, token );
token.add( invocationLog );
// TODO advanced feature bug : if a token cancellation leads to a join reactivation, the logs should reflect this for later undo
// create an execution context
ExecutionContextImpl executionContext = new ExecutionContextImpl( actorId, token, sessionTx, this );
// end the token
token.end( executionContext, true );
// the the cancelled token is a concurrent subflow
if ( ! token.isRoot() ) {
// check if the join needs to be activated...
// the fork can specify a join that needs to be checked upon token cancellation
// if the token has such a join specified, it is executed.
JoinImpl join = token.getReactivationJoin();
if ( join != null ) {
executionContext.setToken( token );
executionContext.setNode( join );
join.acceptToken( executionContext );
}
}
// save the changes
sessionTx.save( token.getProcessInstance() );
// commit the transaction
sessionTx.commitAndClose();
sessionTx = null;
} catch ( SerializerException e ) {
throw new DelegationException( e.getMessage(), e.getCause() );
} finally {
if ( sessionTx != null ) {
sessionTx.rollbackAndClose();
}
}
return invocationLog;
}
private TokenImpl loadToken( Long tokenId, PersistenceSessionTx sessionTx ) {
// check the tokenId
if ( tokenId == null ) {
throw new NullPointerException( "tokenId is null" );
}
// load the token from the database
TokenImpl token = (TokenImpl) sessionTx.load( TokenImpl.class, tokenId );
// obtain a write-lock for the process instance
// this means we do pessimistic locking
sessionTx.lock( token.getProcessInstance() );
return token;
}
private ProcessInstanceImpl loadProcessInstance( Long processInstanceId, PersistenceSessionTx sessionTx ) {
// check the processInstanceId
if ( processInstanceId == null ) {
throw new NullPointerException( "processInstanceId is null" );
}
// load the processInstance from the database
ProcessInstanceImpl processInstance = (ProcessInstanceImpl) sessionTx.load( ProcessInstanceImpl.class, processInstanceId );
// obtain a write-lock for the process instance
// this means we do pessimistic locking
sessionTx.lock( processInstance );
return processInstance;
}
private void checkActor(String actorId, TokenImpl token, ServiceMethod serviceMethod) throws AuthorizationException {
// if it is configured
if ( checkActors ) {
if ( actorId == null ) {
throw new AuthorizationException( "unauthenticated service method invocation of '" + serviceMethod + "' : actorId was null" );
}
// verify the actor
if ( ! actorId.equals( token.getActorId() ) ) {
throw new AuthorizationException( "swimlane '" + actorId + "' is not allowed to perform service method '" + serviceMethod + "' because swimlane '" + token.getActorId() + "' was assigned to the token." );
}
}
}
private static Log log = LogFactory.getLog(ExecutionServiceImpl.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -