Class HubPrincipalConnection

java.lang.Object
com.iizix.server.loadbalancer.HubPrincipalConnection
All Implemented Interfaces:
HubServerProp.IHubEventHandler, LoadBalancerHandler.IMemberConnection

public final class HubPrincipalConnection extends Object implements HubServerProp.IHubEventHandler, LoadBalancerHandler.IMemberConnection
One member connection on the principal, HUB-DESIGN.md sections 2.4, 3.4 and 13 (B-7b): the state machine between the WebSocket opening and admission, shared by the production end point (LoadBalancerEndPoint) and the two-ended test's end point, so that both run the same code.
  • onOpened() when the WebSocket opens: REGISTER must arrive within HubServerProp.REGISTER_DEADLINE_MILLIS, else the connection is closed.
  • bind(HubServerProp) when the member's channel has travelled: the principal's mirror gets its role and this handler, and CHALLENGE goes out with 32 fresh random bytes (ruled LV-12 (a)).
  • Before admission nothing but REGISTER is processed: any other event closes the connection (section 13). REGISTER goes to the table (LoadBalancerHandler.register(LoadBalancerHandler.IMemberConnection, byte[], PropCnr)); admitted, the reply is ok with the warnings and the member list follows; refused, the reply carries the reason and the connection is closed after a short grace, the member normally closing first.
  • After admission REPORT feeds the table; an event of a later order is answered with a refusal so that the member does not wait for its deadline.
Author:
Christopher Mindus
  • Field Details

    • REFUSED_CLOSE_MILLIS

      public static final long REFUSED_CLOSE_MILLIS
      How long a refused member is given to close before the principal closes: 2000L ms.
      See Also:
  • Constructor Details

  • Method Details

    • isAdmitted

      public boolean isAdmitted()
      Tells whether the member is admitted.
      Returns:
      true when admitted.
    • getMemberID

      public String getMemberID()
      Gets the admitted member ID.
      Returns:
      The ID, or null before admission.
    • getChallenge

      public byte[] getChallenge()
      Gets the challenge this connection was opened with, for a test.
      Returns:
      A copy, or null before bind(HubServerProp).
    • getChannel

      public HubServerProp getChannel()
      Gets the channel.
      Returns:
      The principal's mirror of the member's channel, or null before bind(HubServerProp).
    • getRemoteDescription

      public String getRemoteDescription()
      Description copied from interface: LoadBalancerHandler.IMemberConnection
      Gets who the connection is from, for the log lines.
      Specified by:
      getRemoteDescription in interface LoadBalancerHandler.IMemberConnection
      Returns:
      E.g. addr / host.
    • onOpened

      public void onOpened()
      The WebSocket opened: REGISTER must arrive within the deadline.
    • bind

      public void bind(HubServerProp channel)
      The member's channel has travelled: the challenge goes out.
      Parameters:
      channel - The principal's mirror of the member's channel.
    • onHeartBeat

      public void onHeartBeat(long millis)
      The principal's heart-beat measure of this link.
      Parameters:
      millis - The round-trip time in milliseconds.
    • dispose

      public void dispose()
      The connection is gone: the table forgets the member.
    • closeConnection

      public void closeConnection(String why)
      Description copied from interface: LoadBalancerHandler.IMemberConnection
      Closes the connection: called when it is replaced by another run of the same member.
      Specified by:
      closeConnection in interface LoadBalancerHandler.IMemberConnection
      Parameters:
      why - The reason, for the log.
    • sendMembers

      public void sendMembers(PropCnr members)
      Description copied from interface: LoadBalancerHandler.IMemberConnection
      Sends the member list to this member.
      Specified by:
      sendMembers in interface LoadBalancerHandler.IMemberConnection
      Parameters:
      members - The MEMBERS parameters.
    • onEvent

      public void onEvent(int localID, PropCnr params)
      --- The protocol ---
      Specified by:
      onEvent in interface HubServerProp.IHubEventHandler
      Parameters:
      localID - The event id.
      params - The parameters, or null for none.