public abstract class MultipleCommandService extends CommandService
commands.
This class provides another level of indirection to locate the executors of commands. Where CommandService is
the object that explicitly executes the requested command, this class will actually hand off the command to the
actual CommandExecutor object that will execute the command.
This is similar to what the CommandProcessor does; however, this class allows a single, deployed MBean to
handle multiple, distinctly different, command types (whereas the command processor looks for
command service MBeans which do not easily support distinctly different commands (short of
implementing a series of if-else statements to perform instanceof checks on the incoming
command). Therefore, this class allows a single, deployed MBean to handle any number of commands, allowing for a
smaller deployment configuration (rather than being forced to deploy X MBeans to handle X commands; this allows you
to deploy 1 MBean to handle X commands).
Usually, this class is helpful when a command service needs to execute distinctly different commands, but where those commands are logically related to one another.
Subclasses of this class should not override CommandServiceMBean.getSupportedCommandTypes(), instead they
must implement getSupportedCommandTypeExecutors().
Subclasses also should not override execute(Command, InputStream, OutputStream).
The executors this class uses can be instantiated on a per-request basis, or they may be reused (in which case,
the implementor of the CommandExecutor class must ensure its thread safety).
| Modifier and Type | Class and Description |
|---|---|
protected class |
MultipleCommandService.CommandTypeExecutor
An inner class used only by the
MultipleCommandService that encasulates a supported command type and the
executor that should be used to execute commands of that type. |
| Constructor and Description |
|---|
MultipleCommandService() |
| Modifier and Type | Method and Description |
|---|---|
CommandResponse |
execute(Command command,
InputStream in,
OutputStream out)
Given a command to execute, this method will lookup that command's type to determine what
executor should be used. |
protected Map<CommandType,MultipleCommandService.CommandTypeExecutor> |
getExecutors()
Gets the set of executors whose map keys are the
command types and whose map values are
MultipleCommandService.CommandTypeExecutor objects. |
protected abstract MultipleCommandService.CommandTypeExecutor[] |
getSupportedCommandTypeExecutors()
Returns a set of
MultipleCommandService.CommandTypeExecutor objects that define what command types this service supports and the
executors that will execute commands of those types. |
CommandType[] |
getSupportedCommandTypes()
Subclasses to this class do not override this method; instead, they need to implement
getSupportedCommandTypeExecutors(). |
getCommandServiceId, getConnector, getServiceContainer, getSubsystem, prepareRemoteInputStream, prepareRemoteOutputStream, preRegister, setServiceContainergetLog, getMBeanServer, getObjectName, postDeregister, postRegister, preDeregister, startService, stopServicepublic CommandResponse execute(Command command, InputStream in, OutputStream out)
executor should be used. Once the executor is determined, this method delegates to that
object to execute the command.command - the command to executein - input stream should the executor want to get streamed data from the clientout - output stream should the executor want to stream data to the clientIllegalArgumentException - if the command is of an invalid or unknown typeCommandExecutor.execute(Command, InputStream, OutputStream)public CommandType[] getSupportedCommandTypes()
getSupportedCommandTypeExecutors().CommandServiceMBean.getSupportedCommandTypes()protected Map<CommandType,MultipleCommandService.CommandTypeExecutor> getExecutors()
command types and whose map values are
MultipleCommandService.CommandTypeExecutor objects.
This is the method that actually calls the subclass' getSupportedCommandTypeExecutors() and builds
the map from that. We create a Map as opposed to just using the array to make lookups by command
type faster.
protected abstract MultipleCommandService.CommandTypeExecutor[] getSupportedCommandTypeExecutors()
MultipleCommandService.CommandTypeExecutor objects that define what command types this service supports and the
executors that will execute commands of those types.
The returned array should be fixed during the lifetime of this service (or at least during its registration in
an MBeanServer). Changes to the supported command types during runtime will not be detected once the
CommandServiceDirectory has discovered this service. As a corollary to this rule, this method must be
ready to provide the array of support command types at the time it is registered on an MBeanServer (in other
words, this method will be called, specifically by the directory, as soon as this
service is registered).
Unlike direct subclasses to CommandService, subclasses of this class do not need to override
CommandServiceMBean.getSupportedCommandTypes(); instead, they override this method to inform the
framework not only what command types the subclass supports but also what executors should handle the execution
of commands.
Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.