Exemple #1
0
  public DelayedSignal getNextDelayedSignal() {
    synchronized (delayedSignalQueue) {
      while (true) {
        try {
          if (delayedSignalQueue.size() > 0) {
            DelayedSignal sig;
            long delay;
            sig = (DelayedSignal) delayedSignalQueue.get(0);
            delay = sig.getDeliveryTime() - context.getTimeObject().getTimeMs();
            if (delay <= 0) {
              delayedSignalQueue.remove(sig);
              return sig;
            }

            System.out.println("Next delayed signal in " + delay);

            context.getTimeObject().wait(delayedSignalQueue, delay);
          } else {
            if (!isActive()) return null;
            delayedSignalQueue.wait();
          }
        } catch (InterruptedException e) {
          /*
           * InterruptedException is OK.
           */
        }
      }
    }
  }
Exemple #2
0
  /**
   * propogate the next signal from self to all instances. Callers must be synchronized on 'this'
   * object.
   */
  public synchronized boolean propogateNextSignalSelf(Debug debugObject)
      throws LemRuntimeException {
    /*
     * First propogate any elapsed delayed signals to self
     * into the signalSelfQueue.
     */
    while (delayedSignalSelfQueue.size() > 0) {
      DelayedSignal s;
      s = (DelayedSignal) delayedSignalSelfQueue.get(0);
      if (s.getDeliveryTime() <= context.getTimeObject().getTimeMs()) {
        delayedSignalSelfQueue.remove(s);
        addSignalSelf(s);
      } else break;
    }

    if (signalSelfQueue.size() > 0) {
      Signal s = (Signal) signalSelfQueue.remove(0);
      for (Iterator i = instances.iterator(); i.hasNext(); ) {
        Instance in = (Instance) i.next();
        if (in.isActive) {
          in.addSignalSelf(s);
          debugObject.addEntity();
        }
      }
      debugObject.delEntity();
      return true;
    }

    return false;
  }
Exemple #3
0
  public synchronized long getNextDelayedSignalSelfDelay() {
    if (delayedSignalSelfQueue.size() > 0) {
      DelayedSignal sig;
      long delay;
      sig = (DelayedSignal) delayedSignalSelfQueue.get(0);
      delay = sig.getDeliveryTime() - context.getTimeObject().getTimeMs();

      if (delay > 0) return delay;
      return 0;
    } else return -1;
  }
  public void run() {
    while (true) {
      DelayedSignal s = senderObject.getNextDelayedSignal();
      if (s == null) return;

      org.jdns.xtuml.runtime.Object target = s.getTarget();
      System.out.println(target.getObjectId() + " delivered delayed signal");
      synchronized (target) {
        Integer signalId = s.getSignalId();
        Integer targetObjectId = target.getObjectId();
        if (target.isActive()) {
          target.addSignal(s);
        } else {
          /*
           * All interpreters have stopped,
           * signal shouldn't be deliviered.
           */
          context.getDebugObject().delEntity();
        }
      }
    }
  }