Пример #1
0
 /**
  * Post the event to be evaluated. The event is blocking, meaning that it will cause the caller to
  * continue execution until the event is processed.
  *
  * @param entity - the target of the event
  * @param event - the event event
  * @param arguments - the arguments to the event
  * @return
  * @throws Throwable
  */
 @Override
 public Object postContinuingEvent(EntityReference entity, int event, Object... arguments)
     throws Throwable {
   assert blockingEvent == null;
   assert currentEvent != null;
   if (restoreFrame()) {
     returnFrame = null;
     return currentEvent.getContinuation().returnFrom();
   }
   blockingEvent = createEvent(currentTime, entity, event, arguments);
   continuingEvent = currentEvent.clone(currentTime);
   currentFrame = BASE;
   return null;
 }
Пример #2
0
 /**
  * The heart of the event processing loop. This is where the events are actually evaluated.
  *
  * @param next - the event to evaluate.
  * @throws SimulationException - if an exception occurs during the evaluation of the event.
  */
 protected void evaluate(EventImpl next) throws SimulationException {
   currentEvent = next;
   currentTime = currentEvent.getTime();
   Continuation continuation = currentEvent.getContinuation();
   if (continuation != null) {
     returnFrame = continuation.getFrame();
     caller = continuation.getCaller();
   }
   Throwable exception = null;
   Object result = null;
   try {
     if (eventLog != null) {
       eventLog.info(currentEvent.toString());
     }
     result = currentEvent.invoke();
   } catch (SimulationEnd e) {
     throw e;
   } catch (Throwable e) {
     if (caller == null || blockingEvent != null) {
       throw new SimulationException(e);
     }
     exception = e;
   } finally {
     currentEvent = null;
   }
   if (blockingEvent != null) {
     continuingEvent.setContinuation(new Continuation(caller, currentFrame));
     blockingEvent.setContinuation(new Continuation(continuingEvent));
     post(blockingEvent);
     blockingEvent = null;
     continuingEvent = null;
     currentFrame = null;
   } else if (caller != null) {
     post(caller.resume(currentTime, result, exception));
   }
   caller = null;
   returnFrame = null;
 }