From 6aa252f801de6d1c2cd10fc32eb8618cd35e5fde Mon Sep 17 00:00:00 2001 From: ialbert Date: Mon, 11 Sep 2023 20:01:13 +0300 Subject: [PATCH] GatewayRequester --- .../session/stage/impl/GatewayRequester.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/GatewayRequester.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/GatewayRequester.java index 59358851d..4880cd807 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/GatewayRequester.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/GatewayRequester.java @@ -44,6 +44,7 @@ public class GatewayRequester extends QueueConsumer implements InitializingBean private final Lock gatewayLock = new ReentrantLock(); private final Condition gatewayCondition = gatewayLock.newCondition(); + private Long omtId = null; private SingleAssetResponse assetOperationApprovalRequest = null; @@ -66,7 +67,7 @@ public class GatewayRequester extends QueueConsumer implements InitializingBean } public Optional gatewayRequestAndWait(Registry om_t) { - boolean gatewayReceived = false; + SingleAssetResponse responseReceived = null; gatewayLock.lock(); try { if (this.omtId != null) { @@ -89,16 +90,19 @@ public class GatewayRequester extends QueueConsumer implements InitializingBean log.debug("sending om*t.id={} to gateway", om_t.getId()); kafkaSender.sendRequestToQueue(Consts.ASSET_OPERATION, assetOperationListRequest); this.omtId = om_t.getId(); - gatewayReceived = gatewayCondition.await(GATEWAY_TIMEOUT, TimeUnit.SECONDS); + boolean gatewayReceived = gatewayCondition.await(GATEWAY_TIMEOUT, TimeUnit.SECONDS); + if (gatewayReceived) { + responseReceived = assetOperationApprovalRequest; + assetOperationApprovalRequest = null; + } } catch (InterruptedException e) { log.error(ExceptionUtils.getStackTrace(e)); } finally { gatewayLock.unlock(); } - if (gatewayReceived) { - boolean approved = assetOperationApprovalRequest.isApproved(); + if (responseReceived != null) { + boolean approved = responseReceived.isApproved(); log.debug("om*t.id={} answer from gateway received. approval: {}", om_t.getId(), approved); - assetOperationApprovalRequest = null; return Optional.of(approved); } else { log.error("om*t.id={} answer from gateway not received.", om_t.getId());