MonitorCommandpublic class MonitorCommand extends S1ASCommand This class is the implementation for monitor command. |
Fields Summary |
---|
private static final String | MONITOR_TYPE | private static final String | INTERVAL | private static final String | FILTER | private static final String | FILENAME | public static String[] | validTypes |
Methods Summary |
---|
private java.io.File | getFileName()
File fileName = null;
if (getOption(FILENAME) != null)
{
fileName = new File(getOption(FILENAME));
if (fileName.isDirectory())
{
final File tempFile = fileName;
fileName = new File(tempFile, "monitor.log");
}
}
return fileName;
| private com.sun.appserv.management.monitor.ServerRootMonitor | getServerRootMonitor(com.sun.appserv.management.DomainRoot domainRoot, java.lang.String instanceName)
Map<String,ServerRootMonitor> serverRootMonitorMap =
domainRoot.getMonitoringRoot().getServerRootMonitorMap();
ServerRootMonitor serverRootMonitor = serverRootMonitorMap.get(instanceName);
if (serverRootMonitor == null) {
//***** NEED TO I18N THIS MSG *****//
throw new CommandException("Unable to monitoring" + instanceName);
}
return serverRootMonitor;
| private MonitorTask | getTask(java.lang.String type, com.sun.appserv.management.monitor.ServerRootMonitor srm, java.lang.String filterName, java.util.Timer timer, boolean verbose, java.io.File fileName)
MonitorTask monitorTask = null;
if (type.equals("jvm") )
monitorTask = new JVMMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("jdbcpool"))
monitorTask = new JDBCPoolMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("connectorpool"))
monitorTask = new ConnectorPoolMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("threadpool"))
monitorTask = new ThreadPoolMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("connectionqueue"))
monitorTask = new ConnectionQueueMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("filecache"))
monitorTask = new FileCacheMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("keepalive"))
monitorTask = new KeepAliveMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("httplistener"))
monitorTask = new HttpListenerMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("httpservice"))
monitorTask = new HttpServiceVirtualServerMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("connection"))
monitorTask = new ConnectionManagerMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("webmodule"))
monitorTask = new WebModuleVirtualServerMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("servlet"))
monitorTask = new ServletMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("endpoint"))
monitorTask = new WebServiceEndpointMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("entitybean"))
monitorTask = new EntityBeanMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("messagedriven"))
monitorTask = new MessageDrivenBeanMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("statefulsession"))
monitorTask = new StatefulSessionBeanMonitorTask(srm, filterName, timer, verbose, fileName);
else if (type.equals("statelesssession"))
monitorTask = new StatelessSessionBeanMonitorTask(srm, filterName, timer, verbose, fileName);
else {
StringBuffer sb = new StringBuffer();
sb.append(getLocalizedString("InvalidMonitorType", new Object[] {type}));
for (String validType : validTypes)
{
//if first element, then do not append ","
if (validType.equals(validTypes[0]))
sb.append(" " + validType);
else
sb.append(", "+validType);
}
sb.append(".");
throw new MonitorTaskException(sb.toString());
}
return monitorTask;
| private void | go(java.lang.String user, java.lang.String password, java.lang.String host, int port, boolean verbose, java.io.File fileName, java.lang.String monitorType, long interval, java.lang.String instanceName, java.lang.String filterName)
Timer timer = new Timer();
try
{
//use http connector
MBeanServerConnection mbsc = getMBeanServerConnection(host, port, user, password);
final DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
verifyTargetInstance(domainRoot, instanceName);
final ServerRootMonitor srm = getServerRootMonitor(domainRoot, instanceName);
MonitorTask monitorTask = getTask(monitorType, srm, filterName, timer, verbose, fileName);
timer.scheduleAtFixedRate(monitorTask, 0, interval);
boolean done = false;
// detect if a q or Q key is entered
while (!done)
{
final char c = new CliUtil().getKeyboardInput();
final String str = Character.toString(c);
if (str.equals("q") || str.equals("Q"))
{
timer.cancel();
done = true;
}
else if (str.equals("h") || str.equals("H"))
{
monitorTask.displayDetails();
}
}
}
catch(MonitorTaskException mte) {
timer.cancel();
displayExceptionMessage(mte);
}
catch(Exception e)
{
displayExceptionMessage(e);
}
| public void | runCommand()An abstract method that Executes the command
validateOptions();
final String host = getHost();
final int port = getPort();
final String user = getUser();
final String password = getPassword();
final boolean verbose = !getBooleanOption(TERSE);
final String monitorType = getOption(MONITOR_TYPE);
final long interval = Long.parseLong(getOption(INTERVAL)) * 1000;
final String instanceName = (String) getOperands().get(0);
final String filter = getOption(FILTER);
File fileName = getFileName();
go(user, password, host, port, verbose, fileName, monitorType, interval,
instanceName, filter);
| private void | verifyTargetInstance(com.sun.appserv.management.DomainRoot domainRoot, java.lang.String instanceName)verify that the instanceName is an instance
boolean isServer=false;
isServer = domainRoot.getDomainConfig().getStandaloneServerConfigMap().keySet().contains(instanceName);
if (! isServer )
{
throw new CommandException(getLocalizedString("TargetNotAnInstance",
new Object[] {instanceName}));
}
|
|