-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
queue-server: Make the completion ack timeout configurable
- Loading branch information
Showing
7 changed files
with
36 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
public class StandaloneNotificationQueueHandler implements NotificationQueueHandler { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(StandaloneNotificationQueueHandler.class); | ||
private static final long WAIT_ACK_TO_SEC = 3; | ||
private final long ackTimeSec; | ||
|
||
private static final List<Period> RETRY_SCHEDULE = Arrays.asList( | ||
Period.minutes(1), | ||
|
@@ -56,10 +56,12 @@ public class StandaloneNotificationQueueHandler implements NotificationQueueHand | |
private final Map<String, ServerCallStreamObserver<EventMsg>> observers; | ||
private final Map<String, CompletionSuccess> dispatchedEvents; | ||
|
||
public StandaloneNotificationQueueHandler() { | ||
public StandaloneNotificationQueueHandler(long ackTimeSec) { | ||
logger.info("StandaloneNotificationQueueHandler configured with ackTime value = %d sec", ackTimeSec); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sbrossie
Author
Member
|
||
this.lock = new ReentrantLock(); | ||
this.observers = new HashMap<>(); | ||
this.dispatchedEvents = new HashMap(); | ||
this.ackTimeSec = ackTimeSec; | ||
} | ||
|
||
public void notifyEventCompletion(final String userToken, final boolean success) { | ||
|
@@ -181,7 +183,7 @@ public void handleReadyNotification(final NotificationEvent inputEvent, final Da | |
} | ||
foundValidObs = true; | ||
try { | ||
complSuccess = new CompletionSuccess(userTokenStr); | ||
complSuccess = new CompletionSuccess(userTokenStr, ackTimeSec); | ||
dispatchedEvents.put(userTokenStr, complSuccess); | ||
obs.onNext(event); | ||
// Break after first success | ||
|
@@ -214,11 +216,13 @@ private static class CompletionSuccess { | |
|
||
private final String userToken; | ||
private final CountDownLatch latch; | ||
private final long ackTimeSec; | ||
private boolean status; | ||
|
||
public CompletionSuccess(final String userToken) { | ||
public CompletionSuccess(final String userToken, final long ackTimeSec) { | ||
this.userToken = userToken; | ||
this.latch = new CountDownLatch(1); | ||
this.ackTimeSec = ackTimeSec; | ||
} | ||
|
||
public void notify(boolean status) { | ||
|
@@ -228,9 +232,9 @@ public void notify(boolean status) { | |
|
||
public void waitForCompletion() throws QueueRetryException { | ||
try { | ||
final boolean res = latch.await(WAIT_ACK_TO_SEC, TimeUnit.SECONDS); | ||
final boolean res = latch.await(ackTimeSec, TimeUnit.SECONDS); | ||
if (!res) { | ||
logger.warn("Thread waiting for event userToken={} timed out after {} seconds", userToken, WAIT_ACK_TO_SEC); | ||
logger.warn("Thread waiting for event userToken={} timed out after {} seconds", userToken, ackTimeSec); | ||
throw new QueueRetryException(RETRY_SCHEDULE); | ||
} else if (!status) { | ||
logger.info("Client Nack for userToken={}", userToken); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ app: | |
port: 10001 | ||
nbThreads: 30 | ||
recycleTcpConn: false | ||
ackTimeSec: 5 | ||
This comment has been minimized.
Sorry, something went wrong.
pierre
Member
|
||
logging: | ||
level: debug | ||
format: text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ app: | |
port: 9999 | ||
nbThreads: 30 | ||
recycleTcpConn: false | ||
ackTimeSec: 5 | ||
logging: | ||
level: debug | ||
format: text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Don't you need
{}
instead? IDEA should have warned you 🤔