Class LoadBalancerHandler

java.lang.Object
com.iizix.server.loadbalancer.LoadBalancerHandler

public final class LoadBalancerHandler extends Object
The principal's member table, HUB-DESIGN.md sections 2.4, 3.5 and 4.1 (B-7b): shared by every member connection of the hub module, it admits or refuses a REGISTER in the order of section 2.4, keeps the admitted members with the round-trip time of each link as measured at both ends, and writes HUB.MEMBERS informationally (R-3) through the recorder it was given. It knows nothing of end points: a connection is an LoadBalancerHandler.IMemberConnection, so that the two-ended test drives it over a real Jetty WebSocket without a ServerShell.

Admission, in this order, the first refusal answering:

  1. w differs from the principal's: wire.
  2. The credential does not verify as the answer to this connection's challenge: auth, logged SEVERE with the member ID, never the bytes. Until B-9 the credential is the interim cluster key's HMAC (HubClusterKey, ruled H-8); a principal without a key refuses every member.
  3. member is not in the principal's [members]: unknown-member (H-6).
  4. build differs from the principal's: build (R-18 (a)).
  5. Admitting it would exceed the licence's server count: servers (R-6), the IHubLicence's getMaxServers.
  6. The same member ID is connected with another run: the new connection replaces the old, which is closed, and a WARNING names both runs.
A differing definition hash is admitted with a WARNING (H-7), and so are differing active server keys (RB-6 (a)); both are named in the reply's warnings. A member whose shared-DB identity is not the principal's is a local-DB member (section 2.3), logged at INFO.

RTT (section 3.5, ruled H-5): the principal's measure of each link comes from the end point's heart-beat, the member's from its REPORT; member to member is the two link times and their sum, "via principal" (viaPrincipal(LoadBalancerHandler.Entry, LoadBalancerHandler.Entry)), no direct probe.

Author:
Christopher Mindus
  • Field Details

  • Constructor Details

  • Method Details

    • register

      public LoadBalancerHandler.Verdict register(LoadBalancerHandler.IMemberConnection connection, byte[] pn, PropCnr params)
      Admits or refuses a REGISTER, in the order of section 2.4.
      Parameters:
      connection - The connection the request came on.
      pn - The challenge this connection was opened with.
      params - The REGISTER parameters, may be null.
      Returns:
      The verdict; on admission the member is in the table.
    • onReport

      public void onReport(LoadBalancerHandler.IMemberConnection connection, PropCnr params)
      A member's REPORT: the link RTT as the member measured it.
      Parameters:
      connection - The connection.
      params - The parameters, may be null.
    • onHeartBeat

      public void onHeartBeat(LoadBalancerHandler.IMemberConnection connection, long millis)
      The principal's heart-beat measure of a link.
      Parameters:
      connection - The connection.
      millis - The round-trip time in milliseconds.
    • onDisposed

      public void onDisposed(LoadBalancerHandler.IMemberConnection connection)
      A connection ended: an admitted member is gone unless replaced meanwhile.
      Parameters:
      connection - The connection.
    • getMembers

      public List<LoadBalancerHandler.Entry> getMembers()
      Gets the admitted members, in admission order.
      Returns:
      A snapshot, never null.
    • getMember

      public LoadBalancerHandler.Entry getMember(String memberID)
      Gets an admitted member.
      Parameters:
      memberID - The member ID.
      Returns:
      The entry, or null.
    • viaPrincipal

      public static long viaPrincipal(LoadBalancerHandler.Entry a, LoadBalancerHandler.Entry b)
      The round-trip time between two members via the principal (ruled H-5): the two link times as the principal measured them, summed.
      Parameters:
      a - One member.
      b - The other.
      Returns:
      The sum in milliseconds, or -1 when either link is not measured yet.
    • buildMembersList

      public PropCnr buildMembersList()
      Builds the MEMBERS parameters: the container members with one child per admitted member, named by its ID, carrying url, state, rtt (the principal's measure) and rttm (the member's).
      Returns:
      The parameters.
    • broadcastMembers

      public void broadcastMembers()
      Sends the member list to every admitted member, after a change of the table.