Class HubMemberClient

java.lang.Object
com.iizix.server.hub.HubMemberClient

public final class HubMemberClient extends Object
The member client of HUB-DESIGN.md sections 2 and 3 (B-7b): every member of a hub opens one WebSocket to the principal's /iizi/lb.ws on the property framework and is admitted or refused. Modelled on the License System's LicenseComm: a connection thread, a JettyClientWebSocketInstance per attempt, and in onCommConnected a $device container holding one child, the HubServerProp channel, added to the root. Started by ServerShell.onWorkerStarted when a definition names this server; a standalone server has none.

Whom it connects to: the eligible members of the definition in [members] order, itself excluded, one at a time; after every one failed it waits 10000L ms and starts over, the back-off of LicenseComm.connectionLoop. B-7c adds the redirection by NOT_PRINCIPAL; until then the first eligible member that admits it is the principal (ruled H-4's static principal).

TLS (section 2.2): a member URL with https connects with wss and Jetty's default trust; a production server REFUSES a plain http URL (SEVERE, the member is skipped); a development server may use it, as the PN HTTP API allows plain HTTP in development.

Registration (section 2.4): after the channel travelled, the member waits for the principal's CHALLENGE and answers with REGISTER, its first and only event before the reply: the wire version, its member ID, its run UUID (generated once per process, so that a restart can be told from a reconnect), its build, the hash of its definition file, its shared-DB identity, its public URL, the applications it serves, the credential - the cluster key's HMAC over the challenge (H-8) - and the fingerprints of its server keys (RB-6 (a): the active one is compared, the staged ones reported). Admitted, it sends its first REPORT with the link RTT it has measured and one after every later heart-beat; refused, it logs SEVERE with the reason - build means it runs standalone until both run the same build - closes, and retries with the back-off.

RTT (section 3.5): this end's measure comes from the Jetty client's PING-PONG, onCommHeartBeat, in milliseconds since B-7b settled which PONG path Jetty calls (F-1).

The connection's thread calls the listener; nothing here posts.

Author:
Christopher Mindus
  • Field Details

    • WAIT_BETWEEN_ROUNDS_MILLIS

      public static final long WAIT_BETWEEN_ROUNDS_MILLIS
      The wait after every eligible member failed, before the next round: 10000L ms (LicenseComm.WAIT_BETWEEN_SERVER_LOOPS).
      See Also:
    • THREAD_NAME

      public static final String THREAD_NAME
      The name of the connection thread: "iizi-hub-member".
      See Also:
  • Constructor Details

    • HubMemberClient

      public HubMemberClient(HubDefinition definition, PropFactory factory, HubClusterKey key, HubMemberClient.IFacts facts, boolean development, HubMemberClient.IListener listener)
      Creates the client, not yet started.
      Parameters:
      definition - The definition in force, naming this server.
      factory - The server's property factory.
      key - The cluster key, or null when none could be loaded (logged by the caller).
      facts - What to report at registration.
      development - true for a development server: plain http member URLs allowed.
      listener - The listener, or null for none.
      Throws:
      IllegalArgumentException - If the definition is standalone.
  • Method Details

    • getState

      public HubMemberClient.State getState()
      Gets the state.
      Returns:
      The state.
    • getReason

      public String getReason()
      Gets the reason of the last refusal.
      Returns:
      The reason, or null.
    • getRun

      public String getRun()
      Gets this process's run UUID.
      Returns:
      The run.
    • getMemberID

      public String getMemberID()
      Gets the member ID this client registers as.
      Returns:
      The ID.
    • getPrincipal

      public HubDefinitionFile.Member getPrincipal()
      Gets the member this client is connected or connecting to.
      Returns:
      The member, or null between attempts.
    • getLastRTT

      public long getLastRTT()
      Gets the last round-trip time this end measured.
      Returns:
      The time in milliseconds, or -1 for none yet.
    • getMembers

      public PropCnr getMembers()
      Gets the last member list the principal sent.
      Returns:
      The members container, or null for none yet.
    • isAdmitted

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

      public void start()
      Starts the connection thread.
      Throws:
      IllegalStateException - If started or closed.
    • close

      public void close()
      Closes the client: the connection is closed, the thread ends.
    • hasOtherEligibleMember

      public static boolean hasOtherEligibleMember(HubDefinition definition)
      Tells whether a definition names an eligible member other than this server: someone to connect to. The hub's only eligible member is the principal and runs no client (ruled H-4).
      Parameters:
      definition - The definition in force.
      Returns:
      true when another eligible member is named.
    • factsOf

      public static HubMemberClient.IFacts factsOf(ServerShell server, String hubName)
      Builds the facts of a running server.
      Parameters:
      server - The server.
      hubName - The hub's name, for the shared-DB identity.
      Returns:
      The facts, read live at every registration.