home *** CD-ROM | disk | FTP | other *** search
- package com.everyware.tango.jas;
-
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class Timer extends Thread {
- private JAS jas;
- private Vector timedEvents = new Vector();
-
- public Timer(JAS var1) {
- super("Timer");
- this.jas = var1;
- }
-
- public synchronized void register(Timeable var1, Object var2, int var3) throws Exception {
- if (this.jas.isTracing && this.jas.traceM != null) {
- this.jas.traceM.trace("TR: Registering: source=" + var1 + " event=" + var2 + " duration=" + var3);
- }
-
- if (var1 != null && var2 != null && var3 > 0) {
- this.timedEvents.addElement(new TimedEvent(var1, var2, var3));
- } else {
- if (this.jas.isTracing && this.jas.traceM != null) {
- this.jas.traceM.trace("TR: Cannot register null objects");
- }
-
- throw new Exception("TR: Cannot register null objects");
- }
- }
-
- public synchronized void deregister(Object var1) {
- Enumeration var2 = this.timedEvents.elements();
-
- while(var2.hasMoreElements()) {
- TimedEvent var3 = (TimedEvent)var2.nextElement();
- if (var3.event.equals(var1)) {
- if (this.jas.isTracing && this.jas.traceM != null) {
- this.jas.traceM.trace("TR: found desired event to deregister");
- }
-
- this.timedEvents.removeElement(var3);
- return;
- }
- }
-
- }
-
- public void run() {
- while(true) {
- if (this.jas.isTracing && this.jas.traceM != null) {
- this.jas.traceM.trace("TR: " + this.timedEvents.size() + " timed event(s) to check");
- }
-
- long var1 = System.currentTimeMillis();
- Vector var3 = (Vector)this.timedEvents.clone();
- Enumeration var4 = var3.elements();
-
- while(var4.hasMoreElements()) {
- TimedEvent var5 = (TimedEvent)var4.nextElement();
- if (var5.endOfDuration < var1) {
- if (this.jas.isTracing && this.jas.traceM != null) {
- this.jas.traceM.trace("TR: elapsed: " + var5.event);
- }
-
- var5.source.eventElapsed(var5.event);
- this.timedEvents.removeElement(var5);
- }
- }
-
- try {
- Thread.sleep(1000L);
- } catch (InterruptedException var6) {
- }
- }
- }
- }
-