io.vlingo.xoom.lattice.router
:CommandRouter
LoadBalancingCommandRouter
PartitioningCommandRouter
RoundRobinCommandRouter
CommandRouter
types must implement this protocol: void route(final RoutableCommand command)
CommandDispatcher<P, C extends Command, A>
CommandRouter
must implement the CommandDispatcher
interface. The P
is the type name of the protocol to which the command will be sent. The C
is the type name of this command type, which must be a subclass of io.vlingo.xoom.lattice.model.Command
. The A
is the answer type to be provided by the command, and is normally a Completes<T>
where T
is the type to be answered asynchronously.RoutableCommand
CommandRouter
. This is a standard container for a concrete command type. In other words, create a command type, such as Rename
, that implements the protocol CommandDispatcher
and instantiate a new RoutableCommand
with the Rename
command inside. The RoutableCommand
is sent through the CommandRouter
and the Rename
command internally knows how to send a message to its P
generic protocol type parameter.SchemaCommands
. Inside SchemaCommands
where are a number of concrete command types. The SchemaCommands
is a factory that instantiates all the concrete command types as needed. See the main source for full details, such as all necessary imports, etc.SchemaCommands
parent is instantiated with the Stage
and the number of routees
to be create for the router. The constructor creates a new CommandRouter
that is the type used for LoadBalancing
.SchemaCommands
instance exists, it can be used to instantiate individual command instances. The first factory used is categorizeAs()
that instantiates a CategorizeAs
that is wrapped in a RoutableCommand
.RoutableCommand
generic type parameters are as follows:P
protocol is the Schema
domain model interface.C
command type is Command
subclass CategorizeAs
.SchemaState
, which is the type used to hold and transfer the Schema
type's immutable state data.SchemaCommands
does not provide a factory method for the initial Schema
type instance. That's because we use a factory method on the protocol type interface itself that's used to instantiate the initial Schema
domain model object. The protocol commands other than the factory methods are provided.SchemaId
and Category
. First the CategorizeAs
concrete command type itself is instantiated with the two parameters. Next the instance of CategorizeAs
is wrapped by a new RoutableCommand
, and it is then routed. Finally the RoutableCommand
is answered from the factory.RoutableCommand
answer is used to receive the SchemaState
instance when it arrives by way of the Completes<SchemaState>
. The REST resource handler type SchemaResource
initially received an HTTP PATCH
request and used the SchemaCommands
factory method categorizeAs()
in order to create the RoutableCommand
. Once the RoutableCommand
is returned to the SchemaResource
request handler, the request handler registers a function on the Completes<SchemaState>
that will deliver the eventual outcome when it arrives.CategorizeAs
command type itself plays and important role beyond carrying a parameter payload. When the router is ready to delivery the command, it uses the command itself to perform the dispatching.CategorizeAs
command to its destination, the router uses the accept()
on the CategorizeAs
concrete CommandDispatcher
, a Java functional interface, to do so. The accept()
method sends the categorizeAs()
message and parameters to the SchemaEntity
actor through its registered protocol.