ActivityContextHandle _startActivity ( ActivityHandle handle , int activityFlags , final SleeTransaction barrierTx ) { ActivityContext ac = null ; if ( raEntity . getHandleReferenceFactory ( ) != null && ! ActivityFlags . hasSleeMayMarshal ( activityFlags ) ) { final ActivityHandleReference reference = raEntity . getHandleReferenceFactory ( ) . createActivityHandleReference ( handle ) ; try { // create activity context with ref instead ac = acFactory . createActivityContext ( new ResourceAdaptorActivityContextHandleImpl ( raEntity , reference ) , activityFlags ) ; } catch ( ActivityAlreadyExistsException e ) { throw e ; } catch ( RuntimeException e ) { raEntity . getHandleReferenceFactory ( ) . removeActivityHandleReference ( reference ) ; throw e ; } } else { // create activity context ac = acFactory . createActivityContext ( new ResourceAdaptorActivityContextHandleImpl ( raEntity , handle ) , activityFlags ) ; } // suspend activity if needed if ( barrierTx != null && ac != null ) { final ActivityEventQueueManager aeqm = ac . getLocalActivityContext ( ) . getEventQueueManager ( ) ; aeqm . createBarrier ( barrierTx ) ; TransactionalAction action = new TransactionalAction ( ) { public void execute ( ) { aeqm . removeBarrier ( barrierTx ) ; } } ; final TransactionContext tc = barrierTx . getTransactionContext ( ) ; tc . getAfterCommitActions ( ) . add ( action ) ; tc . getAfterRollbackActions ( ) . add ( action ) ; } return ac . getActivityContextHandle ( ) ; }
Start activity logic independent of transaction management .