The atg.integrations.CommandHandler
interface is a generic representation of a handler class for preprocessing and postprocessing commands. Command handlers are not a required part of the RPC API, since a Command.execute()
method can call the corresponding Command.invokeRPC()
method directly. However, command handlers add a great deal of power and flexibility to the RPC system.
To pass a Command
and its input to a CommandHandler
, the Command.execute()
method calls the CommandHandler.executeCommand()
method. The CommandHandler.executeCommand()
method must implement the following logic:
If the
CommandHandler
points to anotherCommandHandle
r (that is, if theCommandHandler.nextCommandHandler
property is not null):Perform any preprocessing.
Pass along the
Command
and its input to the nextCommandHandler
by callingCommandHandler.getNextCommandHandler().executeCommand()
.Perform any postprocessing.
If the
CommandHandler
does not point to anotherCommandHandler
:Perform any preprocessing.
Execute the
Command.invokeRPC()
method.Perform any postprocessing.
This logic allows command handlers (and the services they implement) to be chained together. The final CommandHandler
in the chain must be able to call the Command.invokeRPC()
method, to ensure that the command can be executed. However, it is not required that the command is always executed. For example, one typical use for a command handler is caching of commands and their results. Such a command handler might work like this:
Examine the command to determine if it is in the cache.
If the command is in the cache, return the cached result.
If the command is not in the cache, execute the command, return the result, and cache the command and result.