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

HttpServiceVirtualServerMonitorTask

public class HttpServiceVirtualServerMonitorTask extends MonitorTask

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


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

        final HTTPServiceMonitor httpserviceMonitor = srm.getHTTPServiceMonitor();
        if (httpserviceMonitor == null) 
            throw new MonitorTaskException("Unable to monitor virtualserver");
        final Map<String,HTTPServiceVirtualServerMonitor> httpServiceMap = httpserviceMonitor.getHTTPServiceVirtualServerMonitorMap();
        
        if (httpServiceMap == null)
            throw new MonitorTaskException(localStrings.getString("commands.monitor.unable_to_monitor_virtual_server"));
        
        final String[] keys = MapUtil.getKeyStrings(httpServiceMap);
        if (this.filter == null)
        {
            checkForNumberOfElements(keys);
            this.filter = keys[0];
        }
        else {
            if (!httpServiceMap.containsKey(this.filter)) {
                throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist", new Object[] {this.filter}));
            }
        }
        final String virtualServerTitle=localStrings.getString("commands.monitor.virtual_server_title", new Object[] {this.filter});
        final String title = String.format("%1$50s", virtualServerTitle);
        CLILogger.getInstance().printMessage(title);
        displayHeader();        
    
Methods Summary
private voiddisplayData(HTTPServiceVirtualServerStats vss)

        final String data = String.format(displayFormat,
                                          vss.getHosts().getCurrent(),
                                          vss.getID().getCurrent(),
                                          vss.getInterfaces().getCurrent(),
                                          vss.getMode().getCurrent());
        CLILogger.getInstance().printMessage(data);
        if (fileName != null)
        {
            final String fileData = String.format("%1$s,%2$s,%3$s,%4$s,",
                                          vss.getHosts().getCurrent(),
                                          vss.getID().getCurrent(),
                                          vss.getInterfaces().getCurrent(),
                                          vss.getMode().getCurrent());
            writeToFile(fileData);
        }
    
public voiddisplayDetails()

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

        final String hosts = localStrings.getString("commands.monitor.hosts");
        final String id = localStrings.getString("commands.monitor.id");
        final String interfaces = localStrings.getString("commands.monitor.interfaces");
        final String mode = localStrings.getString("commands.monitor.mode");
        
        final String header = String.format(displayFormat, hosts,id,interfaces,mode);
        CLILogger.getInstance().printMessage(header);
        if (fileName != null)
        {
            writeToFile(hosts+","+id+","+interfaces+","+mode);            
        }
    
public voidrun()

        if (srm == null) {
            super.cancelMonitorTask();
            return;
        }
        

        final HTTPServiceMonitor httpserviceMonitor = srm.getHTTPServiceMonitor();
        if (httpserviceMonitor == null) {
            cancelMonitorTask();
            return;
        }
        
        final Map<String,HTTPServiceVirtualServerMonitor> httpServiceMap = httpserviceMonitor.getHTTPServiceVirtualServerMonitorMap();
        if (httpServiceMap == null || httpServiceMap.size()<1) {
            cancelMonitorTask();
            return;
        }
        
        final HTTPServiceVirtualServerMonitor httpServiceMonitor = httpServiceMap.get(filter);
        if (httpServiceMonitor == null) {
            cancelMonitorTask();
            return;
        }
            
        final HTTPServiceVirtualServerStats httpServiceStats = httpServiceMonitor.getHTTPServiceVirtualServerStats();
        if (verbose && counter == NUM_ROWS)
        {
            displayHeader();
            counter = 0;  //reset to 0
        }
        displayData(httpServiceStats);
        if (verbose) counter++;