1 25 26 package org.objectweb.jonas.resource.pool.lib; 27 28 import org.objectweb.jonas.common.Log; 29 import org.objectweb.jonas.resource.pool.api.Pool; 30 import org.objectweb.util.monolog.api.Logger; 31 import org.objectweb.util.monolog.api.BasicLevel; 32 33 38 public class HArrayPoolMonitor extends Thread { 39 40 43 private Pool pool; 44 47 private Logger logger = null; 48 49 52 private long adjustPeriod = 15 * 1000L; 56 private long samplingPeriod = 60 * 1000L; 60 private long validationPeriod = 10 * 60 * 1000L; 62 65 private long adjustTime = 0; 66 69 private long samplingTime = 0; 70 73 private long validationTime = 0; 74 75 79 public HArrayPoolMonitor(Pool pool) { 80 super("HArrayPoolMonitor"); 81 setDaemon(true); 82 this.pool = pool; 83 logger = Log.getLogger(Log.JONAS_JCA_PREFIX); 84 } 85 86 91 public void setAdjustPeriod(int sec) { 92 if (logger.isLoggable(BasicLevel.DEBUG)) { 93 logger.log(BasicLevel.DEBUG, " to " + sec); 94 } 95 adjustPeriod = sec * 1000L; 96 } 97 98 103 public void setSamplingPeriod(int sec) { 104 if (logger.isLoggable(BasicLevel.DEBUG)) { 105 logger.log(BasicLevel.DEBUG, " to " + sec); 106 } 107 samplingPeriod = sec * 1000L; 108 } 109 110 115 public void setValidationPeriod(int sec) { 116 if (logger.isLoggable(BasicLevel.DEBUG)) { 117 logger.log(BasicLevel.DEBUG, " to " + sec); 118 } 119 validationPeriod = sec * 1000L; 120 } 121 122 125 public void run() { 126 long timeout; 127 resetTimes(); 128 while (true) { 129 timeout = adjustTime; 130 if (samplingTime < timeout) { 131 timeout = samplingTime; 132 } 133 if (validationTime < timeout) { 134 timeout = validationTime; 135 } 136 try { 137 sleep(timeout); 138 adjustTime -= timeout; 139 samplingTime -= timeout; 140 validationTime -= timeout; 141 if (adjustTime <= 0) { 142 pool.adjust(); 143 adjustTime = adjustPeriod; 144 } 145 if (samplingTime <= 0) { 146 pool.sampling(); 147 samplingTime = samplingPeriod; 148 } 149 if (validationTime <= 0) { 150 pool.validateMCs(); 151 validationTime = validationPeriod; 152 } 153 } catch (NullPointerException e) { 154 logger.log(BasicLevel.ERROR, "HArrayPoolMonitor NPE:" + e); 155 e.printStackTrace(); 156 resetTimes(); 157 } catch (Exception e) { 158 logger.log(BasicLevel.ERROR, "HArrayPoolMonitor error:" + e); 159 e.printStackTrace(); 160 resetTimes(); 161 } 162 } 163 } 164 165 private void resetTimes() { 166 adjustTime = adjustPeriod; 167 samplingTime = samplingPeriod; 168 validationTime = validationPeriod; 169 } 170 } 171 | Popular Tags |