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

java.lang.Object
  extended by org.ow2.jasmine.monitoring.mbeancmd.AbstractCommand
      extended by org.ow2.jasmine.monitoring.mbeancmd.commands.Mbean
All Implemented Interfaces:
Command

public class Mbean
extends AbstractCommand

Command that can do any given action on any MBean.


Field Summary
private  org.apache.commons.cli.CommandLine commandLine
          Command line arguments.
private  java.lang.String method
          Method to invoke.
private  javax.management.ObjectName on
          The object name based on the "name" argument in the command line.
private  org.apache.commons.cli.Options options
          List of options that should be parsed from the command line.
private  long period
          Polling period in milliseconds.
 
Fields inherited from class org.ow2.jasmine.monitoring.mbeancmd.AbstractCommand
arguments, name, simpleDateFormat
 
Constructor Summary
Mbean()
          Constructor: calls setOptions().
 
Method Summary
 void exec()
          Implementation of inherited abstract method.
private  java.lang.String[] getAttToPoll()
           
private  void mbeanGet()
          Retrieves attributes of a mbean.
private  void mbeanInfo()
          Prints information about MBeans.
private  void mbeanInvoke()
          Invokes the operation given as command line argument.
private  void mbeanMGet()
          Retrieves attributes of one or more mbeans.
private  void mbeanPoll()
          Periodically polls attributes of one or more mbeans.
private  void mbeanQuery()
          Queries the method method of the on object.
private  void mbeanSet()
          Grabs the options for setting MBean attributes.
private  void mbeanUnregister()
          Unregisters the MBean given as a command line argument.
 void parseCommandLine(java.lang.String[] args)
          Parses the command line arguments into commandLine.
private  java.lang.Object[] parseMethodParams(java.lang.String[] args, java.lang.String[] opSig)
          Parses parameters of a given method.
private  java.lang.String[] parseMethodSig(java.lang.String[] args)
          Parses a method signature to grab arguments
private  void printMBeanGet(javax.management.ObjectName ongot, javax.management.AttributeList attl)
          Prints the list of attributes for an MBean.
private  void printMBeanPoll(long t, javax.management.AttributeList attl)
          Prints the output data: date;time + atts.
private  void printMBeanPollHeader(java.lang.String[] atts)
          Prints the output header: date;time + atts.
 void process()
          Processes the request.
private  void setMethod()
          Sets the GET method if the command line has the "get" option.
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.
 java.lang.String summary()
          Implementation of inherited abstract method.
 java.lang.String toString()
           
 
Methods inherited from class org.ow2.jasmine.monitoring.mbeancmd.AbstractCommand
Exit, getHelpDoc, getName, help, setArgs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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
The object name based on the "name" argument in the command line.


method

private java.lang.String method
Method to invoke.


period

private long period
Polling period in milliseconds.

Constructor Detail

Mbean

public Mbean()
Constructor: calls setOptions().

Method Detail

exec

public void exec()
Implementation of inherited abstract method. Will never return if a period is set in the command line.

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

summary

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

Specified by:
summary in interface Command
Specified by:
summary in class AbstractCommand
Returns:
Command's summary.
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.

setMethod

private void setMethod()
Sets the GET method if the command line has the "get" option.


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.

mbeanQuery

private void mbeanQuery()
Queries the method method of the on object.

See Also:
setMethod(), setObjectName()

mbeanGet

private void mbeanGet()
Retrieves attributes of a mbean.


mbeanMGet

private void mbeanMGet()
Retrieves attributes of one or more mbeans.


printMBeanGet

private void printMBeanGet(javax.management.ObjectName ongot,
                           javax.management.AttributeList attl)
Prints the list of attributes for an MBean.

Parameters:
ongot - Object name.
attl - List of attributes.

mbeanPoll

private void mbeanPoll()
Periodically polls attributes of one or more mbeans.


getAttToPoll

private java.lang.String[] getAttToPoll()
Returns:
List of attributes to poll (read from command line).

printMBeanPollHeader

private void printMBeanPollHeader(java.lang.String[] atts)
Prints the output header: date;time + atts.

Parameters:
atts - List of attributes.

printMBeanPoll

private void printMBeanPoll(long t,
                            javax.management.AttributeList attl)
Prints the output data: date;time + atts.

Parameters:
t - Time.
attl - List of attributes.

mbeanInfo

private void mbeanInfo()
Prints information about MBeans.


mbeanSet

private void mbeanSet()
Grabs the options for setting MBean attributes.


parseMethodSig

private java.lang.String[] parseMethodSig(java.lang.String[] args)
Parses a method signature to grab arguments. - Parameters are conveyed by a list of type-value(s) - Parameter separator is "," Example: java.lang.string x , [Ljava.lang.String a b c

Parameters:
args - Signature to parse.
Returns:
Parsed method signature. null if no arguments present.

parseMethodParams

private java.lang.Object[] parseMethodParams(java.lang.String[] args,
                                             java.lang.String[] opSig)
                                      throws java.lang.ClassNotFoundException,
                                             java.lang.NoSuchMethodException,
                                             java.lang.InstantiationException,
                                             java.lang.IllegalAccessException,
                                             java.lang.reflect.InvocationTargetException
Parses parameters of a given method.

Parameters:
args - Method signature to parse.
opSig - @see parseMethodSig(String[])
Returns:
Parsed parameters.
Throws:
java.lang.ClassNotFoundException - Class not found.
java.lang.NoSuchMethodException - Method not found.
java.lang.InstantiationException - Cannot instantiate argument's class.
java.lang.IllegalAccessException - Cannot access class.
java.lang.reflect.InvocationTargetException - Invocation problem.

mbeanInvoke

private void mbeanInvoke()
Invokes the operation given as command line argument.


mbeanUnregister

private void mbeanUnregister()
Unregisters the MBean given as a command line argument.


setOptions

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

See Also:
options

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Returns stringified on

process

public void process()
Processes the request.