GatewayRequester

This commit is contained in:
ialbert 2023-09-11 20:01:13 +03:00
parent 71cb78b72c
commit 6aa252f801

View file

@ -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<Boolean> 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());