Skip to content

Commit 2cc13c1

Browse files
committed
Refactor verify: split session validation and validateAndDispatchMsg (#939)
1 parent 1d942ca commit 2cc13c1

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ private boolean resetOrDisconnectIfRequired(Message msg) {
13131313

13141314
private void nextReject(Message reject) throws FieldNotFound, RejectLogon, IncorrectDataFormat,
13151315
IncorrectTagValue, UnsupportedMessageType, IOException, InvalidMessage {
1316-
if (!verify(reject, false, validateSequenceNumbers)) {
1316+
if (!validateAndDispatchMsg(reject, false, validateSequenceNumbers)) {
13171317
return;
13181318
}
13191319
if (getExpectedTargetNum() == reject.getHeader().getInt(MsgSeqNum.FIELD)) {
@@ -1332,7 +1332,7 @@ private void nextResendRequest(Message resendRequest) throws IOException, Reject
13321332
// ResendRequest to be satisfied in order to process the queued ResendRequest of the counterparty.
13331333
// Instead, send out the requested messages and afterwards enqueue the ResendRequest in order to
13341334
// later increase the target seqnum in method nextQueued(int).
1335-
if (!verify(resendRequest, false, validateSequenceNumbers)) {
1335+
if (!validateAndDispatchMsg(resendRequest, false, validateSequenceNumbers)) {
13361336
return;
13371337
}
13381338
final int msgSeqNum = resendRequest.getHeader().getInt(MsgSeqNum.FIELD);
@@ -1456,7 +1456,7 @@ private void logApplicationException(String location, Throwable t) {
14561456

14571457
private void nextLogout(Message logout) throws IOException, RejectLogon, FieldNotFound,
14581458
IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
1459-
if (!verify(logout, false, false)) {
1459+
if (!validateAndDispatchMsg(logout, false, false)) {
14601460
return;
14611461
}
14621462

@@ -1543,7 +1543,7 @@ private void nextSequenceReset(Message sequenceReset) throws IOException, Reject
15431543
isGapFill = sequenceReset.getBoolean(GapFillFlag.FIELD) && validateSequenceNumbers;
15441544
}
15451545

1546-
if (!verify(sequenceReset, isGapFill, isGapFill)) {
1546+
if (!validateAndDispatchMsg(sequenceReset, isGapFill, isGapFill)) {
15471547
return;
15481548
}
15491549

@@ -1797,6 +1797,21 @@ private void nextHeartBeat(Message heartBeat) throws FieldNotFound, RejectLogon,
17971797
nextQueued();
17981798
}
17991799

1800+
private boolean validateAndDispatchMsg(Message msg, boolean checkTooHigh, boolean checkTooLow)
1801+
throws RejectLogon, FieldNotFound, IncorrectDataFormat, IncorrectTagValue,
1802+
UnsupportedMessageType, IOException {
1803+
if (!verify(msg, checkTooHigh, checkTooLow)) {
1804+
return false;
1805+
}
1806+
1807+
final Message.Header header = msg.getHeader();
1808+
final String msgType = header.getString(MsgType.FIELD);
1809+
1810+
fromCallback(msgType, msg, sessionID);
1811+
1812+
return true;
1813+
}
1814+
18001815
private boolean verify(Message msg, boolean checkTooHigh, boolean checkTooLow)
18011816
throws RejectLogon, FieldNotFound, IncorrectDataFormat, IncorrectTagValue,
18021817
UnsupportedMessageType, IOException {
@@ -1869,7 +1884,6 @@ private boolean verify(Message msg, boolean checkTooHigh, boolean checkTooLow)
18691884
return false;
18701885
}
18711886

1872-
fromCallback(msgType, msg, sessionID);
18731887
return true;
18741888
}
18751889

@@ -1940,7 +1954,7 @@ private synchronized boolean validLogonState(String msgType) {
19401954

19411955
private boolean verify(Message message) throws RejectLogon, FieldNotFound, IncorrectDataFormat,
19421956
IncorrectTagValue, UnsupportedMessageType, IOException {
1943-
return verify(message, validateSequenceNumbers, validateSequenceNumbers);
1957+
return validateAndDispatchMsg(message, validateSequenceNumbers, validateSequenceNumbers);
19441958
}
19451959

19461960
/**
@@ -2202,7 +2216,7 @@ private void nextLogon(Message logon) throws FieldNotFound, RejectLogon, Incorre
22022216
state.setResetReceived(true);
22032217
}
22042218

2205-
if (!verify(logon, false, validateSequenceNumbers)) {
2219+
if (!validateAndDispatchMsg(logon, false, validateSequenceNumbers)) {
22062220
return;
22072221
}
22082222

0 commit comments

Comments
 (0)