org.rhq.enterprise.communications.command.client
Class CmdlineClient

java.lang.Object
  extended by org.rhq.enterprise.communications.command.client.CmdlineClient

public class CmdlineClient
extends Object

A command line client that can be used to issue a command from a shell or script.

Note that using this type of client limits the types of data that can be sent to the server; specifically parameters to the command. Since arguments are parsed from the command line, only data that can be represented as a String can be passed to the server as command parameters.

Author:
John Mazzitelli

Constructor Summary
CmdlineClient()
           
 
Method Summary
 Command buildCommand(String[] args)
          Simply builds and returns a command defined by the given cmdline arguments.
 CommandClient buildCommandClient(String[] args)
          Simply builds and returns a command client defined by the given cmdline arguments.
 String getUsage()
          Returns the help usage string.
 CommandResponse issueCommand(CommandType commandType, String locatorURI)
          Convienence method that invokes a given command type on the remote server found at the given URI.
 CommandResponse issueCommand(CommandType commandType, String locatorURI, Map<String,String> params)
          Convienence method that invokes a given command type (with the given set of parameter values) on the remote server found at the given URI.
 CommandResponse issueCommand(String[] args)
          Issues a command defined by the given cmdline arguments.
static void main(String[] args)
          Main entry point to the command line client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmdlineClient

public CmdlineClient()
Method Detail

main

public static void main(String[] args)
Main entry point to the command line client.

Parameters:
args - specifies the command to invoke and its parameters

buildCommandClient

public CommandClient buildCommandClient(String[] args)
                                 throws IllegalArgumentException,
                                        ClassNotFoundException,
                                        InstantiationException,
                                        IllegalAccessException,
                                        MalformedURLException
Simply builds and returns a command client defined by the given cmdline arguments. It does not send the command.

Given the command type information and the optional package locations where command clients can be found, this will attempt to instantiate the specific client for the specific command. If the client cannot be found, an attempt will be made to issue the command using the generic client.

Parameters:
args - cmdline arguments
Returns:
the command client
Throws:
IllegalArgumentException - if a failure occurred while processing the cmdline arguments
ClassNotFoundException - if failed to find a valid command client class
IllegalAccessException - if failed to instantiate the command's client class
InstantiationException - if failed to instantiate the command's client class
MalformedURLException - if the given URL is invalid and cannot be used to locate an invoker

buildCommand

public Command buildCommand(String[] args)
                     throws IllegalArgumentException,
                            ClassNotFoundException,
                            InstantiationException,
                            IllegalAccessException,
                            MalformedURLException
Simply builds and returns a command defined by the given cmdline arguments. It does not send the command.

Given the command type information and the optional package locations where command clients can be found, this will attempt to instantiate the specific client for the specific command. If the client cannot be found, an attempt will be made to issue the command using the generic client.

Parameters:
args - cmdline arguments
Returns:
the command
Throws:
IllegalArgumentException - if a failure occurred while processing the cmdline arguments
ClassNotFoundException - if failed to find a valid command client class
IllegalAccessException - if failed to instantiate the command's client class
InstantiationException - if failed to instantiate the command's client class
MalformedURLException - if the given URL is invalid and cannot be used to locate an invoker

issueCommand

public CommandResponse issueCommand(String[] args)
                             throws IllegalArgumentException,
                                    ClassNotFoundException,
                                    InstantiationException,
                                    IllegalAccessException,
                                    MalformedURLException,
                                    Throwable
Issues a command defined by the given cmdline arguments.

Given the command type information and the optional package locations where command clients can be found, this will attempt to instantiate the specific client for the specific command. If the client cannot be found, an attempt will be made to issue the command using the generic client.

Parameters:
args - cmdline arguments
Returns:
the response of the command
Throws:
IllegalArgumentException - if a failure occurred while processing the cmdline arguments
ClassNotFoundException - if failed to find a valid command client class
IllegalAccessException - if failed to instantiate the command's client class
InstantiationException - if failed to instantiate the command's client class
MalformedURLException - if the given URL is invalid and cannot be used to locate an invoker
Throwable - any other error that was due to a failure during the invocation of the command

issueCommand

public CommandResponse issueCommand(CommandType commandType,
                                    String locatorURI,
                                    Map<String,String> params)
                             throws IllegalArgumentException,
                                    MalformedURLException,
                                    ClassNotFoundException,
                                    InstantiationException,
                                    IllegalAccessException,
                                    Throwable
Convienence method that invokes a given command type (with the given set of parameter values) on the remote server found at the given URI.

Note that this method may or may not be the most appropriate to use. Use this method if you do not know ahead of time the type of command you are going to issue. If you already know the type of command you are going to issue, it is best to use the command's more strongly typed client subclass method that implements CommandClient.invoke(Command).

Parameters:
commandType - the type of command to issue
locatorURI - location of the remote server
params - set of name/value parameters sent along with the command (may be null)
Returns:
the command response
Throws:
IllegalArgumentException - if a failure occurred while processing the cmdline arguments
ClassNotFoundException - if failed to find the command's client class
IllegalAccessException - if failed to instantiate the command's client class
InstantiationException - if failed to instantiate the command's client class
MalformedURLException - if the given URL is invalid and cannot be used to locate an invoker
Throwable - any other error that was due to a failure during the invocation of the command

issueCommand

public CommandResponse issueCommand(CommandType commandType,
                                    String locatorURI)
                             throws IllegalArgumentException,
                                    MalformedURLException,
                                    ClassNotFoundException,
                                    InstantiationException,
                                    IllegalAccessException,
                                    Throwable
Convienence method that invokes a given command type on the remote server found at the given URI. Note that this method is only useful if the command to be issued does not require any parameters.

Parameters:
commandType - the type of command to issue
locatorURI - location of the remote server
Returns:
the command response
Throws:
IllegalArgumentException - if a failure occurred while processing the cmdline arguments
ClassNotFoundException - if failed to find the command's client class
IllegalAccessException - if failed to instantiate the command's client class
InstantiationException - if failed to instantiate the command's client class
MalformedURLException - if the given URL is invalid and cannot be used to locate an invoker
Throwable - any other error that was due to a failure during the invocation of the command

getUsage

public String getUsage()
Returns the help usage string.

Returns:
help text


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.