Class SessionTransMgr
- All Implemented Interfaces:
GCloseCodes, GManagementConstants, ITransactionCreator, ISessionStatistics, ISessionTransMgr, TransactionCommListener, GConstants
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHow far behind the expected serial a received serial may be to count as a transaction already received, 0x7FFF: half of the serial cycle 0x0001-0xFFFF.static final intThe heartbeats in a row that may go without any inbound frame before the link is cut, 3.Fields inherited from interface GCloseCodes
CC_APPMSG, CC_DISPOSED, CC_HISTORY_ERROR, CC_OCCUPIED, CC_PAUSE, CC_SERVER_RESTART, CC_USERINFOFields inherited from interface GConstants
TRANS_ATOM, TRANS_BINARY_DATA, TRANS_BUSY, TRANS_CLIENT_LOCK, TRANS_CREATE, TRANS_DISPLAYTERMINAL, TRANS_DOWNLOAD_RESOURCES, TRANS_HOSTPRINT, TRANS_INIT, TRANS_INSTALL_RESOURCE, TRANS_LOG, TRANS_MANAGEMENT, TRANS_MESSAGE, TRANS_RELOAD, TRANS_REMOTE_CALL, TRANS_REMOTE_EVENT, TRANS_REMOTE_REPLY, TRANS_REMOVETERMINAL, TRANS_TERMINALUPDATE, TRANS_UPDATEFields inherited from interface GManagementConstants
MT_CONNECTION, MT_DISPOSE_WHEN_CLOSED, MT_NEXT_SERIAL, MT_PING, MT_PONG, MT_RECONNECTION, MT_RESEND_TRANSConstructor Summary
ConstructorsConstructorDescriptionSessionTransMgr(ITransactionProcessor processor) Creates a new session for a new transaction processor.Method Summary
Modifier and TypeMethodDescriptionvoidAssigns the created transaction communications instance.voidcloseClient(int closeCode, String msg) Closes the client with a close code and a message, then disposes of the session: the reason the client reads is"iz!" + closeCode + "!" + msg, at most 123 bytes of UTF-8 in all (the WebSocket limit), which the caller keeps (CC-SERVER-RESTART-UPDATE-V5).voidcloseClient(String msg) Sends a close management transaction with an message in HTML format for the close reason.voidSends a close management transaction indicating the User Name or Password were incorrect.static SessionTransMgrcreateReconnectionInstance(SocketAddress address, String reconnectID, int nextSerialReconnect) Creates a reconnection session instance for an existing transaction processor and attempts reconnection.Creates a transaction for processing normal transactions.voiddispose(boolean doAbort) Dispose of this session by delegating it to the Session ID.voiddoDispose(boolean doAbort) Called when the session ID has been disposed of by a call to its dispose method.booleandoPause()Requests a pause of the session from the server.Gets the current state.Gets the transaction processor for unpackaged transactions.static ITransactionProcessorgetReconnectionProcessor(String reconnectID) Gets the transaction processor of the session a reconnection names (CC-FIX-APP-DEFINITIONS, D-11): the client end point constructor asks it for the application of that session before it accepts the upgrade on a port configuration, so that a reconnection is gated as a new connection is.Gets the session.Gets the session identifier.Gets the statistics instance of the session.Gets the statistics as a snapshot.booleanChecks if current session is connected.booleanChecks if current session is connected.booleanisPaused()Checks if current session is connected.static booleanisReconnectionInstance(String reconnectID, String from) Checks if it's a valid reconnection session instance for an existing transaction processor and attempts reconnection.voidonCommClosed(TransactionComm comm, int code, String reason) Called when the communication link is closed.voidonCommClosing(TransactionComm comm) Called when the communication link is closing.voidCalled when the communication link is connected.voidonCommData(TransactionComm comm, ReadTransaction trans, int size) Called when the communication link has received data.voidonCommError(TransactionComm comm, Throwable e) Called when the communication link is closed.voidonCommHeartBeat(TransactionComm comm, long duration) Called when a heart-beat frame is received.voidonCommTimeout(TransactionComm comm, boolean isReadTimeout) Called when the communication link has timed out on a read or write operation.voidRequests a ping-pong transaction.booleansendTransaction(SendTransaction trans) Send a transaction to the client, assigning the transaction serial and processing statistics.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ISessionStatistics
getLastConnectionTime, getProperties, getProperty, setProperty
Field Details
MAX_UNANSWERED_HEARTBEATS
public static final int MAX_UNANSWERED_HEARTBEATSThe heartbeats in a row that may go without any inbound frame before the link is cut, 3.A peer that no longer answers is not noticed while the server's PINGs are written: behind a reverse proxy the TCP peer is the proxy, which acknowledges everything, and a suspended phone's kernel may acknowledge too, so TCP reports nothing and the session looks connected for as long as the dormant time-out. Any inbound frame - a PONG, a data frame - proves the peer reads and resets the count (
onCommHeartBeat(TransactionComm, long),onCommData(TransactionComm, ReadTransaction, int)); when this many heartbeats in a row got none,doTimeoutCheck(long, long, long, long)closes the link hard from the server, with no close handshake (InternalWebSocket.close(true): Jetty'sSession.disconnect), and the session takes the broken -> dormant path of a communication error, so a client that comes back reconnects as after any drop, within the dormant time-out. The cut comes between three and four heartbeat intervals after the last inbound frame: 90-120 s at a 30 s heartbeat, 135-180 s at the 45 s default. The link's idle time-out (SessionMgr.getLinkIdleTimeout) does not fire first: the PINGs the server writes reset it, and only inbound silence is counted here. A frozen desktop tab keeps answering PINGs from the Browser's network service and is not cut. No server setting: a constant (CC-FIX-WS-HEARTBEAT-SKIP, Set C).- See Also:
MAX_DUPLICATE_DISTANCE
public static final int MAX_DUPLICATE_DISTANCEHow far behind the expected serial a received serial may be to count as a transaction already received, 0x7FFF: half of the serial cycle 0x0001-0xFFFF. A serial at most this far behind is a duplicate - the client re-sent it after a reconnection because theMT_NEXT_SERIALthat acknowledged it was lost with the link - and is dropped; one further away is ahead of the expected serial, a gap (processIncoming(ReadTransaction)).- See Also:
Constructor Details
SessionTransMgr
Creates a new session for a new transaction processor.- Parameters:
processor- The transaction processor.
Method Details
isReconnectionInstance
getReconnectionProcessor
Gets the transaction processor of the session a reconnection names (CC-FIX-APP-DEFINITIONS, D-11): the client end point constructor asks it for the application of that session before it accepts the upgrade on a port configuration, so that a reconnection is gated as a new connection is.- Parameters:
reconnectID- The reconnection ID of the query.- Returns:
- The processor, or null when the session has been disposed of or has none.
createReconnectionInstance
public static SessionTransMgr createReconnectionInstance(SocketAddress address, String reconnectID, int nextSerialReconnect) Creates a reconnection session instance for an existing transaction processor and attempts reconnection.- Returns:
- The instance of the Session Manager, null if the reconnection instance is not available.
assignTransactionComm
Assigns the created transaction communications instance.getProcessor
Gets the transaction processor for unpackaged transactions.getSessionStatistics
Gets the statistics instance of the session.- Specified by:
getSessionStatisticsin interfaceISessionStatistics- Returns:
- The SessionStatistics instance.
dispose
public void dispose(boolean doAbort) Dispose of this session by delegating it to the Session ID.- Parameters:
doAbort- Abort-flag, if true pending transaction are not sent.
getStatisticsSnapshot
Gets the statistics as a snapshot.getSession
getSessionID
Gets the session identifier.- Returns:
- The session identifier, or null if disposed of.
doDispose
public void doDispose(boolean doAbort) Called when the session ID has been disposed of by a call to its dispose method.- Specified by:
doDisposein interfaceISessionTransMgr- Parameters:
doAbort- Abort-flag, if true pending transaction are not sent.
getCurrentState
Gets the current state.isConnected
public boolean isConnected()Checks if current session is connected. Be careful, do not forget that a connection can becomeisConnected()==falsewhen paused!isDisconnected
public boolean isDisconnected()Checks if current session is connected. Be careful, do not forget that a connection can becomeisConnected()==falsewhen paused!isPaused
public boolean isPaused()Checks if current session is connected. Be careful, do not forget that a connection can becomeisConnected()==falsewhen paused!doPause
public boolean doPause()Requests a pause of the session from the server.- Returns:
- true if the session still had open communication connection, false otherwise. When false is returned, the session has NOT entered real pause state.
createTransaction
Creates a transaction for processing normal transactions.- Specified by:
createTransactionin interfaceITransactionCreator- Returns:
- The new
Transactioninstance.
onCommConnected
Called when the communication link is connected.- Specified by:
onCommConnectedin interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.
onCommData
Called when the communication link has received data.- Specified by:
onCommDatain interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.trans- The transaction received.size- The size of the data received, as it may have been uncompressed.
onCommHeartBeat
Called when a heart-beat frame is received.- Specified by:
onCommHeartBeatin interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.duration- Duration of the PING-PONG message exchange in milliseconds, recorded as the connection'slastHeartBeatDuration.
onCommTimeout
Called when the communication link has timed out on a read or write operation.- Specified by:
onCommTimeoutin interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.isReadTimeout- Flag indicating read timeout when true, false indicates write timeout.
onCommError
Called when the communication link is closed.- Specified by:
onCommErrorin interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.e- The exception.
onCommClosing
Called when the communication link is closing.- Specified by:
onCommClosingin interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.
onCommClosed
Called when the communication link is closed.- Specified by:
onCommClosedin interfaceTransactionCommListener- Parameters:
comm- The transaction communication instance.
requestPingPong
public void requestPingPong()Requests a ping-pong transaction.sendTransaction
Send a transaction to the client, assigning the transaction serial and processing statistics.- Parameters:
trans- The transaction to send.- Returns:
- true for success, false for failure.
closeClientAuthenticationInfo
Sends a close management transaction indicating the User Name or Password were incorrect.- Parameters:
info- The information string.
closeClient
Sends a close management transaction with an message in HTML format for the close reason.- Parameters:
msg- The close reason in HTML format.
closeClient
Closes the client with a close code and a message, then disposes of the session: the reason the client reads is"iz!" + closeCode + "!" + msg, at most 123 bytes of UTF-8 in all (the WebSocket limit), which the caller keeps (CC-SERVER-RESTART-UPDATE-V5).- Parameters:
closeCode- The close code:GCloseCodes.CC_APPMSG,GCloseCodes.CC_SERVER_RESTART, ...msg- The message.