final class Router extends java.lang.Object implements MessageTypes
INIT_*
and ADDRESS_REQUEST
messages. These
messages are used for dynamic address assignment by leaf nodes and
for routing information lookup respectively.
Firewall capability is partially implemented. Hooks are available to filter inbound, outbound, and forwarded messages. At the time of writing, no filtering is active, so all messages are allowed to pass through these hooks.
Modifier and Type | Class and Description |
---|---|
private class |
Router.RouterStub
Implements a router thread which processes messages in the routing
queue.
|
Modifier and Type | Field and Description |
---|---|
private int |
boundary
The maximum valid address which could belong to this routing node.
|
private int |
lastAddress
Last allocated address.
|
private java.util.HashMap<java.lang.Integer,Queue> |
leafTable
Local nodes registry.
|
private static java.util.logging.Logger |
LOG
Logger.
|
private int |
nodeAddress
Local node address.
|
private static Router |
router
Singleton instance of this class.
|
private static java.lang.ThreadGroup |
routeThreads
thread group for the router threads
|
private static ThreadSafeQueue<InboundRequest> |
routingQueue
Routing message queue (shared instance).
|
private java.util.HashMap<java.lang.Integer,Queue> |
routingTable
Routing table.
|
private java.lang.Thread[] |
threads
Message processing thread pool.
|
ADDRESS_REPLY, ADDRESS_REQUEST, BEGIN_REPLY, ECHO, ECHO_REPLY, END_REPLY, INIT_CONVERSATION, INIT_REPLY, INIT_ROUTER, INIT_STANDARD, REPLY_ASYNC, REPLY_EXCEPTION_ASYNC, REPLY_EXCEPTION_SYNC, REPLY_SYNC, REQUEST_ASYNCH, REQUEST_SYNCH, UNKNOWN
Modifier | Constructor and Description |
---|---|
private |
Router(int address,
int num)
Constructs an instance of node address using specified node address and
specified number of threads in the thread pool.
|
Modifier and Type | Method and Description |
---|---|
private void |
addRoutingNode(Queue queue,
int addr)
Add the specified queue into the routing table and this router into
into the list of the queue's notifiables.
|
private void |
allocateAddress(Queue queue,
int addr)
Assign an address to the node and put the node into the local node
registry.
|
private void |
cleanUpQueue(Queue queue)
This method is called when a queue has been disabled, but before it has
been stopped.
|
(package private) static boolean |
filterForwarded(Message message)
Filter a forwarded message according to installed firewall rules (if
any) for forwarded messages.
|
(package private) static boolean |
filterInbound(Message message)
Filter an inbound message according to installed firewall rules (if any)
for inbound messages.
|
(package private) static boolean |
filterOutbound(Message message)
Filter an outbound message according to installed firewall rules (if
any) for outbound messages.
|
(package private) static void |
forward(InboundRequest request)
Forward an inbound request which is not destined for this network node.
|
private void |
generateAddress(Queue queue)
Generate the next available address, assign it to the node and put the
node into the local node registry.
|
(package private) static void |
initRouter(int address,
int num)
Return the singleton instance of this class if it is already running
or create a new instance if not.
|
(package private) static void |
queueStopping(Queue queue)
This method is called when a queue has been disabled, but before it has
been stopped.
|
private void |
route()
Main message processing procedure.
|
(package private) static void |
terminateQueue()
Terminate static queue.
|
private static final java.util.logging.Logger LOG
private static java.lang.ThreadGroup routeThreads
private static final ThreadSafeQueue<InboundRequest> routingQueue
private static Router router
private int boundary
private int lastAddress
private int nodeAddress
private java.util.HashMap<java.lang.Integer,Queue> routingTable
private java.util.HashMap<java.lang.Integer,Queue> leafTable
private java.lang.Thread[] threads
private Router(int address, int num)
address
- The local node's address address.num
- Number of threads in the thread pool.static void initRouter(int address, int num)
address
- The local node's address address.num
- Number of threads in the thread pool.static void forward(InboundRequest request) throws java.lang.InterruptedException
request
- Request to be forwarded.java.lang.InterruptedException
- when the queue is terminated.static void terminateQueue()
static void queueStopping(Queue queue)
queue
- The queue that is stopping.static boolean filterInbound(Message message)
The current implementation is a stub only, always returning
true
.
message
- Message to be tested.true
if the message should be processed,
false
if it should be dropped.static boolean filterOutbound(Message message)
The current implementation is a stub only, always returning
true
.
message
- Message to be tested.true
if the message should be processed,
false
if it should be dropped.static boolean filterForwarded(Message message)
The current implementation is a stub only, always returning
true
.
message
- Message to be tested.true
if the message should be processed,
false
if it should be dropped.private void route()
private void addRoutingNode(Queue queue, int addr)
queue
- A Queue
instance to add into routing table.addr
- The address to associate with the remote side of the queue.private void allocateAddress(Queue queue, int addr)
queue
- A Queue
instance to which address will be
assigned.addr
- The address to associate with the remote side of the queue.private void generateAddress(Queue queue)
queue
- A Queue
instance to which address will be
assigned.private void cleanUpQueue(Queue queue)
queue
- The queue that is stopping.