Пример #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
 /**
  * Checks for valid PIM field.
  *
  * @param type list type
  * @param field identifier for field
  * @return <code>true</code> if field is valid
  */
 static boolean isValidPIMField(int type, int field) {
   switch (type) {
     case PIM.CONTACT_LIST:
       return ContactImpl.isValidPIMField(field);
     case PIM.EVENT_LIST:
       return EventImpl.isValidPIMField(field);
     case PIM.TODO_LIST:
       return ToDoImpl.isValidPIMField(field);
     default:
       return false;
   }
 }
Пример #3
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;
 }
Пример #4
0
  /*
   * Complete the construction of an EventSet.  This is called from
   * an event handler thread.  It upacks the JDWP events inside
   * the packet and creates EventImpls for them.  The EventSet is already
   * on EventQueues when this is called, so it has to be synch.
   */
  synchronized void build() {
    if (pkt == null) {
      return;
    }
    PacketStream ps = new PacketStream(vm, pkt);
    JDWP.Event.Composite compEvt = new JDWP.Event.Composite(vm, ps);
    suspendPolicy = compEvt.suspendPolicy;
    if ((vm.traceFlags & vm.TRACE_EVENTS) != 0) {
      switch (suspendPolicy) {
        case JDWP.SuspendPolicy.ALL:
          vm.printTrace("EventSet: SUSPEND_ALL");
          break;

        case JDWP.SuspendPolicy.EVENT_THREAD:
          vm.printTrace("EventSet: SUSPEND_EVENT_THREAD");
          break;

        case JDWP.SuspendPolicy.NONE:
          vm.printTrace("EventSet: SUSPEND_NONE");
          break;
      }
    }

    ThreadReference fix6485605 = null;
    for (int i = 0; i < compEvt.events.length; i++) {
      EventImpl evt = createEvent(compEvt.events[i]);
      if ((vm.traceFlags & vm.TRACE_EVENTS) != 0) {
        try {
          vm.printTrace("Event: " + evt);
        } catch (VMDisconnectedException ee) {
          // ignore - see bug 6502716
        }
      }

      switch (evt.destination()) {
        case UNKNOWN_EVENT:
          // Ignore disabled, deleted, unknown events, but
          // save the thread if there is one since we might
          // have to resume it.  Note that events for different
          // threads can't be in the same event set.
          if (evt instanceof ThreadedEventImpl
              && suspendPolicy == JDWP.SuspendPolicy.EVENT_THREAD) {
            fix6485605 = ((ThreadedEventImpl) evt).thread();
          }
          continue;
        case CLIENT_EVENT:
          addEvent(evt);
          break;
        case INTERNAL_EVENT:
          if (internalEventSet == null) {
            internalEventSet = new EventSetImpl(this.vm, null);
          }
          internalEventSet.addEvent(evt);
          break;
        default:
          throw new InternalException("Invalid event destination");
      }
    }
    pkt = null; // No longer needed - free it up

    // Avoid hangs described in 6296125, 6293795
    if (super.size() == 0) {
      // This set has no client events.  If we don't do
      // needed resumes, no one else is going to.
      if (suspendPolicy == JDWP.SuspendPolicy.ALL) {
        vm.resume();
      } else if (suspendPolicy == JDWP.SuspendPolicy.EVENT_THREAD) {
        // See bug 6485605.
        if (fix6485605 != null) {
          fix6485605.resume();
        } else {
          // apparently, there is nothing to resume.
        }
      }
      suspendPolicy = JDWP.SuspendPolicy.NONE;
    }
  }
  public boolean dispatchEvent(Event evt) throws EventException {
    // We need to use the internal APIs to modify and access the event status
    EventImpl eventImpl = (EventImpl) evt;

    if (!eventImpl.isInitialized()) {
      throw new EventException(EventException.UNSPECIFIED_EVENT_TYPE_ERR, "Event not initialized");
    } else if ((eventImpl.getType() == null) || eventImpl.getType().equals("")) {
      throw new EventException(EventException.UNSPECIFIED_EVENT_TYPE_ERR, "Unspecified even type");
    }

    // Initialize event status
    eventImpl.setTarget(mNodeTarget);

    // TODO: At this point, to support event capturing and bubbling, we should
    // establish the chain of EventTargets from the top of the tree to this
    // event's target.

    // TODO: CAPTURING_PHASE skipped

    // Handle AT_TARGET
    // Invoke handleEvent of non-capturing listeners on this EventTarget.
    eventImpl.setEventPhase(Event.AT_TARGET);
    eventImpl.setCurrentTarget(mNodeTarget);
    if (!eventImpl.isPropogationStopped() && (mListenerEntries != null)) {
      for (int i = 0; i < mListenerEntries.size(); i++) {
        EventListenerEntry listenerEntry = mListenerEntries.get(i);
        if (!listenerEntry.mUseCapture && listenerEntry.mType.equals(eventImpl.getType())) {
          try {
            listenerEntry.mListener.handleEvent(eventImpl);
          } catch (Exception e) {
            // Any exceptions thrown inside an EventListener will
            // not stop propagation of the event
            Log.w(TAG, "Catched EventListener exception", e);
          }
        }
      }
    }

    if (eventImpl.getBubbles()) {
      // TODO: BUBBLING_PHASE skipped
    }

    return eventImpl.isPreventDefault();
  }