TimerEvent.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): ____________________________________.
00022  * Contributor(s): ______________________________________.
00023  *
00024  * --------------------------------------------------------------------------
00025  * $Id: TimerEvent.java,v 1.10 2004/05/17 09:57:47 durieuxp Exp $
00026  * --------------------------------------------------------------------------
00027  */
00028 
00029 
00030 package org.objectweb.jonas_timer;
00031 
00032 import org.objectweb.util.monolog.api.BasicLevel;
00033 
00034 public class TimerEvent {
00035 
00036     private TimerEventListener listener = null;
00037     private Object arg = null;
00038     private long remaining;     // millisec
00039     private long startvalue;    // millisec
00040     private long createtime;
00041     private boolean permanent = false;
00042     private boolean stopped = false;
00043 
00051     public TimerEvent(TimerEventListener l, long timeout, Object a, boolean p) {
00052         if (TraceTimer.isDebug())
00053             TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+l+",timeout = "+timeout+" ,object = "+a+" ,permanent = "+p+")");
00054         listener = l;
00055         remaining = timeout;
00056         startvalue = timeout;
00057         createtime = System.currentTimeMillis();
00058         arg = a;
00059         permanent = p;
00060     }
00061 
00062 
00068     public long update() {
00069         remaining = startvalue + createtime - System.currentTimeMillis();
00070         if (TraceTimer.isDebug() && remaining <= 10) {
00071             TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" remaining = "+remaining);
00072         }
00073         return remaining;
00074     }
00075 
00079     public long restart() {
00080         stopped = false;
00081         // remaining should be < 0 here.
00082         createtime = System.currentTimeMillis() + remaining;
00083         remaining += startvalue;
00084         if (TraceTimer.isDebug())
00085             TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" remaining = "+remaining);
00086         return remaining;
00087     }
00088 
00092     public void process() {
00093         if (listener != null) {
00094             if (TraceTimer.isDebug())
00095                 TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" remaining = "+remaining);
00096             listener.timeoutExpired(arg);
00097         }
00098     }
00099 
00104     public void change(long timeout, Object a) {
00105         if (TraceTimer.isDebug())
00106             TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener+" timeout = "+timeout+",object = "+a);
00107         stopped = false;
00108         startvalue = timeout;
00109         remaining = startvalue;
00110         arg = a;
00111     }
00112 
00116     public void unset() {
00117         if (TraceTimer.isDebug())
00118             TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener);
00119         // the timerlist is not locked.
00120         remaining = 100;
00121         arg = null;
00122         listener = null;
00123         permanent = false;
00124         stopped = false;
00125     }
00126 
00130     public void stop() {
00131         if (TraceTimer.isDebug())
00132             TraceTimer.logger.log(BasicLevel.DEBUG,"listener = "+listener);
00133         // the timerlist is not locked.
00134         remaining = 1000000;
00135         stopped = true;
00136     }
00137 
00141     public boolean valid() {
00142         return (listener != null);
00143     }
00144 
00148     public boolean ispermanent() {
00149         return permanent;
00150     }
00151 
00155     public boolean isStopped() {
00156         return stopped;
00157     }
00158 
00162     public long getRemaining() {
00163         return remaining;
00164     }
00165 }
00166 

Generated on Tue Feb 15 15:05:57 2005 for JOnAS by  doxygen 1.3.9.1