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

WebModuleVirtualServerMonitorTask

public class WebModuleVirtualServerMonitorTask extends MonitorTask

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


             
                                                  
         
    
        super(srm, filter, timer, verbose, fileName);

        
        if (this.filter == null)
            getDefaultFilter();
        else
        {
            final StringTokenizer st = new StringTokenizer(this.filter, ":");
            if (st.countTokens() < 2)
                webFilter = st.nextToken();
            else {
                appFilter = st.nextToken();
                webFilter = st.nextToken();
            }
            verifyFilterValue();
        }
        final String webmoduleVSMonitoringTitle=localStrings.getString("commands.monitor.webmodule_virtual_server_monitoring_title", new Object[] {this.filter});
        final String title = String.format("%1$50s", webmoduleVSMonitoringTitle);
        CLILogger.getInstance().printMessage(title);
        displayHeader();        
    
Methods Summary
private voiddisplayData(WebModuleVirtualServerStats stat)


        final String data = String.format(displayFormat,
                                          stat.getActiveSessionsCurrent().getCount(),
                                          stat.getActiveSessionsHigh().getCount(),
//                                          stat.getCachedSessionsCurrent().getCount(),
//                                          stat.getContainerLatency().getLowWaterMark(),
//                                          stat.getContainerLatency().getHighWaterMark(),
//                                          stat.getContainerLatency().getCurrent(),
                                          stat.getExpiredSessionsTotal().getCount(),
                                          stat.getJSPCount().getCount(),
                                          stat.getJSPErrorCount().getCount(),
                                          stat.getJSPReloadCount().getCount(),
//                                          stat.getPassivatedSessionsCurrent().getCount(),
                                          stat.getRejectedSessionsTotal().getCount(),
                                          stat.getServletProcessingTimes().getCount(),
//                                          stat.getSessionPersistTime().getLowWaterMark(),
//                                          stat.getSessionPersistTime().getHighWaterMark(),
//                                          stat.getSessionPersistTime().getCurrent(),
                                          stat.getSessions().getCurrent(),
//                                          stat.getSessionSize().getLowWaterMark(),
//                                          stat.getSessionSize().getHighWaterMark(),
//                                          stat.getSessionSize().getCurrent(),
                                          stat.getSessionsTotal().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",
                                                  stat.getActiveSessionsCurrent().getCount(),
                                                  stat.getActiveSessionsHigh().getCount(),
                                                  stat.getExpiredSessionsTotal().getCount(),
                                                  stat.getJSPCount().getCount(),
                                                  stat.getJSPErrorCount().getCount(),
                                                  stat.getJSPReloadCount().getCount(),
                                                  stat.getRejectedSessionsTotal().getCount(),
                                                  stat.getServletProcessingTimes().getCount(),
                                                  stat.getSessions().getCurrent(),
                                                  stat.getSessionsTotal().getCount());
            writeToFile(fileData);
        }
    
public voiddisplayDetails()

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

        final String asc = localStrings.getString("commands.monitor.asc");
        final String ash = localStrings.getString("commands.monitor.ash");
        final String est = localStrings.getString("commands.monitor.est");
        final String jc = localStrings.getString("commands.monitor.jc");
        final String jec = localStrings.getString("commands.monitor.jec");
        final String jrc = localStrings.getString("commands.monitor.jrc");
        final String rst = localStrings.getString("commands.monitor.rst");
        final String svpt = localStrings.getString("commands.monitor.svpt");
        final String ss = localStrings.getString("commands.monitor.ss");
        final String sst = localStrings.getString("commands.monitor.sst");
        
        final String header = String.format(displayFormat,
                                            asc,ash,est,jc,jec,jrc,rst,svpt,ss,sst);                                            
            /*
        final String header = String.format(displayFormat,
                                            "asc","ash","csc","low","hi","cur","est","jc","jec",
                                            "psc","rst","svpt","sspt","low","hi","cur","ss","low",
                                            "hi","cur","sst");
            */
        CLILogger.getInstance().printMessage(header);
        if (fileName != null)
        {
            writeToFile(localStrings.getString("commands.monitor.webmodule_virtual_server_write_to_file"));
        }
    
private java.lang.StringgetAvailableFilterMessage(java.lang.String[] appModuleFilters, java.lang.String[] webModuleFilters)

        StringBuffer sb = new StringBuffer();
        sb.append(localStrings.getString("commands.monitor.more_than_one_monitoring_elements"));
        if (webModuleFilters.length > 0)
        {
            sb.append(localStrings.getString("commands.monitor.available_webmodule_elements"));
            for (String webmodule: webModuleFilters)
            {
                sb.append("    ");
                sb.append(webmodule);
                sb.append("\n");
            }
        }
        if (appModuleFilters.length > 0)
        {
            sb.append(localStrings.getString("commands.monitor.available_webmodule_elements_in_appmodule"));
            for (String appmodule: appModuleFilters)
            {
                sb.append("    ");
                sb.append(appmodule);
                sb.append("\n");
            }
        }
        return sb.toString();
    
private voidgetDefaultFilter()
If filter option is not specified, then this method will get the default filter value. WebModuleVirtualServer is in both standalone webmodule or a webmodule in a application. If there are more than one standalone webmodule or an application with a webmodule, this method will display the available filter selections. If there is only one webmodule then that is the default filter value.

        String[] appModuleFilters = possibleAppModuleFilters();
        String[] webModuleFilters = possibleWebModuleFilters();        
            
        if (webModuleFilters.length < 1 && appModuleFilters.length < 1)
        {
            throw new MonitorTaskException(localStrings.getString("command.monitor.no_value_to_monitor"));
        }
        else if (webModuleFilters.length == 1 && appModuleFilters.length < 1)
        {
            webFilter = webModuleFilters[0];
            filter = webFilter;
        }
        else if (webModuleFilters.length < 1 && appModuleFilters.length == 1)
        {
            filter = appModuleFilters[0];
            final StringTokenizer st = new StringTokenizer(filter, ":");
            appFilter = st.nextToken();
            webFilter = st.nextToken();
        }
        else
        {
            final String msg = getAvailableFilterMessage(appModuleFilters, webModuleFilters);
            throw new MonitorTaskException(msg);
        }
    
private java.lang.String[]possibleAppModuleFilters()
Returns all the possible webmodules in all the application. The return format is :

        final Map<String,ApplicationMonitor> appModuleMap = srm.getApplicationMonitorMap();

        List<String> possibleFilters = new Vector<String>();
        if (appModuleMap != null && appModuleMap.size() > 0)
        {
                //search through all application and check for the webmodules
            final String[] appModules = MapUtil.getKeyStrings(appModuleMap);
            for (String appModule : appModules)
            {
                ApplicationMonitor am = (ApplicationMonitor)appModuleMap.get(appModule);
                    //search for the webmodule virtual server in the appmodule
                final Map<String, WebModuleVirtualServerMonitor> innerWebModuleMap = am.getWebModuleVirtualServerMonitorMap();
                if (innerWebModuleMap != null && innerWebModuleMap.size() > 0)
                {
                    final String[] webModules = MapUtil.getKeyStrings(innerWebModuleMap);
                    for (String webModule : webModules)
                        possibleFilters.add(appModule+":"+webModule);
                }
            }
        }
        return (String[])possibleFilters.toArray(new String[0]);
    
private java.lang.String[]possibleWebModuleFilters()

        final Map<String,WebModuleVirtualServerMonitor> webModuleMap = srm.getWebModuleVirtualServerMonitorMap();

        List<String> possibleFilters = new Vector<String>();
        final String[] webModules = MapUtil.getKeyStrings(webModuleMap);
        if (webModuleMap != null && webModuleMap.size() > 0)
        {
            for (String webModule : webModules)
                possibleFilters.add(webModule);
        }
        return (String[])possibleFilters.toArray(new String[0]);
    
public voidrun()

        if (srm == null) {
            super.cancelMonitorTask();
            return;
        }
        
        WebModuleVirtualServerStats vsStat = null;
        Map<String,WebModuleVirtualServerMonitor> webMap = null;
        if (appFilter == null)
            webMap = srm.getWebModuleVirtualServerMonitorMap();
        else
        {
            final Map<String,ApplicationMonitor> appMap = srm.getApplicationMonitorMap();
            if (appMap == null || appMap.size()<1) {
                cancelMonitorTask();
                return;
            }
            
            final ApplicationMonitor am = appMap.get(appFilter);
            if (am == null) {
                cancelMonitorTask();
                return;
            }
            webMap = am.getWebModuleVirtualServerMonitorMap();

        }
        if (webMap == null || webMap.size()<1) cancelMonitorTask();
        final WebModuleVirtualServerMonitor vsMonitor = webMap.get(webFilter);
        if (vsMonitor == null) {
            cancelMonitorTask();
            return;
        }
        
        final WebModuleVirtualServerStats vsStats = vsMonitor.getWebModuleVirtualServerStats();
        if (verbose && counter == NUM_ROWS)
        {
            displayHeader();
            counter = 0;  //reset to 0
        }
        displayData(vsStats);
        if (verbose) counter++;
    
private voidverifyFilterValue()

        if (appFilter != null)
        {
            final Map<String,ApplicationMonitor> appModuleMap = srm.getApplicationMonitorMap();
            if (appModuleMap.containsKey(appFilter))
            {
                final ApplicationMonitor am = appModuleMap.get(appFilter);
                final Map<String, WebModuleVirtualServerMonitor> innerWebModuleMap = am.getWebModuleVirtualServerMonitorMap();
                if (!innerWebModuleMap.containsKey(webFilter))
                    throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist_in1", new Object[] {webFilter, appFilter}));
            }
            else {
                throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist", new Object[] {appFilter}));
            }
        }
        else
        {
            final Map<String,WebModuleVirtualServerMonitor> webModuleMap = srm.getWebModuleVirtualServerMonitorMap();
            if (!webModuleMap.containsKey(webFilter))
                throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist", new Object[] {webFilter}));
        }