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:REGISTERmust arrive withinHubServerProp.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, andCHALLENGEgoes out with 32 fresh random bytes (ruled LV-12 (a)).- Before admission nothing but
REGISTERis processed: any other event closes the connection (section 13).REGISTERgoes to the table (LoadBalancerHandler.register(LoadBalancerHandler.IMemberConnection, byte[], PropCnr)); admitted, the reply isokwith 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
REPORTfeeds 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
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe end point behind a connection.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longHow long a refused member is given to close before the principal closes: 2000L ms.Constructor Summary
ConstructorsConstructorDescriptionHubPrincipalConnection(LoadBalancerHandler handler, HubPrincipalConnection.IPeer peer, ITimerEngine timerEngine) Creates the connection's state.Method Summary
Modifier and TypeMethodDescriptionvoidbind(HubServerProp channel) The member's channel has travelled: the challenge goes out.voidcloseConnection(String why) Closes the connection: called when it is replaced by another run of the same member.voiddispose()The connection is gone: the table forgets the member.byte[]Gets the challenge this connection was opened with, for a test.Gets the channel.Gets the admitted member ID.Gets who the connection is from, for the log lines.booleanTells whether the member is admitted.void--- The protocol ---voidonHeartBeat(long millis) The principal's heart-beat measure of this link.voidonOpened()The WebSocket opened:REGISTERmust arrive within the deadline.voidsendMembers(PropCnr members) Sends the member list to this member.
Field Details
REFUSED_CLOSE_MILLIS
public static final long REFUSED_CLOSE_MILLISHow long a refused member is given to close before the principal closes: 2000L ms.- See Also:
Constructor Details
HubPrincipalConnection
public HubPrincipalConnection(LoadBalancerHandler handler, HubPrincipalConnection.IPeer peer, ITimerEngine timerEngine) Creates the connection's state.- Parameters:
handler- The table.peer- The end point.timerEngine- The timer engine, or null for the system's.
Method Details
isAdmitted
public boolean isAdmitted()Tells whether the member is admitted.- Returns:
- true when admitted.
getMemberID
getChallenge
public byte[] getChallenge()Gets the challenge this connection was opened with, for a test.- Returns:
- A copy, or null before
bind(HubServerProp).
getChannel
Gets the channel.- Returns:
- The principal's mirror of the member's channel, or null before
bind(HubServerProp).
getRemoteDescription
Description copied from interface:LoadBalancerHandler.IMemberConnectionGets who the connection is from, for the log lines.- Specified by:
getRemoteDescriptionin interfaceLoadBalancerHandler.IMemberConnection- Returns:
- E.g.
addr / host.
onOpened
public void onOpened()The WebSocket opened:REGISTERmust arrive within the deadline.bind
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
Description copied from interface:LoadBalancerHandler.IMemberConnectionCloses the connection: called when it is replaced by another run of the same member.- Specified by:
closeConnectionin interfaceLoadBalancerHandler.IMemberConnection- Parameters:
why- The reason, for the log.
sendMembers
Description copied from interface:LoadBalancerHandler.IMemberConnectionSends the member list to this member.- Specified by:
sendMembersin interfaceLoadBalancerHandler.IMemberConnection- Parameters:
members- TheMEMBERSparameters.
onEvent
--- The protocol ---- Specified by:
onEventin interfaceHubServerProp.IHubEventHandler- Parameters:
localID- The event id.params- The parameters, or null for none.