PoolKeeper.java

00001 
00026 package org.objectweb.jonas.dbm;
00027 import org.objectweb.jonas.common.Log;
00028 import org.objectweb.util.monolog.api.Logger;
00029 import org.objectweb.util.monolog.api.BasicLevel;
00030 
00036 public class PoolKeeper extends Thread {
00037 
00041     private Pool pool;
00045     private Logger logger = null;
00049     private long adjustperiod = 15000L;  // default = 15s
00053     private long samplingperiod = 60000L;  // default = 60s
00054 
00059     public PoolKeeper(Pool pool) {
00060         super("PoolKeeper");
00061         setDaemon(true);
00062         this.pool = pool;
00063         logger = Log.getLogger(Log.JONAS_DBM_PREFIX);
00064     }
00065 
00073     public void setSamplingPeriod(int sec) {
00074         logger.log(BasicLevel.DEBUG, " to " + sec);
00075         samplingperiod = sec * 1000L;
00076     }
00077 
00081     public void run() {
00082         long timeout;
00083         long adjusttime = adjustperiod;
00084         long samplingtime = samplingperiod;
00085         while (true) {
00086             timeout = adjusttime;
00087             if (samplingtime < timeout) {
00088                 timeout = samplingtime;
00089             }
00090             try {
00091                 sleep(timeout);
00092                 adjusttime -= timeout;
00093                 samplingtime -= timeout;
00094                 if (adjusttime <= 0) {
00095                     pool.adjust();
00096                     adjusttime = adjustperiod;
00097                 }
00098                 if (samplingtime <= 0) {
00099                     pool.sampling();
00100                     samplingtime = samplingperiod;
00101                 }
00102             } catch (NullPointerException e) {
00103                 logger.log(BasicLevel.ERROR, "poolkeeper NPE:" + e);
00104                 e.printStackTrace();
00105             } catch (Exception e) {
00106                 logger.log(BasicLevel.ERROR, "poolkeeper error:" + e);
00107                 e.printStackTrace();
00108             }
00109         }
00110     }
00111 }

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