Class WebsocketAddr

java.lang.Object
com.tccc.kos.commons.util.net.WebsocketAddr

public class WebsocketAddr extends Object
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:clientId
 
Each 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 Details

    • WebsocketAddr

      public WebsocketAddr(String zone, String routerId, String clientId)
      Creates an address from the specified components.
      Parameters:
      zone - the zone name
      routerId - the router identifier
      clientId - the client identifier
    • WebsocketAddr

      public WebsocketAddr(String addr)
      Creates an address from the given string.
      Parameters:
      addr - the address to parse, in the form "zone:router:client"
  • Method Details

    • getZone

      public String getZone()
      Returns the name of the zone.
      Returns:
      the zone's name
    • setZone

      public void setZone(String zone)
      Sets the name of the zone.
      Parameters:
      zone - the zone's name
    • getRouterId

      public String getRouterId()
      Returns the router's identifier.
      Returns:
      the routerId
    • setRouterId

      public void setRouterId(String routerId)
      Sets the router's identifier.
      Parameters:
      routerId - the router's ID
    • getClientId

      public String getClientId()
      Returns the client's identifier.
      Returns:
      the clientId
    • setClientId

      public void setClientId(String clientId)
      Sets the client's identifier.
      Parameters:
      clientId - the client's ID
    • toString

      public String toString()
      Returns the string form of the address.
      Overrides:
      toString in class Object
    • toRouter

      public String toRouter()
      Returns the address of the router that manages the given address. The router always has a clientId of "0".
    • getZone

      public static String getZone(String addr)
      Returns the zone of an address.
      Parameters:
      addr - the address to parse
      Returns:
      the zone portion of the address
    • getClientId

      public static String getClientId(String addr)
      Returns the clientId of an address.
      Parameters:
      addr - the address to parse
      Returns:
      the clientId portion of the address
    • withoutClientId

      public static String withoutClientId(String addr)
      Removes the clientId from the specified address.
      Parameters:
      addr - the address to parse
      Returns:
      the address without clientId but with terminating colon
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object