1 23 24 36 37 39 package com.sun.enterprise.util; 40 41 import java.util.logging.Level ; 42 import com.sun.enterprise.util.logging.Debug; 43 import com.sun.enterprise.corba.ee.internal.util.LogWrap; 44 import java.util.ArrayList ; 45 import java.util.TimerTask ; 46 import java.util.Iterator ; 47 48 public class MonitorTask extends java.util.TimerTask { 49 50 private static boolean initialized = false; 51 private static boolean needORBMonitoring = false; 52 private static boolean needEJBMonitoring = false; 53 private static boolean needJDBCMonitoring = false; 54 private static ArrayList monitorableList = null; 55 private static long schedPeriod = 180000; private static java.util.Timer timer; 57 58 68 private synchronized static boolean isMonitoring () { 69 if (!initialized) { 70 try { 71 String str1=System.getProperties().getProperty("MONITOR_ORB"); 72 String str2=System.getProperties().getProperty("MONITOR_EJB"); 73 String str3=System.getProperties().getProperty("MONITOR_JDBC"); 74 String strm=System.getProperties().getProperty("MONITOR_TIME_PERIOD_SECONDS"); 75 if( null!=str1 ) { 76 if ( str1.startsWith("true") || str1.startsWith("TRUE") ) { 77 needORBMonitoring = true; 78 } 79 } 80 if ( null!=str2 ) { 81 if ( str2.startsWith("true") || str2.startsWith("TRUE") ) { 82 needEJBMonitoring = true; 83 } 84 } 85 if ( null!=str3 ) { 86 if ( str3.startsWith("true") || str3.startsWith("TRUE") ) { 87 needJDBCMonitoring = true; 88 } 89 } 90 if (needORBMonitoring || needEJBMonitoring || needJDBCMonitoring) { 91 if(null!=strm) { 92 schedPeriod = 1000 * Long.parseLong(strm); 93 } 94 } 95 } catch(Exception e) { 96 LogWrap.logger.log(Level.FINE, 97 "MINOR: Unable to start a performance monitoring task > " + e); 98 } 99 if (needORBMonitoring || needEJBMonitoring || needJDBCMonitoring) { 100 monitorableList = new ArrayList (); 101 timer = new java.util.Timer (); 102 timer.schedule(new MonitorTask(), schedPeriod, schedPeriod); 103 LogWrap.logger.log(Level.SEVERE, 104 "Starting the MonitorTask every "+schedPeriod+" milliseconds."); 105 } 106 initialized = true; 107 } 108 return (needORBMonitoring || needEJBMonitoring || needJDBCMonitoring); 109 } 110 111 118 public static void addORBMonitorable(Object monitorable) { 119 if (isMonitoring() && needORBMonitoring) { 120 monitorableList.add(monitorable); 121 } 122 } 123 124 public static void addEJBMonitorable(Object monitorable) { 125 if (isMonitoring() && needEJBMonitoring) { 126 monitorableList.add(monitorable); 127 } 128 } 129 130 public static void addJDBCMonitorable(Object monitorable) { 131 if (isMonitoring() && needJDBCMonitoring) { 132 monitorableList.add(monitorable); 133 } 134 } 135 136 public static ArrayList getMonitorableList() { 137 return monitorableList; 138 } 139 140 151 public void run() { 152 StringBuffer sb = new StringBuffer (); 153 try { 154 boolean first = true; 155 156 sb.append("MONITORING : "); 157 Iterator iter = MonitorTask.getMonitorableList().iterator(); 158 while (iter.hasNext()) { 159 if (first == false) { 160 sb.append(", "); 161 } else { 162 first = false; 163 } 164 sb.append(iter.next().toString()); 165 } 166 LogWrap.logger.log(Level.SEVERE, sb.toString() ); 167 } catch(Exception e) { 168 LogWrap.logger.log(Level.FINE, "MonitorTask received an exception > " + e); 169 } 170 } 171 172 protected java.util.Timer getTimer() { 173 return timer; 174 } 175 176 } 177 178 | Popular Tags |