org.ow2.jasmine.monitoring.mbeancmd.commands
Class Stat

java.lang.Object
  extended byorg.ow2.jasmine.monitoring.mbeancmd.AbstractCommand
      extended byorg.ow2.jasmine.monitoring.mbeancmd.commands.Stat
All Implemented Interfaces:
Command

public class Stat
extends AbstractCommand

Periodically polls attributes of one or more mbeans on one or more J2EE servers.


Nested Class Summary
private  class Stat.StatContext
          Statistics context.
 
Field Summary
private  org.apache.commons.cli.CommandLine commandLine
          Command line arguments.
private  Stat.StatContext[] context
          Statistics contexts.
private  java.lang.String graphDef
          Graph definitions, null for no graph output.
private  java.lang.String header
          Header to use.
private  boolean isRefreshable
          Is content refresheable ?
private  java.lang.String jasmineURI
          URI of the JASMINe event switch, null for no JASMINe output.
private  javax.management.ObjectName on
          ObjectNale to use.
private  org.apache.commons.cli.Options options
          List of options that should be parsed from the command line.
private  java.lang.String outputFilePath
          Output file path, null for no file output.
private  long period
          Polling period in seconds.
private  java.io.PrintStream pout
          Output stream.
private  long refreshPeriod
          Refresh period, in seconds.
private  java.lang.String separator
          Separator to use.
 
Fields inherited from class org.ow2.jasmine.monitoring.mbeancmd.AbstractCommand
arguments, name, simpleDateFormat
 
Constructor Summary
Stat()
          Constructor: calls setOptions().
 
Method Summary
 int exec()
          Implementation of inherited abstract method.
private  java.lang.String[] getAttToPoll()
           
private  java.lang.String getMBeanPollHeader(javax.management.AttributeList attl)
          Prints a given header.
 void help()
          Calls AbstractCommand.help() and prints the DTD for the graph.
static void main(java.lang.String[] args)
          Tests the Stat implementation.
private  void mbeanPoll()
          Polls the MBeans.
 void parseCommandLine(java.lang.String[] args)
          Parses the command line arguments into commandLine.
private  void printMBeanPoll(long t, Stat.StatContext ctx, javax.management.AttributeList attl, javax.management.ObjectName oname)
          Prints out the poll data based on a header.
private  void process()
          Initializes data polling and calls mbeanPoll().
private  void putArrayIntoHeader(java.lang.StringBuffer buf, javax.management.Attribute att)
          Puts a list of attributes into a buffer.
private  void putCompositeDataIntoHeader(java.lang.StringBuffer buf, javax.management.Attribute att)
          Puts composite data into a buffer.
private  void putMapIntoHeader(java.lang.StringBuffer buf, javax.management.Attribute att)
          Puts a map of attributes into a buffer.
private  void setObjectName()
          Sets the object name based on the "name" argument in the command line.
private  void setOptions()
          Sets all options that are parseable from the command line.
private  void setPeriod()
          Sets the period if the command line has the "p" option.
private  void setRefreshPeriod()
          Sets the refresh period if the command line has the "r" option.
 java.lang.String summary()
          Implementation of inherited abstract method.
 java.lang.String toString()
           
 
Methods inherited from class org.ow2.jasmine.monitoring.mbeancmd.AbstractCommand
getHelpDoc, getName, setArgs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

context

private Stat.StatContext[] context
Statistics contexts.


options

private org.apache.commons.cli.Options options
List of options that should be parsed from the command line.


commandLine

private org.apache.commons.cli.CommandLine commandLine
Command line arguments.


on

private javax.management.ObjectName on
ObjectNale to use.


period

private long period
Polling period in seconds.


refreshPeriod

private long refreshPeriod
Refresh period, in seconds. A value of 0 means refresh at each poll


isRefreshable

private boolean isRefreshable
Is content refresheable ?


graphDef

private java.lang.String graphDef
Graph definitions, null for no graph output.


outputFilePath

private java.lang.String outputFilePath
Output file path, null for no file output.


jasmineURI

private java.lang.String jasmineURI
URI of the JASMINe event switch, null for no JASMINe output.


pout

private java.io.PrintStream pout
Output stream.


separator

private java.lang.String separator
Separator to use.


header

private java.lang.String header
Header to use.

Constructor Detail

Stat

public Stat()
Constructor: calls setOptions().

Method Detail

main

public static void main(java.lang.String[] args)
Tests the Stat implementation.

Parameters:
args - Arguments to pass to Stat#setArgs.

exec

public int exec()
Implementation of inherited abstract method. Will never return except in the case of failure.

Specified by:
exec in interface Command
Specified by:
exec in class AbstractCommand
See Also:
AbstractCommand.exec()

help

public void help()
Calls AbstractCommand.help() and prints the DTD for the graph.

Specified by:
help in interface Command
Overrides:
help in class AbstractCommand
See Also:
Command.help(), AbstractCommand.getHelpDoc()

summary

public java.lang.String summary()
Implementation of inherited abstract method.

Specified by:
summary in interface Command
Specified by:
summary in class AbstractCommand
See Also:
AbstractCommand.summary()

parseCommandLine

public void parseCommandLine(java.lang.String[] args)
                      throws org.apache.commons.cli.ParseException,
                             javax.management.MalformedObjectNameException
Parses the command line arguments into commandLine.

Parameters:
args - Arguments to parse.
Throws:
org.apache.commons.cli.ParseException - If parsing fails.
javax.management.MalformedObjectNameException - Object name given in the command line is invalid.

setObjectName

private void setObjectName()
                    throws javax.management.MalformedObjectNameException
Sets the object name based on the "name" argument in the command line.

Throws:
javax.management.MalformedObjectNameException - Object name given in the command line is invalid.

setPeriod

private void setPeriod()
                throws java.lang.NumberFormatException
Sets the period if the command line has the "p" option.

Throws:
java.lang.NumberFormatException - Number after the "p" option is invalid.

setRefreshPeriod

private void setRefreshPeriod()
                       throws java.lang.NumberFormatException
Sets the refresh period if the command line has the "r" option.

Throws:
java.lang.NumberFormatException - Number after the "r" option is invalid, note that "never" is a valid number.

mbeanPoll

private void mbeanPoll()
Polls the MBeans.


getAttToPoll

private java.lang.String[] getAttToPoll()
Returns:
Attributes to poll.

getMBeanPollHeader

private java.lang.String getMBeanPollHeader(javax.management.AttributeList attl)
Prints a given header.

Parameters:
attl - Header attributes.
Returns:
Printed header.

putArrayIntoHeader

private void putArrayIntoHeader(java.lang.StringBuffer buf,
                                javax.management.Attribute att)
Puts a list of attributes into a buffer.

Parameters:
buf - String buffer to print into.
att - Attribute list.

putMapIntoHeader

private void putMapIntoHeader(java.lang.StringBuffer buf,
                              javax.management.Attribute att)
Puts a map of attributes into a buffer.

Parameters:
buf - String buffer to print into.
att - Attribute map.

putCompositeDataIntoHeader

private void putCompositeDataIntoHeader(java.lang.StringBuffer buf,
                                        javax.management.Attribute att)
Puts composite data into a buffer.

Parameters:
buf - String buffer to print into.
att - Attribute data.

printMBeanPoll

private void printMBeanPoll(long t,
                            Stat.StatContext ctx,
                            javax.management.AttributeList attl,
                            javax.management.ObjectName oname)
Prints out the poll data based on a header.

Parameters:
t - Time.
ctx - Statistics context.
attl - Attribute list.
oname - Object to print as data.

setOptions

private void setOptions()
Sets all options that are parseable from the command line.

See Also:
options

toString

public java.lang.String toString()
Returns:
The ObjectName.

process

private void process()
Initializes data polling and calls mbeanPoll().