When a Command
or CommandHandler
object executes a Command
, it must return a CommandResult
. A CommandResult
is just a container that has two other objects as properties:
The
result
property is ajava.lang.Object
that is the actual object returned by the remote call.The
context
property is ajava.util.Map
that can be used to store additional parameters and their values.
Application code should access the results in the result
object by using the DynamicBeans API. For example, suppose the RPC call adds two integers and stores the result as an integer named sum
. The application code could obtain the value of sum
like this:
Integer sum = (Integer)
DynamicBeans.getPropertyValue(getCommandResult.getResults(),"sum");
The DynamicBeans API is recommended because it eliminates the need to convert the object returned from the transport RPC into a generic data format, which requires additional memory and processing time. For example, if a query returns a DOM object, the DynamicBeans API can be used to access the data directly from it, avoiding the need to copy the properties from the DOM object to another object type (such as a Map
).
RPC implementations are not required to use the context
Map
. It is included in the CommandResult
object to provide a way to store additional information that is not part of the result
object.