Skip to content

Commit ce6c3ed

Browse files
esanchezroschrjohn
andauthored
Add SessionID to SessionStateListener methods (#370)
* Add SessionID to SessionStateListener methods * added SessionID to calls to onConnectException() Co-authored-by: Christoph John <christoph.john@macd.com>
1 parent b33d7ff commit ce6c3ed

File tree

9 files changed

+82
-80
lines changed

9 files changed

+82
-80
lines changed

quickfixj-core/src/main/java/org/quickfixj/jmx/mbean/session/SessionAdmin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,47 +391,47 @@ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Except
391391
// Session State Notifications
392392
//
393393

394-
public void onConnect() {
394+
public void onConnect(SessionID sessionID) {
395395
sendNotification("connect");
396396
}
397397

398-
public void onDisconnect() {
398+
public void onDisconnect(SessionID sessionID) {
399399
sendNotification("disconnect");
400400
}
401401

402-
public void onLogon() {
402+
public void onLogon(SessionID sessionID) {
403403
sendNotification("logon");
404404
}
405405

406-
public void onLogout() {
406+
public void onLogout(SessionID sessionID) {
407407
sendNotification("logout");
408408
}
409409

410-
public void onHeartBeatTimeout() {
410+
public void onHeartBeatTimeout(SessionID sessionID) {
411411
sendNotification("heartBeatTimeout");
412412
}
413413

414-
public void onMissedHeartBeat() {
414+
public void onMissedHeartBeat(SessionID sessionID) {
415415
sendNotification("missedHeartBeat");
416416
}
417417

418-
public void onRefresh() {
418+
public void onRefresh(SessionID sessionID) {
419419
sendNotification("refresh");
420420
}
421421

422-
public void onResendRequestSent(int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
422+
public void onResendRequestSent(SessionID sessionID, int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
423423
sendNotification("resendRequestSent");
424424
}
425425

426-
public void onSequenceResetReceived(int newSeqNo, boolean gapFillFlag) {
426+
public void onSequenceResetReceived(SessionID sessionID, int newSeqNo, boolean gapFillFlag) {
427427
sendNotification("sequenceResetReceived");
428428
}
429429

430-
public void onResendRequestSatisfied(int beginSeqNo, int endSeqNo) {
430+
public void onResendRequestSatisfied(SessionID sessionID, int beginSeqNo, int endSeqNo) {
431431
sendNotification("resentRequestSatisfied");
432432
}
433433

434-
public void onReset() {
434+
public void onReset(SessionID sessionID) {
435435
sendNotification("reset");
436436
}
437437

quickfixj-core/src/main/java/quickfix/Session.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ public void setResponder(Responder responder) {
579579
synchronized (responderLock) {
580580
this.responder = responder;
581581
if (responder != null) {
582-
stateListener.onConnect();
582+
stateListener.onConnect(sessionID);
583583
} else {
584-
stateListener.onDisconnect();
584+
stateListener.onDisconnect(sessionID);
585585
}
586586
}
587587
}
@@ -1508,7 +1508,7 @@ private void nextSequenceReset(Message sequenceReset) throws IOException, Reject
15081508

15091509
if (validateSequenceNumbers && sequenceReset.isSetField(NewSeqNo.FIELD)) {
15101510
final int newSequence = sequenceReset.getInt(NewSeqNo.FIELD);
1511-
stateListener.onSequenceResetReceived(newSequence, isGapFill);
1511+
stateListener.onSequenceResetReceived(sessionID, newSequence, isGapFill);
15121512
getLog().onEvent(
15131513
"Received SequenceReset FROM: " + getExpectedTargetNum() + " TO: "
15141514
+ newSequence);
@@ -1808,7 +1808,7 @@ private boolean verify(Message msg, boolean checkTooHigh, boolean checkTooLow)
18081808
getLog().onEvent(
18091809
"ResendRequest for messages FROM " + range.getBeginSeqNo() + " TO " + range.getEndSeqNo()
18101810
+ " has been satisfied.");
1811-
stateListener.onResendRequestSatisfied(range.getBeginSeqNo(), range.getEndSeqNo());
1811+
stateListener.onResendRequestSatisfied(sessionID, range.getBeginSeqNo(), range.getEndSeqNo());
18121812
state.setResendRange(0, 0, 0);
18131813
}
18141814
}
@@ -1977,15 +1977,15 @@ public void next() throws IOException {
19771977
if (state.isTimedOut()) {
19781978
if (!disableHeartBeatCheck) {
19791979
disconnect("Timed out waiting for heartbeat", true);
1980-
stateListener.onHeartBeatTimeout();
1980+
stateListener.onHeartBeatTimeout(sessionID);
19811981
} else {
19821982
LOG.warn("Heartbeat failure detected but deactivated");
19831983
}
19841984
} else {
19851985
if (state.isTestRequestNeeded()) {
19861986
generateTestRequest("TEST");
19871987
getLog().onEvent("Sent test request TEST");
1988-
stateListener.onMissedHeartBeat();
1988+
stateListener.onMissedHeartBeat(sessionID);
19891989
} else if (state.isHeartBeatNeeded()) {
19901990
generateHeartbeat();
19911991
}
@@ -2098,7 +2098,7 @@ public void disconnect(String reason, boolean logError) throws IOException {
20982098
logApplicationException("onLogout()", t);
20992099
}
21002100

2101-
stateListener.onLogout();
2101+
stateListener.onLogout(sessionID);
21022102
}
21032103
} finally {
21042104
state.setLogonReceived(false);
@@ -2279,7 +2279,7 @@ private void nextLogon(Message logon) throws FieldNotFound, RejectLogon, Incorre
22792279
} catch (final Throwable t) {
22802280
logApplicationException("onLogon()", t);
22812281
}
2282-
stateListener.onLogon();
2282+
stateListener.onLogon(sessionID);
22832283
lastSessionLogon = SystemTime.currentTimeMillis();
22842284
logonAttempts = 0;
22852285
}
@@ -2502,7 +2502,7 @@ private void sendResendRequest(String beginString, int msgSeqNum, int beginSeqNo
25022502
int resendRangeEndSeqNum = msgSeqNum - 1;
25032503
int resendRangeCurrentSeqNum = resendRequestChunkSize == 0 ? 0 : lastEndSeqNoSent;
25042504
state.setResendRange(beginSeqNo, resendRangeEndSeqNum, resendRangeCurrentSeqNum);
2505-
stateListener.onResendRequestSent(beginSeqNo, resendRangeEndSeqNum, resendRangeCurrentSeqNum);
2505+
stateListener.onResendRequestSent(sessionID, beginSeqNo, resendRangeEndSeqNum, resendRangeCurrentSeqNum);
25062506
}
25072507

25082508
private boolean validatePossDup(Message msg) throws FieldNotFound, IOException {
@@ -2678,7 +2678,7 @@ private void resetState() {
26782678
}
26792679
try {
26802680
state.reset();
2681-
stateListener.onReset();
2681+
stateListener.onReset(sessionID);
26822682
} finally {
26832683
isResettingState.set(false);
26842684
state.setResetStatePending(false);
@@ -3084,7 +3084,7 @@ private void setLogonTags(final Message logon) {
30843084
private void refreshState() throws IOException {
30853085
getLog().onEvent("Refreshing message/state store on Logon");
30863086
getStore().refresh();
3087-
stateListener.onRefresh();
3087+
stateListener.onRefresh(sessionID);
30883088
}
30893089

30903090
}

quickfixj-core/src/main/java/quickfix/SessionStateListener.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,58 @@ public interface SessionStateListener {
2323
/**
2424
* Called when connection has been established.
2525
*/
26-
default void onConnect() {
26+
default void onConnect(SessionID sessionID) {
2727
}
2828

2929
/**
3030
* Called when Exception occurs during connection establishment.
3131
*
32+
* @param sessionID affected SessionID
3233
* @param exception thrown Exception
3334
*/
34-
default void onConnectException(Exception exception) {
35+
default void onConnectException(SessionID sessionID, Exception exception) {
3536
}
3637

3738
/**
3839
* Called when connection has been disconnected.
3940
*/
40-
default void onDisconnect() {
41+
default void onDisconnect(SessionID sessionID) {
4142
}
4243

4344
/**
4445
* Called when session has been logged on.
4546
*/
46-
default void onLogon() {
47+
default void onLogon(SessionID sessionID) {
4748
}
4849

4950
/**
5051
* Called when session has been logged out.
5152
*/
52-
default void onLogout() {
53+
default void onLogout(SessionID sessionID) {
5354
}
5455

5556
/**
5657
* Called when message store gets reset.
5758
*/
58-
default void onReset() {
59+
default void onReset(SessionID sessionID) {
5960
}
6061

6162
/**
6263
* Called when message store gets refreshed on Logon.
6364
*/
64-
default void onRefresh() {
65+
default void onRefresh(SessionID sessionID) {
6566
}
6667

6768
/**
6869
* Called when TestRequest is sent out due to missed Heartbeat.
6970
*/
70-
default void onMissedHeartBeat() {
71+
default void onMissedHeartBeat(SessionID sessionID) {
7172
}
7273

7374
/**
7475
* Called when Heartbeat timeout has been detected.
7576
*/
76-
default void onHeartBeatTimeout() {
77+
default void onHeartBeatTimeout(SessionID sessionID) {
7778
}
7879

7980
/**
@@ -84,7 +85,7 @@ default void onHeartBeatTimeout() {
8485
* @param currentEndSeqNo last seqnum of range that gets requested on
8586
* chunked ResendRequests
8687
*/
87-
default void onResendRequestSent(int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
88+
default void onResendRequestSent(SessionID sessionID, int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
8889
}
8990

9091
/**
@@ -93,7 +94,7 @@ default void onResendRequestSent(int beginSeqNo, int endSeqNo, int currentEndSeq
9394
* @param newSeqNo NewSeqNo from SequenceReset
9495
* @param gapFillFlag GapFillFlag from SequenceReset
9596
*/
96-
default void onSequenceResetReceived(int newSeqNo, boolean gapFillFlag) {
97+
default void onSequenceResetReceived(SessionID sessionID, int newSeqNo, boolean gapFillFlag) {
9798
}
9899

99100
/**
@@ -102,7 +103,6 @@ default void onSequenceResetReceived(int newSeqNo, boolean gapFillFlag) {
102103
* @param beginSeqNo first seqnum that was requested
103104
* @param endSeqNo last seqnum that was requested
104105
*/
105-
default void onResendRequestSatisfied(int beginSeqNo, int endSeqNo) {
106+
default void onResendRequestSatisfied(SessionID sessionID, int beginSeqNo, int endSeqNo) {
106107
}
107-
108108
}

quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ private void handleConnectException(Throwable e) {
263263
final String nextRetryMsg = " (Next retry in " + computeNextRetryConnectDelay() + " milliseconds)";
264264
if (e instanceof IOException) {
265265
fixSession.getLog().onErrorEvent(e.getClass().getName() + " during connection to " + socketAddress + ": " + e + nextRetryMsg);
266-
fixSession.getStateListener().onConnectException((IOException) e);
266+
fixSession.getStateListener().onConnectException(fixSession.getSessionID(), (IOException) e);
267267
} else {
268268
LogUtil.logThrowable(fixSession.getLog(), "Exception during connection to " + socketAddress + nextRetryMsg, e);
269-
fixSession.getStateListener().onConnectException(new Exception(e));
269+
fixSession.getStateListener().onConnectException(fixSession.getSessionID(), new Exception(e));
270270
}
271271
connectFuture = null;
272272
}

quickfixj-core/src/test/java/quickfix/SessionDisconnectConcurrentlyTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,37 +330,37 @@ public void disconnect() {
330330
}
331331
}
332332

333-
public void onConnect() {
333+
public void onConnect(SessionID sessionID) {
334334
}
335335

336-
public void onDisconnect() {
336+
public void onDisconnect(SessionID sessionID) {
337337
}
338338

339-
public void onLogon() {
339+
public void onLogon(SessionID sessionID) {
340340
}
341341

342-
public void onLogout() {
342+
public void onLogout(SessionID sessionID) {
343343
}
344344

345-
public void onReset() {
345+
public void onReset(SessionID sessionID) {
346346
}
347347

348-
public void onRefresh() {
348+
public void onRefresh(SessionID sessionID) {
349349
}
350350

351-
public void onMissedHeartBeat() {
351+
public void onMissedHeartBeat(SessionID sessionID) {
352352
}
353353

354-
public void onHeartBeatTimeout() {
354+
public void onHeartBeatTimeout(SessionID sessionID) {
355355
}
356356

357-
public void onResendRequestSent(int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
357+
public void onResendRequestSent(SessionID sessionID, int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
358358
}
359359

360-
public void onSequenceResetReceived(int newSeqNo, boolean gapFillFlag) {
360+
public void onSequenceResetReceived(SessionID sessionID, int newSeqNo, boolean gapFillFlag) {
361361
}
362362

363-
public void onResendRequestSatisfied(int beginSeqNo, int endSeqNo) {
363+
public void onResendRequestSatisfied(SessionID sessionID, int beginSeqNo, int endSeqNo) {
364364
}
365365
}
366366

quickfixj-core/src/test/java/quickfix/SessionResetTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,38 @@ public String getRemoteAddress() {
107107
public void disconnect() {
108108
}
109109

110-
public void onConnect() {
110+
public void onConnect(SessionID sessionID) {
111111
}
112112

113-
public void onDisconnect() {
113+
public void onDisconnect(SessionID sessionID) {
114114
}
115115

116-
public void onLogon() {
116+
public void onLogon(SessionID sessionID) {
117117
}
118118

119-
public void onLogout() {
119+
public void onLogout(SessionID sessionID) {
120120
}
121121

122-
public void onReset() {
122+
public void onReset(SessionID sessionID) {
123123
onResetCalled = true;
124124
}
125125

126-
public void onRefresh() {
126+
public void onRefresh(SessionID sessionID) {
127127
}
128128

129-
public void onMissedHeartBeat() {
129+
public void onMissedHeartBeat(SessionID sessionID) {
130130
}
131131

132-
public void onHeartBeatTimeout() {
132+
public void onHeartBeatTimeout(SessionID sessionID) {
133133
}
134134

135-
public void onResendRequestSent(int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
135+
public void onResendRequestSent(SessionID sessionID, int beginSeqNo, int endSeqNo, int currentEndSeqNo) {
136136
}
137137

138-
public void onSequenceResetReceived(int newSeqNo, boolean gapFillFlag) {
138+
public void onSequenceResetReceived(SessionID sessionID, int newSeqNo, boolean gapFillFlag) {
139139
}
140140

141-
public void onResendRequestSatisfied(int beginSeqNo, int endSeqNo) {
141+
public void onResendRequestSatisfied(SessionID sessionID, int beginSeqNo, int endSeqNo) {
142142
}
143143
}
144144

quickfixj-core/src/test/java/quickfix/SessionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ public void testSendingTimeRejectBeforeLogon() throws Exception {
12151215

12161216
session.next(message);
12171217

1218-
verify(mockStateListener).onDisconnect();
1218+
verify(mockStateListener).onDisconnect(session.getSessionID());
12191219
verifyNoMoreInteractions(mockStateListener);
12201220
}
12211221
}
@@ -1238,7 +1238,7 @@ public void testCorruptLogonReject() throws Exception {
12381238

12391239
session.next(message);
12401240

1241-
verify(mockStateListener).onDisconnect();
1241+
verify(mockStateListener).onDisconnect(session.getSessionID());
12421242
verifyNoMoreInteractions(mockStateListener);
12431243
}
12441244
}

0 commit comments

Comments
 (0)