Skip to content

Commit

Permalink
Enable client reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
denis.plotnikov committed Dec 5, 2024
1 parent 9eb318d commit 8360cab
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/main/java/com/exactpro/th2/FixHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,26 @@ public CompletableFuture<MessageID> send(@NotNull ByteBuf body, @NotNull Map<Str
disconnectStrategyLock.unlock();
}

FixField msgType = findField(body, MSG_TYPE_TAG);
boolean isLogout = msgType != null && Objects.equals(msgType.getValue(), MSG_TYPE_LOGOUT);
boolean isLogon = msgType != null && Objects.equals(msgType.getValue(), MSG_TYPE_LOGON);
boolean enableReconnect = properties.containsKey(ENABLE_RECONNECT_PROPERTY);

if(isLogon && enableReconnect) {
context.send(CommonUtil.toEvent(String.format("Enabling session reconnects: %b", channel.getSessionAlias())));
sessionActive.set(true);
try {
sendingTimeoutHandler.getWithTimeout(channel.open());
} catch (Exception e) {
context.send(CommonUtil.toErrorEvent(String.format("Error while ending session %s by user logout. Is graceful disconnect: %b", channel.getSessionAlias()), e));
}
return CompletableFuture.completedFuture(null);
}

if (!sessionActive.get()) {
throw new IllegalStateException("Session is not active. It is not possible to send messages.");
}

FixField msgType = findField(body, MSG_TYPE_TAG);
boolean isLogout = msgType != null && Objects.equals(msgType.getValue(), MSG_TYPE_LOGOUT);
boolean isLogon = msgType != null && Objects.equals(msgType.getValue(), MSG_TYPE_LOGON);
if(isLogout && !channel.isOpen()) {
String message = String.format("%s - %s: Logout ignored as channel is already closed.", channel.getSessionGroup(), channel.getSessionAlias());
LOGGER.warn(message);
Expand All @@ -400,7 +413,6 @@ public CompletableFuture<MessageID> send(@NotNull ByteBuf body, @NotNull Map<Str
boolean isUngracefulDisconnect = Boolean.getBoolean(properties.get(UNGRACEFUL_DISCONNECT_PROPERTY));

boolean disableReconnect = properties.containsKey(DISABLE_RECONNECT_PROPERTY);
boolean enableReconnect = properties.containsKey(ENABLE_RECONNECT_PROPERTY);

if(isLogout) {
context.send(CommonUtil.toEvent(String.format("Closing session %s. Is graceful disconnect: %b", channel.getSessionAlias(), !isUngracefulDisconnect)));
Expand All @@ -421,17 +433,6 @@ public CompletableFuture<MessageID> send(@NotNull ByteBuf body, @NotNull Map<Str
return CompletableFuture.completedFuture(null);
}

if(isLogon && enableReconnect) {
context.send(CommonUtil.toEvent(String.format("Enabling session reconnects: %b", channel.getSessionAlias())));
sessionActive.set(true);
try {
sendingTimeoutHandler.getWithTimeout(channel.open());
} catch (Exception e) {
context.send(CommonUtil.toErrorEvent(String.format("Error while ending session %s by user logout. Is graceful disconnect: %b", channel.getSessionAlias(), !isUngracefulDisconnect), e));
}
return CompletableFuture.completedFuture(null);
}



// TODO: probably, this should be moved to the core part
Expand Down

0 comments on commit 8360cab

Please sign in to comment.