org.rhq.enterprise.communications.command.server
Class CommandService

java.lang.Object
  extended by org.rhq.enterprise.communications.command.server.CommandMBean
      extended by org.rhq.enterprise.communications.command.server.CommandService
All Implemented Interfaces:
MBeanRegistration, CommandExecutor, CommandServiceMBean
Direct Known Subclasses:
EchoCommandService, IdentifyCommandService, MultipleCommandService, RemoteInputStreamCommandService, RemoteOutputStreamCommandService, RemotePojoInvocationCommandService

public abstract class CommandService
extends CommandMBean
implements CommandServiceMBean

The superclass for all command services. Command services are providers of command types - that is, they support the invocation of one or more commands.

Extending this class gives all command services the same interface, which is how the CommandProcessor can be extended to execute arbitrary commands.

All command services are registered with the command service directory, which allows the command processor to find this service and its supported commands easily.

Note that subclasses do not need define their own MBean interface; they need only inherit this service's MBean interface in order to plug into the command processor infrastructure.

This class is typically used to process requests of the same kind of command, or perhaps different versions of the same kind of command. To facilitate easier support for multiple commands, see MultipleCommandService. Use that class if a command service expects to process many different kinds of commands. That is not to say direct subclasses of this class cannot support multiple commands - they can. However, it typically will involve the execute method containing a series of if-then-else statements to check the instanceof value of the incoming Command object.

Author:
John Mazzitelli

Constructor Summary
CommandService()
           
 
Method Summary
protected  CommandServiceId getCommandServiceId()
          Returns the command service ID that this command service is registered under - will be null if not registered or was not registered with ServiceContainer.addCommandService(CommandService).
protected  org.jboss.remoting.transport.ConnectorMBean getConnector()
          Gets the connector providing our remote services.
 ServiceContainer getServiceContainer()
          If this service was registered by the ServiceContainer, that container's reference will be returned.
protected  String getSubsystem()
          Returns the subsystem that this command service is registered under.
protected  void prepareRemoteInputStream(RemoteInputStream remote_stream)
          This is a convienence method for use by those subclass services that need to process incoming remote input streams that were received from a client.
protected  void prepareRemoteOutputStream(RemoteOutputStream remote_stream)
          This is a convienence method for use by those subclass services that need to process incoming remote output streams that were received from a client.
 ObjectName preRegister(MBeanServer mbs, ObjectName name)
          Ensures that the name this command service is to be registered on is valid.
 void setServiceContainer(ServiceContainer container)
          When this service is added by the ServiceContainer, that container's reference will be set via this method.
 
Methods inherited from class org.rhq.enterprise.communications.command.server.CommandMBean
getLog, getMBeanServer, getObjectName, postDeregister, postRegister, preDeregister, startService, stopService
 
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.server.CommandServiceMBean
getSupportedCommandTypes
 
Methods inherited from interface org.rhq.enterprise.communications.command.CommandExecutor
execute
 

Constructor Detail

CommandService

public CommandService()
Method Detail

preRegister

public ObjectName preRegister(MBeanServer mbs,
                              ObjectName name)
                       throws Exception
Ensures that the name this command service is to be registered on is valid. See KeyProperty for more information on the valid key properties.

If the name is invalid, an exception is thrown and the service will not get registered.

Specified by:
preRegister in interface MBeanRegistration
Overrides:
preRegister in class CommandMBean
Throws:
IllegalArgumentException - if the name does not follow the required format needed to interact with the command processor
Exception
See Also:
MBeanRegistration.preRegister(MBeanServer, ObjectName)

getServiceContainer

public ServiceContainer getServiceContainer()
If this service was registered by the ServiceContainer, that container's reference will be returned. If this service object has not yet been registered or registered by some other mechanism, this will return null.

Returns:
the server-side components container that registered this service

setServiceContainer

public void setServiceContainer(ServiceContainer container)
When this service is added by the ServiceContainer, that container's reference will be set via this method. This allows this command service to obtain its container (in case this service needs things like the client configuration.

Parameters:
container -

getConnector

protected org.jboss.remoting.transport.ConnectorMBean getConnector()
                                                            throws Exception
Gets the connector providing our remote services. The returned connector is the object that is accepting from remote clients the commands that this command service processes.

Returns:
this service's associated connector
Throws:
Exception - if failed to get the connector

getSubsystem

protected String getSubsystem()
Returns the subsystem that this command service is registered under.

Returns:
the subsystem or null if not registered

getCommandServiceId

protected CommandServiceId getCommandServiceId()
Returns the command service ID that this command service is registered under - will be null if not registered or was not registered with ServiceContainer.addCommandService(CommandService).

Returns:
the command service ID or null if not registered

prepareRemoteInputStream

protected void prepareRemoteInputStream(RemoteInputStream remote_stream)
This is a convienence method for use by those subclass services that need to process incoming remote input streams that were received from a client. Remote input streams require a connection back to the client that sent the stream - this is so this service can pull down the input stream data. This method prepares the given remote input stream with a properly configured client command sender targeted to send commands back to the client that sent the remote input stream.

Parameters:
remote_stream - the stream to be prepared with a sender

prepareRemoteOutputStream

protected void prepareRemoteOutputStream(RemoteOutputStream remote_stream)
This is a convienence method for use by those subclass services that need to process incoming remote output streams that were received from a client. Remote output streams require a connection back to the client that sent the stream - this is so this service can push down the output stream data. This method prepares the given remote output stream with a properly configured client command sender targeted to send commands back to the client that sent the remote output stream.

Parameters:
remote_stream - the stream to be prepared with a sender


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