org.ow2.jasmine.monitoring.mbeancmd
Class CommandDispatcher

java.lang.Object
  extended by org.ow2.jasmine.monitoring.mbeancmd.CommandDispatcher

public class CommandDispatcher
extends java.lang.Object

This is the main class of the archive. It dispatches the processing of the command to the right class. The available commands in the current archive are retrieved by introspection of the archive. In order to execute a command, a dispatcher instance is created and initialized with the command's arguments. The command object gets a reference on its dispatcher, so it can report its state changes to the dispatcher. Then, the dispatcher sets status information in the thread executing the command.


Nested Class Summary
static class CommandDispatcher.CommandStatus
           
 
Field Summary
protected  Command cmd
           
protected static org.ow2.util.log.Log logger
          Logger.
 
Constructor Summary
protected CommandDispatcher()
          Dummy constructor to avoid the class from being used in any other way than calling the CommandDispatcher.main method.
 
Method Summary
 java.lang.String[] getAvailableCommands()
          Returns the names of the available commands in the archive.
 Command getCommand(java.lang.String name)
          Returns an instance of Command.
protected  java.io.InputStreamReader getInputStreamReader(java.lang.String name)
          Return an inputStreamReader for the specified resource, by using the context class loader.
 int init(java.lang.String[] args)
          The class is selected from the first argument.
 boolean isEmbedded()
          Get the state of MBeanCmd.
protected  java.lang.Class<?> loadClass(java.lang.String cname)
          Load and return a class for a given class name, by using the defining class loader of the current class.
static void main(java.lang.String[] args)
          Main method.
 void setEmbedded(boolean isEmbedded)
          Set the sate of MBeanCmd
 void setFailed()
           
 void setFailed(java.lang.String error)
           
 void setRunning()
           
 void setStarted()
          Start method was called.
 void setStopped()
           
static int start(java.lang.String[] args)
          Start module when embedded in Jasmine
 void stopCommand()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cmd

protected Command cmd

logger

protected static org.ow2.util.log.Log logger
Logger.

Constructor Detail

CommandDispatcher

protected CommandDispatcher()
Dummy constructor to avoid the class from being used in any other way than calling the CommandDispatcher.main method.

Method Detail

main

public static void main(java.lang.String[] args)
Main method. Calls start(String[])(args) followed by System.exit of the returned value. IMPORTANT: This method calls System.exit !

Parameters:
args - See start(String[]).

start

public static int start(java.lang.String[] args)
Start module when embedded in Jasmine

Parameters:
args - Arguments of the command, including the command itself at the first position.
Returns:
0 if succeeded, an error code otherwise.

stopCommand

public void stopCommand()

init

public int init(java.lang.String[] args)
The class is selected from the first argument. If no class is available to process the command, it dispatches it to the built-in help class.

Parameters:
argsArguments - of the command, including the command itself at the first position.
Returns:
0 if succeeded, an error code otherwise.

getCommand

public Command getCommand(java.lang.String name)
Returns an instance of Command.

Parameters:
name - the name of the command.
Returns:
Command instance corresponding to that name.

getAvailableCommands

public java.lang.String[] getAvailableCommands()
Returns the names of the available commands in the archive.

Returns:
Names of the available commands in the archive, null if no command has been set yet.

getInputStreamReader

protected java.io.InputStreamReader getInputStreamReader(java.lang.String name)
                                                  throws java.io.IOException
Return an inputStreamReader for the specified resource, by using the context class loader.

Parameters:
name - the resource name
Returns:
an inputStreamReader for the specified resource
Throws:
java.io.IOException - if an I/O exception occurs

loadClass

protected java.lang.Class<?> loadClass(java.lang.String cname)
                                throws java.lang.ClassNotFoundException
Load and return a class for a given class name, by using the defining class loader of the current class.

Parameters:
cname - a class name
Returns:
a loaded class for a given class name
Throws:
java.lang.ClassNotFoundException - if the class cannot be found

isEmbedded

public boolean isEmbedded()
Get the state of MBeanCmd.

Returns:
True if MBeanCmd is embedded in the EventSwitch, false otherwise.

setEmbedded

public void setEmbedded(boolean isEmbedded)
Set the sate of MBeanCmd

Parameters:
isEmbedded - The state to set.

setStarted

public void setStarted()
Start method was called. The CommandDispatcher class is loaded. Ready to create and initialize the command class. If the command is sampler one (stat or poll), the status will pass either to RUNNING or FAILED


setFailed

public void setFailed()

setFailed

public void setFailed(java.lang.String error)

setRunning

public void setRunning()

setStopped

public void setStopped()


Copyright © 2011 OW2 Consortium. All Rights Reserved.