private void fireEvent(EventContext event, TransactionContext txContext) { if (logger.isDebugEnabled()) { logger.debug("Firing " + event); } final ActivityEventQueueManager aeqm = event.getLocalActivityContext() .getEventQueueManager(); if (aeqm != null) { if (txContext != null) { // put event as pending in ac event queue manager aeqm.pending(event); // add tx actions to commit or rollback txContext.getAfterCommitPriorityActions().add( new CommitEventContextAction(event, aeqm)); txContext.getAfterRollbackActions().add( new RollbackEventContextAction(event, aeqm)); } else { // commit event, there is no tx aeqm.fireNotTransacted(event); } } else { throw new SLEEException("unable to find ACs event queue manager"); } }
public void execute() { if(!canceled) { transactionalAction = null; switch (op) { case suspend: suspended = true; transaction = tx; // put a barrier in the event queue manager for this activity, to // freeze the event routing on this activity at that level event.getLocalActivityContext().getEventQueueManager().createBarrier(tx); // init queue to store events about to be routed (after this one), // which may have passed the barrier barriedEvents = new LinkedList<EventContext>(); // set state as suspended suspended = true; // schedule task scheduledFuture = sleeContainer.getNonClusteredScheduler().schedule(new SuspensionTimerTask(),timeout,TimeUnit.MILLISECONDS); break; case resume: resume(); break; default: throw new SLEEException("unxpected op type when executing event context state change"); } } }
@Override public void suspend() throws TransactionRequiredLocalException, SLEEException { final SleeTransactionManager txManager = sleeContainer .getTransactionManager(); txManager.mandateTransaction(); try { final SleeTransaction tx = txManager.getTransaction(); final ActivityEventQueueManager aeqm = activityContext .getLocalActivityContext().getEventQueueManager(); aeqm.createBarrier(tx); final TransactionalAction action = new TransactionalAction() { public void execute() { aeqm.removeBarrier(tx); } }; final TransactionContext tc = tx.getTransactionContext(); tc.getAfterCommitActions().add(action); tc.getAfterRollbackActions().add(action); } catch (Throwable e) { throw new SLEEException(e.getMessage(), e); } } }
final ActivityEventQueueManager aeqm = ac.getLocalActivityContext().getEventQueueManager(); aeqm.createBarrier(barrierTx); TransactionalAction action = new TransactionalAction() {
public void run() { if (scheduledFuture == null) { // already resumed return; } // cancel timer task scheduledFuture.cancel(false); scheduledFuture = null; // send events frozen to event router again, will be processed only after this one ends (this one is already being executed) for (EventContext ec : barriedEvents) { ec.getLocalActivityContext().getExecutorService().routeEvent(ec); } barriedEvents = null; // remove barrier on activity event queue event.getLocalActivityContext().getEventQueueManager().removeBarrier(transaction); // remove suspension suspended = false; // continue routing the event related with this context event.getLocalActivityContext().getCurrentEventRoutingTask().run(); } };
.getLocalActivityContext().getEventQueueManager(); eventQueue.createBarrier(tx); TransactionalAction action = new TransactionalAction() {
final ActivityEventQueueManager aeqm = ac.getLocalActivityContext().getEventQueueManager(); aeqm.createBarrier(barrierTx); TransactionalAction action = new TransactionalAction() {
final ActivityEventQueueManager aeqm = ac.getLocalActivityContext().getEventQueueManager(); aeqm.createBarrier(barrierTx); TransactionalAction action = new TransactionalAction() {