Package com.tccc.kos.commons.util.net
Class WebsocketAddr
java.lang.Object
com.tccc.kos.commons.util.net.WebsocketAddr
Data class encapsulating the pieces that make up a kOS websocket network address.
These kOS addresses are used within the routed websocket mesh network, and have
the following structure:
zone:routerId:clientIdEach of the three pieces are:
- zone -- identifies a cluster of nodes, where all routers in the same zone know about each other, can route between them, and can typically recover if there's a failure.
- routerId -- is a unique (within its zone) identifier for a router. Exactly one router runs on every node.
- clientId -- is any non-router piece of software that makes a websocket connection to a kOS router. This is typically a browser, but can be anything that can open a websocket. The clientId for the router itself is always zero.
Data Fields
private String zone; // zone of the address
private String routerId; // router within the zone
private String clientId; // client attached to the router (or 0 for the router itself)
Examples
Constructors
// Both of these constructor calls create the same network address:
new WebsocketAddr("Zone1", "Router7", "Client12");
new WebsocketAddr("Zone1:Router7:Client12");
- Since:
- 1.0
- Version:
- 2022-09-14
-
Constructor Summary
ConstructorsConstructorDescriptionWebsocketAddr
(String addr) Creates an address from the given string.WebsocketAddr
(String zone, String routerId, String clientId) Creates an address from the specified components. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the client's identifier.static String
getClientId
(String addr) Returns theclientId
of an address.Returns the router's identifier.getZone()
Returns the name of the zone.static String
Returns thezone
of an address.int
hashCode()
void
setClientId
(String clientId) Sets the client's identifier.void
setRouterId
(String routerId) Sets the router's identifier.void
Sets the name of the zone.toRouter()
Returns the address of the router that manages the given address.toString()
Returns the string form of the address.static String
withoutClientId
(String addr) Removes theclientId
from the specified address.
-
Constructor Details
-
WebsocketAddr
Creates an address from the specified components.- Parameters:
zone
- the zone namerouterId
- the router identifierclientId
- the client identifier
-
WebsocketAddr
Creates an address from the given string.- Parameters:
addr
- the address to parse, in the form "zone:router:client"
-
-
Method Details
-
getZone
Returns the name of the zone.- Returns:
- the zone's name
-
setZone
Sets the name of the zone.- Parameters:
zone
- the zone's name
-
getRouterId
Returns the router's identifier.- Returns:
- the routerId
-
setRouterId
Sets the router's identifier.- Parameters:
routerId
- the router's ID
-
getClientId
Returns the client's identifier.- Returns:
- the
clientId
-
setClientId
Sets the client's identifier.- Parameters:
clientId
- the client's ID
-
toString
Returns the string form of the address. -
toRouter
Returns the address of the router that manages the given address. The router always has a clientId of "0". -
getZone
Returns thezone
of an address.- Parameters:
addr
- the address to parse- Returns:
- the zone portion of the address
-
getClientId
Returns theclientId
of an address.- Parameters:
addr
- the address to parse- Returns:
- the clientId portion of the address
-
withoutClientId
Removes theclientId
from the specified address.- Parameters:
addr
- the address to parse- Returns:
- the address without clientId but with terminating colon
-
equals
-
hashCode
public int hashCode()
-