FileDocCategorySizeDatePackage
MonitorTask.javaAPI DocGlassfish v2 API7818Fri May 04 22:32:08 BST 2007com.sun.enterprise.util

MonitorTask

public class MonitorTask extends TimerTask
This task is put in a Timer thread and is executed every N seconds. This task prints in the output the monitorabled of the ORB.
author
Darpan Dinker, $Author: tcfujii $
version
$Revision: 1.4 $ on $Date: 2007/05/05 05:32:07 $
since
jdk1.4 Note: None of the methods in this class are synchronized, it is assumed that code which is using this class would take care of synchronization if there is a need. Most cases where initialization of these monitorables is done during server startup should not require any kind of synchronization

Fields Summary
private static boolean
initialized
private static boolean
needORBMonitoring
private static boolean
needEJBMonitoring
private static boolean
needJDBCMonitoring
private static ArrayList
monitorableList
private static long
schedPeriod
private static Timer
timer
Constructors Summary
Methods Summary
public static voidaddEJBMonitorable(java.lang.Object monitorable)

        if (isMonitoring() && needEJBMonitoring) {
            monitorableList.add(monitorable);
        }
    
public static voidaddJDBCMonitorable(java.lang.Object monitorable)

        if (isMonitoring() && needJDBCMonitoring) {
            monitorableList.add(monitorable);
        }
    
public static voidaddORBMonitorable(java.lang.Object monitorable)
Other subsystems in the ORB can use this method to add monitorable entities which are then dumped at the preset intervals. The only requirement for adding an object to the list is that it should implement the toString interface so that details about the object are dumped

        if (isMonitoring() && needORBMonitoring) {
            monitorableList.add(monitorable);
        }
    
public static java.util.ArrayListgetMonitorableList()

        return monitorableList;
    
protected java.util.TimergetTimer()

        return timer;
    
private static synchronized booleanisMonitoring()
This method will read the System properties and look for "MONITOR_ORB". "MONITOR_EJB". "MONITOR_JDBC". If the string exists, the monitoring task shall be created at every MONITOR_TIME_PERIOD_SECONDS if provided too, otherwise defaults will be taken for scheduling period.


                                              
          
        if (!initialized) {
            try {
                String str1=System.getProperties().getProperty("MONITOR_ORB");
                String str2=System.getProperties().getProperty("MONITOR_EJB");
                String str3=System.getProperties().getProperty("MONITOR_JDBC");
                String strm=System.getProperties().getProperty("MONITOR_TIME_PERIOD_SECONDS");
                if( null!=str1 ) {
                    if ( str1.startsWith("true") || str1.startsWith("TRUE") ) {
                        needORBMonitoring = true;
                    }
                }
                if ( null!=str2 ) {
                    if ( str2.startsWith("true") || str2.startsWith("TRUE") ) {
                        needEJBMonitoring = true;
                    }
                }
                if ( null!=str3 ) {
                    if ( str3.startsWith("true") || str3.startsWith("TRUE") ) {
                        needJDBCMonitoring = true;
                    }
                }
                if (needORBMonitoring || needEJBMonitoring || needJDBCMonitoring) {
                    if(null!=strm) {
                        schedPeriod = 1000 * Long.parseLong(strm);
                    }
                }
            } catch(Exception e) {
                LogWrap.logger.log(Level.FINE,
                                   "MINOR: Unable to start a performance monitoring task > " + e);
            }
            if (needORBMonitoring || needEJBMonitoring || needJDBCMonitoring) {
                monitorableList = new ArrayList();
                timer = new java.util.Timer();
                timer.schedule(new MonitorTask(), schedPeriod, schedPeriod);
                LogWrap.logger.log(Level.SEVERE,
                                   "Starting the MonitorTask every "+schedPeriod+" milliseconds.");
            }
            initialized = true;
        }
        return (needORBMonitoring || needEJBMonitoring || needJDBCMonitoring);
    
public voidrun()
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

The general contract of the method run is that it may take any action whatsoever.

see
java.lang.Thread#run()

        StringBuffer sb = new StringBuffer ();
        try {
            boolean first = true;

            sb.append("MONITORING : ");
            Iterator iter = MonitorTask.getMonitorableList().iterator();
            while (iter.hasNext()) {
                if (first == false) {
                    sb.append(", ");
                } else {
                    first = false;
                }
                sb.append(iter.next().toString());
            }            
            LogWrap.logger.log(Level.SEVERE, sb.toString() );
        } catch(Exception e) {
            LogWrap.logger.log(Level.FINE, "MonitorTask received an exception > " + e);
        }