diff --git a/src/main/java/com/exactpro/th2/FixHandler.java b/src/main/java/com/exactpro/th2/FixHandler.java index b57c312..f59bcf3 100644 --- a/src/main/java/com/exactpro/th2/FixHandler.java +++ b/src/main/java/com/exactpro/th2/FixHandler.java @@ -358,19 +358,11 @@ public void onStart() { msgSeqNum.set(sequences.getClientSeq()); serverMsgSeqNum.set(sequences.getServerSeq()); } - if(!channel.isOpen()) channel.open(); + if(!channel.isOpen()) openChannel(); } @NotNull public CompletableFuture send(@NotNull ByteBuf body, @NotNull Map properties, @Nullable EventID eventID) { - try { - disconnectStrategyLock.lock(); - strategy.getSendStrategy(SendStrategy::getSendPreprocessor).process(body, properties); - } - finally { - 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); @@ -380,7 +372,7 @@ public CompletableFuture send(@NotNull ByteBuf body, @NotNull Map send(@NotNull ByteBuf body, @NotNull Map send(@NotNull ByteBuf body, @NotNull Map send(@NotNull ByteBuf body, @NotNull Map send(@NotNull ByteBuf body, @NotNull Map handleLogout(@NotNull ByteBuf message, Map logoutOnLogon(ByteBuf message, Map m handleLogon(message, metadata); try { disconnect(strategy.getGracefulDisconnect()); - if(!channel.isOpen()) channel.open().get(); + if(!channel.isOpen()) openChannel().get(); } catch (Exception e) { LOGGER.error("Error while reconnecting.", e); } @@ -2096,7 +2096,7 @@ private void setupTransformStrategy(RuleConfiguration configuration) { strategy.setCleanupHandler(this::cleanupTransformStrategy); try { disconnect(configuration.getGracefulDisconnect()); - if(!channel.isOpen()) channel.open().get(); + if(!channel.isOpen()) openChannel().get(); } catch (Exception e) { String message = String.format("Error while setting up %s", strategy.getType()); LOGGER.error(message, e); @@ -2670,10 +2670,17 @@ private void disconnect(boolean graceful) throws ExecutionException, Interrupted } private void openChannelAndWaitForLogon() throws ExecutionException, InterruptedException { - if(!channel.isOpen()) channel.open().get(); + if(!channel.isOpen()) openChannel().get(); waitUntilLoggedIn(); } + private CompletableFuture openChannel() { + if(channel != null && sessionActive.get()) { + return channel.open(); + } + return CompletableFuture.completedFuture(null); + } + private void waitUntilLoggedIn() { long start = System.currentTimeMillis(); while (!enabled.get() && System.currentTimeMillis() - start < 2000) {