FileDocCategorySizeDatePackage
ThreadPoolMonitorTask.javaAPI DocGlassfish v2 API9933Fri May 04 22:25:18 BST 2007com.sun.enterprise.cli.commands.monitor

ThreadPoolMonitorTask

public class ThreadPoolMonitorTask extends MonitorTask

Fields Summary
private final String
displayFormat
Constructors Summary
public ThreadPoolMonitorTask(ServerRootMonitor srm, String filter, Timer timer, boolean verbose, File fileName)


             
                                      
         
    
        super(srm, filter, timer, verbose, fileName);
        final Map<String,ThreadPoolMonitor> threadpoolMap = srm.getThreadPoolMonitorMap();
        if (threadpoolMap == null)
                throw new MonitorTaskException(localStrings.getString("commands.monitor.unable_to_monitor_threadpool"));
        final String[] keys = MapUtil.getKeyStrings(threadpoolMap);
        if (this.filter == null)
        {
            checkForNumberOfElements(keys);
            this.filter = keys[0];
        }
        else {
            if (!threadpoolMap.containsKey(this.filter)) {
                throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist", new Object[] {this.filter}));
            }
        }
        final String threadPoolMonitoringTitle=localStrings.getString("commands.monitor.thread_pool_monitoring_title", new Object[] {this.filter});
        final String title = String.format("%1$70s", threadPoolMonitoringTitle);
        CLILogger.getInstance().printMessage(title);
        displayHeader();        
    
Methods Summary
private voiddisplayData(ThreadPoolStats tps)

        final String data = String.format(displayFormat,
                                          tps.getAverageTimeInQueue().getLowWaterMark(),
                                          tps.getAverageTimeInQueue().getHighWaterMark(),
                                          tps.getAverageTimeInQueue().getCurrent(),
                                          tps.getAverageWorkCompletionTime().getLowWaterMark(), 
                                          tps.getAverageWorkCompletionTime().getHighWaterMark(),
                                          tps.getAverageWorkCompletionTime().getCurrent(),
                                          tps.getCurrentNumberOfThreads().getLowerBound(),
                                          tps.getCurrentNumberOfThreads().getUpperBound(),
                                          tps.getCurrentNumberOfThreads().getLowWaterMark(),
                                          tps.getCurrentNumberOfThreads().getHighWaterMark(),
                                          tps.getCurrentNumberOfThreads().getCurrent(),
                                          tps.getNumberOfAvailableThreads().getCount(),
                                          tps.getNumberOfBusyThreads().getCount(),
                                          tps.getTotalWorkItemsAdded().getCount());
        CLILogger.getInstance().printMessage(data);
        if (fileName != null)
        {
            final String fileData = String.format("%1$s,%2$s,%3$s,%4$s,%5$s,%6$s,%7$s,%8$s,%9$s,"+
                                                  "%10$s,%11$s,%12$s,%13$s,%14$s",
                                                  tps.getAverageTimeInQueue().getLowWaterMark(),
                                                  tps.getAverageTimeInQueue().getHighWaterMark(),
                                                  tps.getAverageTimeInQueue().getCurrent(),
                                                  tps.getAverageWorkCompletionTime().getLowWaterMark(), 
                                                  tps.getAverageWorkCompletionTime().getHighWaterMark(),
                                                  tps.getAverageWorkCompletionTime().getCurrent(),
                                                  tps.getCurrentNumberOfThreads().getLowerBound(),
                                                  tps.getCurrentNumberOfThreads().getUpperBound(),
                                                  tps.getCurrentNumberOfThreads().getLowWaterMark(),
                                                  tps.getCurrentNumberOfThreads().getHighWaterMark(),
                                                  tps.getCurrentNumberOfThreads().getCurrent(),
                                                  tps.getNumberOfAvailableThreads().getCount(),
                                                  tps.getNumberOfBusyThreads().getCount(),
                                                  tps.getTotalWorkItemsAdded().getCount());
            writeToFile(fileData);
        }
    
public voiddisplayDetails()

        final String details = localStrings.getString("commands.monitor.thread_pool_detail");
        CLILogger.getInstance().printMessage(details);
    
private voiddisplayHeader()

        final String avgTimeInQueue=localStrings.getString("commands.monitor.AvgTimeInQueue");
        final String avgWorkCompTime=localStrings.getString("commands.monitor.AvgWorkCompTime");
        final String currNumOfThreads=localStrings.getString("commands.monitor.CurrNumOfThreads");
        final String low = localStrings.getString("commands.monitor.low");
        final String hi = localStrings.getString("commands.monitor.hi");
        final String cur = localStrings.getString("commands.monitor.cur");
        final String min = localStrings.getString("commands.monitor.min");        
        final String max = localStrings.getString("commands.monitor.max");
        final String avl = localStrings.getString("commands.monitor.avl");
        final String busy = localStrings.getString("commands.monitor.busy");
        final String add = localStrings.getString("commands.monitor.add");
        
        final String header = String.format("%1$2s %2$18s %3$30s",
                                            avgTimeInQueue, avgWorkCompTime,currNumOfThreads);
        final String subHeader = String.format(displayFormat,
                                               low,hi,cur,low,hi,cur,min,max,
                                               low,hi,cur,avl,busy,add);
        
        CLILogger.getInstance().printMessage(header);
        CLILogger.getInstance().printMessage(subHeader);        
        if (fileName != null)
        {
            writeToFile(localStrings.getString("commands.monitor.thread_pool_write_to_file"));
        }
    
private voidmonitorThreadPool(java.lang.String element, java.util.Map threadpoolMap)

        final ThreadPoolMonitor threadpoolMonitor = threadpoolMap.get(element);
        final ThreadPoolStats threadpoolStats = threadpoolMonitor.getThreadPoolStats();

        displayData(threadpoolStats);
    
public voidrun()

        if (srm == null) {
            super.cancelMonitorTask();
            return;
        }
        
        final Map<String,ThreadPoolMonitor> threadpoolMap = srm.getThreadPoolMonitorMap();
        
            //maybe lost connection?
        if (threadpoolMap == null || threadpoolMap.size()<1) {
            cancelMonitorTask();
            return;
        }
        
        if (verbose && counter == NUM_ROWS)
        {
            displayHeader();
            counter = 0;  //reset to 0
        }
        monitorThreadPool(filter, threadpoolMap);
        if (verbose) counter++;