1 28 29 30 package org.objectweb.jonas_timer; 31 32 import org.objectweb.util.monolog.api.BasicLevel; 33 34 public class TimerEvent { 35 36 private TimerEventListener listener = null; 37 private Object arg = null; 38 private long remaining; private long startvalue; private long createtime; 41 private boolean permanent = false; 42 private boolean stopped = false; 43 44 51 public TimerEvent(TimerEventListener l, long timeout, Object a, boolean p) { 52 if (TraceTimer.isDebug()) 53 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+l+",timeout = "+timeout+" ,object = "+a+" ,permanent = "+p+")"); 54 listener = l; 55 remaining = timeout; 56 startvalue = timeout; 57 createtime = System.currentTimeMillis(); 58 arg = a; 59 permanent = p; 60 } 61 62 63 68 public long update() { 69 remaining = startvalue + createtime - System.currentTimeMillis(); 70 if (TraceTimer.isDebug() && remaining <= 10) { 71 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" remaining = "+remaining); 72 } 73 return remaining; 74 } 75 76 79 public long restart() { 80 stopped = false; 81 createtime = System.currentTimeMillis() + remaining; 83 remaining += startvalue; 84 if (TraceTimer.isDebug()) 85 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" remaining = "+remaining); 86 return remaining; 87 } 88 89 92 public void process() { 93 if (listener != null) { 94 if (TraceTimer.isDebug()) 95 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" remaining = "+remaining); 96 listener.timeoutExpired(arg); 97 } 98 } 99 100 104 public void change(long timeout, Object a) { 105 if (TraceTimer.isDebug()) 106 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" timeout = "+timeout+",object = "+a); 107 stopped = false; 108 startvalue = timeout; 109 remaining = startvalue; 110 arg = a; 111 } 112 113 116 public void unset() { 117 if (TraceTimer.isDebug()) 118 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener); 119 remaining = 100; 121 arg = null; 122 listener = null; 123 permanent = false; 124 stopped = false; 125 } 126 127 130 public void stop() { 131 if (TraceTimer.isDebug()) 132 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener); 133 remaining = 1000000; 135 stopped = true; 136 } 137 138 141 public boolean valid() { 142 return (listener != null); 143 } 144 145 148 public boolean ispermanent() { 149 return permanent; 150 } 151 152 155 public boolean isStopped() { 156 return stopped; 157 } 158 159 162 public long getRemaining() { 163 return remaining; 164 } 165 } 166 167 | Popular Tags |