Class FixSession
- All Implemented Interfaces:
AutoCloseable
Gap recovery: inbound gaps trigger a ResendRequest(2) and out-of-order messages are dropped until redelivered; inbound ResendRequests are serviced from an in-session message store — application messages are replayed with PossDupFlag(43)/OrigSendingTime(122) and admin runs are coalesced into SequenceReset-GapFill(4). Duplicates (PossDup below the expected seqnum) are suppressed; a too-low seqnum without PossDup disconnects the session.
Persistence: sessions default to an in-memory FixSessionStore
(sequence numbers reset per connection); pass a FileSessionStore to
the initiate/accept overloads for sequence-number
continuation across restarts, with ResendRequests serviced from messages
sent before the reconnect.
ResetSeqNumFlag(141): FixSession.Config.withResetOnLogon() makes the
initiator send 141=Y and restart both counters at 1; receiving a Logon
with 141=Y (and 34=1, per spec) resets the inbound expectation to 1 and —
on the side that did not initiate the reset — the outbound counter too,
persisted, with the acceptor confirming 141=Y back. This is the standard
escape hatch when the two sides' stores have diverged: without it a fresh
peer's seq 1 reads as "too low" against a durable store and the session
dies on sight. One stated caveat: the message store is not wiped on reset,
so until an old sequence number is naturally overwritten, a post-reset
ResendRequest could replay a pre-reset message stored under it — reset
into a fresh store when replay purity matters.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic interfaceSession callbacks; invoked on the session's reader thread. -
Method Summary
Modifier and TypeMethodDescriptionstatic FixSessionaccept(ServerSocket server, FixSession.Config config, FixSession.Listener listener) Accepts one connection, awaits the peer's Logon, replies, and returns established.static FixSessionaccept(ServerSocket server, FixSession.Config config, FixSession.Listener listener, FixSessionStore store) Asaccept(ServerSocket, Config, Listener)with a durable session store.voidclose()longNext incoming sequence number this session expects (for diagnostics/tests).static FixSessioninitiate(String host, int port, FixSession.Config config, FixSession.Listener listener) Connects, sends Logon, and blocks until the handshake completes.static FixSessioninitiate(String host, int port, FixSession.Config config, FixSession.Listener listener, FixSessionStore store) Asinitiate(String, int, Config, Listener)with a durable session store.booleanvoidlogout()Initiates the Logout handshake and closes the session.voidsendExecutionReport(ExecutionReport report) Venue side: sends an execution report for a received order.sendNewOrderSingle(String clOrdId, String symbol, Side side, long quantity, double limitPrice, char timeInForce) Sends a NewOrderSingle.sendOrderCancelReplace(String clOrdId, String origClOrdId, String symbol, Side side, long quantity, double limitPrice, char timeInForce) Sends an OrderCancelReplaceRequest (35=G);limitPrice = NaN= market.sendOrderCancelRequest(String clOrdId, String origClOrdId, String symbol, Side side, long quantity) Sends an OrderCancelRequest (35=F) for a working order.voidsendReject(long refSeqNum, String text) Sends a session-level Reject (35=3) referring to an inbound message.
-
Method Details
-
initiate
public static FixSession initiate(String host, int port, FixSession.Config config, FixSession.Listener listener) throws IOException Connects, sends Logon, and blocks until the handshake completes.- Throws:
IOException
-
initiate
public static FixSession initiate(String host, int port, FixSession.Config config, FixSession.Listener listener, FixSessionStore store) throws IOException Asinitiate(String, int, Config, Listener)with a durable session store.- Throws:
IOException
-
accept
public static FixSession accept(ServerSocket server, FixSession.Config config, FixSession.Listener listener) throws IOException Accepts one connection, awaits the peer's Logon, replies, and returns established.- Throws:
IOException
-
accept
public static FixSession accept(ServerSocket server, FixSession.Config config, FixSession.Listener listener, FixSessionStore store) throws IOException Asaccept(ServerSocket, Config, Listener)with a durable session store.- Throws:
IOException
-
sendNewOrderSingle
-
sendExecutionReport
Venue side: sends an execution report for a received order. -
sendOrderCancelRequest
-
sendOrderCancelReplace
-
sendReject
Sends a session-level Reject (35=3) referring to an inbound message. -
logout
public void logout()Initiates the Logout handshake and closes the session. -
isEstablished
public boolean isEstablished() -
expectedIncomingSeqNum
public long expectedIncomingSeqNum()Next incoming sequence number this session expects (for diagnostics/tests). -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-