Class LoadBalancerHandler
java.lang.Object
com.iizix.server.loadbalancer.LoadBalancerHandler
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:
wdiffers from the principal's:wire.- 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. memberis not in the principal's[members]:unknown-member(H-6).builddiffers from the principal's:build(R-18 (a)).- Admitting it would exceed the licence's server count:
servers(R-6), theIHubLicence'sgetMaxServers. - The same member ID is connected with another run: the new connection replaces the old, which is closed, and a WARNING names both runs.
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
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn admitted member.static final recordThe principal's own facts, read at every registration.static interfaceA member connection as the table sees it.static interfaceWhat writesHUB.MEMBERS: the module'sDBLoadBalancer, nothing in a test.static final recordThe outcome of a registration.Field Summary
FieldsConstructor Summary
ConstructorsConstructorDescriptionLoadBalancerHandler(HubDefinition definition, HubClusterKey key, IHubLicence licence, Supplier<LoadBalancerHandler.Facts> facts, LoadBalancerHandler.IMemberRecorder recorder) Creates the table.Method Summary
Modifier and TypeMethodDescriptionvoidSends the member list to every admitted member, after a change of the table.Builds theMEMBERSparameters: the containermemberswith one child per admitted member, named by its ID, carryingurl,state,rtt(the principal's measure) andrttm(the member's).Gets an admitted member.Gets the admitted members, in admission order.voidonDisposed(LoadBalancerHandler.IMemberConnection connection) A connection ended: an admitted member is gone unless replaced meanwhile.voidonHeartBeat(LoadBalancerHandler.IMemberConnection connection, long millis) The principal's heart-beat measure of a link.voidonReport(LoadBalancerHandler.IMemberConnection connection, PropCnr params) A member'sREPORT: the link RTT as the member measured it.register(LoadBalancerHandler.IMemberConnection connection, byte[] pn, PropCnr params) Admits or refuses aREGISTER, in the order of section 2.4.static longThe round-trip time between two members via the principal (ruled H-5): the two link times as the principal measured them, summed.
Field Details
STATE_ADMITTED
STATE_GONE
STATE_REFUSED
Constructor Details
LoadBalancerHandler
public LoadBalancerHandler(HubDefinition definition, HubClusterKey key, IHubLicence licence, Supplier<LoadBalancerHandler.Facts> facts, LoadBalancerHandler.IMemberRecorder recorder) Creates the table.- Parameters:
definition- The definition in force.key- The cluster key, or null when none is loaded.licence- The licence.facts- The principal's facts, read at every registration.recorder- The recorder ofHUB.MEMBERS, or null for none.
Method Details
register
public LoadBalancerHandler.Verdict register(LoadBalancerHandler.IMemberConnection connection, byte[] pn, PropCnr params) Admits or refuses aREGISTER, in the order of section 2.4.- Parameters:
connection- The connection the request came on.pn- The challenge this connection was opened with.params- TheREGISTERparameters, may be null.- Returns:
- The verdict; on admission the member is in the table.
onReport
A member'sREPORT: the link RTT as the member measured it.- Parameters:
connection- The connection.params- The parameters, may be null.
onHeartBeat
The principal's heart-beat measure of a link.- Parameters:
connection- The connection.millis- The round-trip time in milliseconds.
onDisposed
A connection ended: an admitted member is gone unless replaced meanwhile.- Parameters:
connection- The connection.
getMembers
Gets the admitted members, in admission order.- Returns:
- A snapshot, never null.
getMember
Gets an admitted member.- Parameters:
memberID- The member ID.- Returns:
- The entry, or null.
viaPrincipal
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
Builds theMEMBERSparameters: the containermemberswith one child per admitted member, named by its ID, carryingurl,state,rtt(the principal's measure) andrttm(the member's).- Returns:
- The parameters.
broadcastMembers
public void broadcastMembers()Sends the member list to every admitted member, after a change of the table.