Class RouterEngine
java.lang.Object
com.tccc.kos.commons.web.websocket.router.RouterEngine
- All Implemented Interfaces:
WebsocketMsgHandler
This is the core of the websocket router.
- Version:
- Jul-18-22
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRouterEngine
(WebsocketRouter router, String zone, String routerId, boolean primary) Create a new router engine. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAlias
(WebsocketConnection conn, String alias) Add an alias to the specified connection.void
addClient
(WebsocketConnection conn) Add a client to the router.void
addRouter
(WebsocketConnection conn) Add the connection as a router.void
Handle disconnect of a routed connection.void
forwardMsg
(InboundMessage msg, String dstAddr, String trace) Forward the message using the forwarding rules.int
int
Return the current table rebuild delay.getZone()
void
onReceiveFromRemote
(WebsocketConnection conn, String txtMsg) Route the message to the correct destination.Resolve the specified address using the aliases table.void
routeMsg
(OutboundMessage msg) Attempt to route the outbound message.void
routeMsg
(WebsocketConnection conn, InboundMessage msg) Attempt to route the specified message.void
sendMsg
(WebsocketConnection conn, RoutedMessage msg) Convenience method to send a message to a connectionvoid
setRouterTTL
(int routerTTL) void
setTableRebuildDelay
(int delay) Set the table rebuild delay.
-
Field Details
-
ATTR_ALIAS
- See Also:
-
PRIMARY_ALIAS
- See Also:
-
MSG_TYPE_NAK_PREFIX
- See Also:
-
MSG_TYPE_NO_CLIENT
- See Also:
-
MSG_TYPE_NO_ROUTE
- See Also:
-
-
Constructor Details
-
RouterEngine
Create a new router engine.- Parameters:
router
- the front end of the routerzone
- the zone the router is in (null to detect from master)routerId
- the unique id of this router within the zoneprimary
- true if this is a primary (used to alias)
-
-
Method Details
-
addClient
Add a client to the router. This may end up being a router connection eventually but we'll switch it once we get a hello message if that's the case.- Parameters:
conn
- the connection to add
-
addRouter
Add the connection as a router. This is only used for outbound connections where we know the connection is router / router so we don't accidentally send router protocol messages to clients.- Parameters:
conn
- the connection to add
-
addAlias
Add an alias to the specified connection. -
disconnect
Handle disconnect of a routed connection. -
sendMsg
Convenience method to send a message to a connection -
onReceiveFromRemote
Route the message to the correct destination.- Specified by:
onReceiveFromRemote
in interfaceWebsocketMsgHandler
- Parameters:
conn
- the connection the message was received ontxtMsg
- the message- Throws:
Exception
- if there is any error
-
routeMsg
Attempt to route the outbound message. This will serialize the outbound message to an inbound message suitable for routing. If the destination is this node then we're going to serialize to json and back again which isn't very efficient so we shouldn't be routing messages that don't need to be routed.- Parameters:
msg
- the message to route
-
resolve
Resolve the specified address using the aliases table. Returns the input if no there is no alias match. This does not validate that the input is a valid address. -
routeMsg
Attempt to route the specified message. This may result in the message being processed locally or forwarded to a client or another router. The source address should be set in the message before getting here in order to receive a response (unless the message originated on this node in which case no source address is required).- Parameters:
conn
- the connection the message arrived on, may be nullmsg
- the message to route
-
forwardMsg
Forward the message using the forwarding rules. -
getTableRebuildDelay
public int getTableRebuildDelay()Return the current table rebuild delay. -
setTableRebuildDelay
public void setTableRebuildDelay(int delay) Set the table rebuild delay.- Parameters:
delay
- the new delay
-
getZone
-
getRouterId
-
getRouterAddr
-
getRouterTTL
public int getRouterTTL() -
setRouterTTL
public void setRouterTTL(int routerTTL)
-