예제 #1
1
  public synchronized Signal cancelDelayedSignalSelf(Event e) {
    Iterator i;

    i = signalSelfQueue.iterator();
    while (i.hasNext()) {
      Signal s = (Signal) i.next();
      if (s instanceof DelayedSignal) {
        if (s.getEvent() == e) {
          signalSelfQueue.remove(s);
          return s;
        }
      }
    }

    i = delayedSignalSelfQueue.iterator();
    while (i.hasNext()) {
      Signal s = (Signal) i.next();
      if (s.getEvent() == e) {
        delayedSignalSelfQueue.remove(s);
        return s;
      }
    }

    return null;
  }
예제 #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;
  }
예제 #3
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.
           */
        }
      }
    }
  }
예제 #4
0
 public void addDelayedSignal(DelayedSignal s) {
   synchronized (delayedSignalQueue) {
     if (delayedGenerator == null) delayedGenerator = new SignalGenerator(context, this);
     delayedSignalQueue.add(s);
     delayedSignalQueue.notify();
   }
 }
예제 #5
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;
  }
예제 #6
0
  public synchronized void drainSignals(Debug debug) {
    while (signalQueue.size() > 0) {
      signalQueue.remove(0);
      debug.delEntity();
    }

    while (signalSelfQueue.size() > 0) {
      signalSelfQueue.remove(0);
      debug.delEntity();
    }

    while (delayedSignalSelfQueue.size() > 0) {
      delayedSignalSelfQueue.remove(0);
      debug.delEntity();
    }

    synchronized (delayedSignalQueue) {
      while (delayedSignalQueue.size() > 0) {
        delayedSignalQueue.remove(0);
        debug.delEntity();
      }
    }
  }
예제 #7
0
 public synchronized void addDelayedSignalSelf(DelayedSignal s) {
   delayedSignalSelfQueue.add(s);
   notifyAll();
 }
예제 #8
0
 public void delDelayedSignal(DelayedSignal s) {
   synchronized (delayedSignalQueue) {
     delayedSignalQueue.remove(s);
   }
 }