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

java.lang.Object
  extended by org.rhq.enterprise.communications.command.client.AbstractCommandClient
All Implemented Interfaces:
CommandClient
Direct Known Subclasses:
EchoCommandClient, GenericCommandClient

public abstract class AbstractCommandClient
extends Object
implements CommandClient

Provides basic functionality to all command clients.

This superclass provides the hooks by which users of the client can select the location of the remote endpoint where the command is to be invoked.

That also implicitly defines the underlying remote framework to be used when transporting the command data to and from the remote endpoint since a concrete implementation of a RemoteCommunicator defines a particular remote framework.

The users of this object may manually connect and disconnect that communicator. Typically, there will not be a need to connect since it will be done automatically when appropriate; however, it is good practice to tell this object to disconnect its communicator when this object is no longer needed to issue commands to the remote endpoint.

All subclasses should include a no-arg constructor so they can be built dynamically by the cmdline client.

Author:
John Mazzitelli

Constructor Summary
AbstractCommandClient()
          Constructor for AbstractCommandClient that initializes the client with no remote communicator defined.
AbstractCommandClient(RemoteCommunicator communicator)
          Constructor for AbstractCommandClient that allows you to specify the remote communicator to use.
 
Method Summary
 void connectRemoteCommunicator()
          Provides a mechanism by which users can notify this object that the user is about to issue commands and that a remoting communicator should be created and should connect to the remote server.
 void disconnectRemoteCommunicator()
          Provides a mechanism by which users can notify this object that the user is no longer interested in issuing commands to the remote server.
 RemoteCommunicator getRemoteCommunicator()
          Gets the object that encapsulates the underlying remote framework implementation.
 CommandResponse invoke(Command command)
          Invokes the actual command by utilizing the remoting communicator to transport the command to the server.
 CommandResponse invoke(Map<String,Object> params)
          Invokes the actual command by utilizing the remoting communicator to transport the command to the server.
 void setRemoteCommunicator(RemoteCommunicator communicator)
          Sets the object that encapsulates the underlying remote framework implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.rhq.enterprise.communications.command.client.CommandClient
createNewCommand
 

Constructor Detail

AbstractCommandClient

public AbstractCommandClient()
Constructor for AbstractCommandClient that initializes the client with no remote communicator defined. It must later be specified through setRemoteCommunicator(RemoteCommunicator) before any commands can be issued.

Note that all subclasses are strongly urged to include this no-arg constructor so it can plug into the cmdline client seamlessly.


AbstractCommandClient

public AbstractCommandClient(RemoteCommunicator communicator)
Constructor for AbstractCommandClient that allows you to specify the remote communicator to use. communicator may be null, in which case, it must later be specified through setRemoteCommunicator(RemoteCommunicator) before any commands can be issued.

Parameters:
communicator - the remote communicator to be used to send commands to a remote endpoint
Method Detail

setRemoteCommunicator

public void setRemoteCommunicator(RemoteCommunicator communicator)
Description copied from interface: CommandClient
Sets the object that encapsulates the underlying remote framework implementation. This is the object that performs the actual sending of commands and receiving of command responses over the underlying remote framework transport.

Specified by:
setRemoteCommunicator in interface CommandClient
Parameters:
communicator - the remote communicator object that is specific to a particular underlying remote framework.
See Also:
CommandClient.setRemoteCommunicator(RemoteCommunicator)

getRemoteCommunicator

public RemoteCommunicator getRemoteCommunicator()
Description copied from interface: CommandClient
Gets the object that encapsulates the underlying remote framework implementation. This is the object that performs the actual sending of commands and receiving of command responses over the underlying remote framework transport.

Specified by:
getRemoteCommunicator in interface CommandClient
Returns:
the remote communicator object that is specific to a particular underlying remote framework.
See Also:
CommandClient.getRemoteCommunicator()

connectRemoteCommunicator

public void connectRemoteCommunicator()
                               throws Exception
Description copied from interface: CommandClient
Provides a mechanism by which users can notify this object that the user is about to issue commands and that a remoting communicator should be created and should connect to the remote server.

Specified by:
connectRemoteCommunicator in interface CommandClient
Throws:
Exception - if failed to connect to the remote server for any reason
See Also:
CommandClient.connectRemoteCommunicator()

disconnectRemoteCommunicator

public void disconnectRemoteCommunicator()
Description copied from interface: CommandClient
Provides a mechanism by which users can notify this object that the user is no longer interested in issuing commands to the remote server. The effect of this is the remoting communicator will now disconnect from the remote server.

Note that the user may later on change its mind and reconnect simply by calling CommandClient.connectRemoteCommunicator(). Calling that method will reconnect the remoting communicator.

Specified by:
disconnectRemoteCommunicator in interface CommandClient
See Also:
CommandClient.disconnectRemoteCommunicator()

invoke

public CommandResponse invoke(Map<String,Object> params)
                       throws Throwable
Description copied from interface: CommandClient
Invokes the actual command by utilizing the remoting communicator to transport the command to the server. This is the method in which subclasses make the command-specific client calls necessary to invoke the command on the remote server.

This method is typically used in conjunction with CmdlineClient to invoke commands that are unknown at compile-time. In this case, params typically contain values of type String - these are text-based parameters that were entered via a script or cmdline. That text-based data will be converted to meaningful Java types in order to be able to build the proper Command objects.

Specified by:
invoke in interface CommandClient
Parameters:
params - a set of command parameters that are to be used to execute the proper command (may be null)
Returns:
the command response
Throws:
Throwable - on any error (either during the sending or execution of the command)
See Also:
CommandClient.invoke(Map)

invoke

public CommandResponse invoke(Command command)
                       throws Throwable
Description copied from interface: CommandClient
Invokes the actual command by utilizing the remoting communicator to transport the command to the server. This is the method in which subclasses make the command-specific client calls necessary to invoke the command on the remote server.

This is the prefered method for clients to call when it needs to invoke commands since each Command is strongly typed and provides compile-time error checking. However, in order to be able to invoke this method on subclasses, concrete implementations must be used and hence the actual command that is to be issued must be known at compile time. Should a dynamic runtime client be needed to invoke commands unknown at compile time (see CmdlineClient), the use of CommandClient.invoke(Map) will be required.

Specified by:
invoke in interface CommandClient
Parameters:
command - encapsulates the command that is to be executed (must not be null)
Returns:
the command response
Throws:
Throwable - on any error (either during the sending or execution of the command)
See Also:
CommandClient.invoke(Command)


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