Class HubMemberClient
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
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhat the member reports at registration, read when theCHALLENGEarrives.static interfaceThe listener of the client's progress, for the server's log and for tests: called on the connection's thread.static enumThe state of the client.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the connection thread: "iizi-hub-member".static final longThe wait after every eligible member failed, before the next round: 10000L ms (LicenseComm.WAIT_BETWEEN_SERVER_LOOPS).Constructor Summary
ConstructorsConstructorDescriptionHubMemberClient(HubDefinition definition, PropFactory factory, HubClusterKey key, HubMemberClient.IFacts facts, boolean development, HubMemberClient.IListener listener) Creates the client, not yet started.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the client: the connection is closed, the thread ends.static HubMemberClient.IFactsfactsOf(ServerShell server, String hubName) Builds the facts of a running server.longGets the last round-trip time this end measured.Gets the member ID this client registers as.Gets the last member list the principal sent.Gets the member this client is connected or connecting to.Gets the reason of the last refusal.getRun()Gets this process's run UUID.getState()Gets the state.static booleanhasOtherEligibleMember(HubDefinition definition) Tells whether a definition names an eligible member other than this server: someone to connect to.booleanTells whether the client is admitted.voidstart()Starts the connection thread.
Field Details
WAIT_BETWEEN_ROUNDS_MILLIS
public static final long WAIT_BETWEEN_ROUNDS_MILLISThe wait after every eligible member failed, before the next round: 10000L ms (LicenseComm.WAIT_BETWEEN_SERVER_LOOPS).- See Also:
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: plainhttpmember URLs allowed.listener- The listener, or null for none.- Throws:
IllegalArgumentException- If the definition is standalone.
Method Details
getState
getReason
getRun
getMemberID
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
Gets the last member list the principal sent.- Returns:
- The
memberscontainer, 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
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
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.