home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #6 / Datatid_1999-06.iso / internet / Tango352Promo / Tango / data.z / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-02-03  |  2.5 KB  |  77 lines

  1. package com.everyware.tango.jas;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Vector;
  5.  
  6. public class Timer extends Thread {
  7.    private JAS jas;
  8.    private Vector timedEvents = new Vector();
  9.  
  10.    public Timer(JAS var1) {
  11.       super("Timer");
  12.       this.jas = var1;
  13.    }
  14.  
  15.    public synchronized void register(Timeable var1, Object var2, int var3) throws Exception {
  16.       if (this.jas.isTracing && this.jas.traceM != null) {
  17.          this.jas.traceM.trace("TR: Registering: source=" + var1 + " event=" + var2 + " duration=" + var3);
  18.       }
  19.  
  20.       if (var1 != null && var2 != null && var3 > 0) {
  21.          this.timedEvents.addElement(new TimedEvent(var1, var2, var3));
  22.       } else {
  23.          if (this.jas.isTracing && this.jas.traceM != null) {
  24.             this.jas.traceM.trace("TR: Cannot register null objects");
  25.          }
  26.  
  27.          throw new Exception("TR: Cannot register null objects");
  28.       }
  29.    }
  30.  
  31.    public synchronized void deregister(Object var1) {
  32.       Enumeration var2 = this.timedEvents.elements();
  33.  
  34.       while(var2.hasMoreElements()) {
  35.          TimedEvent var3 = (TimedEvent)var2.nextElement();
  36.          if (var3.event.equals(var1)) {
  37.             if (this.jas.isTracing && this.jas.traceM != null) {
  38.                this.jas.traceM.trace("TR: found desired event to deregister");
  39.             }
  40.  
  41.             this.timedEvents.removeElement(var3);
  42.             return;
  43.          }
  44.       }
  45.  
  46.    }
  47.  
  48.    public void run() {
  49.       while(true) {
  50.          if (this.jas.isTracing && this.jas.traceM != null) {
  51.             this.jas.traceM.trace("TR: " + this.timedEvents.size() + " timed event(s) to check");
  52.          }
  53.  
  54.          long var1 = System.currentTimeMillis();
  55.          Vector var3 = (Vector)this.timedEvents.clone();
  56.          Enumeration var4 = var3.elements();
  57.  
  58.          while(var4.hasMoreElements()) {
  59.             TimedEvent var5 = (TimedEvent)var4.nextElement();
  60.             if (var5.endOfDuration < var1) {
  61.                if (this.jas.isTracing && this.jas.traceM != null) {
  62.                   this.jas.traceM.trace("TR: elapsed: " + var5.event);
  63.                }
  64.  
  65.                var5.source.eventElapsed(var5.event);
  66.                this.timedEvents.removeElement(var5);
  67.             }
  68.          }
  69.  
  70.          try {
  71.             Thread.sleep(1000L);
  72.          } catch (InterruptedException var6) {
  73.          }
  74.       }
  75.    }
  76. }
  77.