Grid Ops Java - NodeContainer
Jakob Jenkov |
The NodeContainer
class in Grid Ops functions can route incoming messages to the components
that are to process them. The NodeContainer
will look at the node id in the incoming message and forward the message
to the corresponding NodeReactor
. The NodeReactor
will look at the
semantic protocol id + version and forward the message to the corresponding protocol reactor. The
protocol reactor will look at the message type of the incoming message and forward the message to the
corresponding message reactor.
The message routing is illustrated here:

Messages are received from the outside, typically via a TcpServer
and a TcpSocketsPort
,
and then given to the NodeContainer
, which internally routes the messages to the correct
MessageReactor
(via the NodeReactor
and ProtocolReactor
instances).
Required IAP Message Fields
For this routing to work, each incoming message must contain at least the following fields:
- Receiving Node Id
- Semantic Protocol Id
- Semantic Protocol Version
- Message Type
These four fields are some of the core fields of IAP messages which IAP messages of all semantic protocols should contain.
Creating a NodeContainer
To use a NodeContainer
you must first create and configure it. Here is an example that creates
and configures a NodeContainer
:
byte[] messageType = new byte[]{11}; MessageReactor messageReactor = new MessageReactor(messageType) { @Override public void react(IonReader ionReader, IapMessage iapMessage) { System.out.println("Reacting to message"); } }; byte[] protocolId = new byte[]{99}; ProtocolReactor protocolReactor = new ProtocolReactor(protocolId, messageReactor); byte[] nodeId = new byte[]{123}; NodeReactor nodeReactor = GridOps.nodeReactor(nodeId, protocolReactor); NodeContainer nodeContainer = GridOps.nodeContainer();
Notice how the examples creates an instance of a MessageReactor
, ProtocolReactor
,
NodeReactor
and NodeContainer
. The NodeContainer
is now ready
to receive incoming messages.
Tweet | |
Jakob Jenkov |