Github user JiriOndrusek commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1761#discussion_r160420636
--- Diff:
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/RemotingConnectionImpl.java
---
@@ -205,14 +211,59 @@ public void fail(final ActiveMQException me, String
scaleDownTargetNodeID) {
}
// Then call the listeners
- callFailureListeners(me, scaleDownTargetNodeID);
+ List<CountDownLatch> failureLatches = callFailureListeners(me,
scaleDownTargetNodeID);
callClosingListeners();
- internalClose();
+ CountDownLatch latch = new CountDownLatch(1);
- for (Channel channel : channels.values()) {
- channel.returnBlocking(me);
+ new ScheduledInternalClose(failureLatches, me, latch).run();
+
+ return latch;
+ }
+
+ // internalClose has to be called after failureListeners are finished.
+ private class ScheduledInternalClose implements Runnable {
+
+ private final List<CountDownLatch> failureLatches;
+ private final ActiveMQException me;
+ private final CountDownLatch latch;
+
+ public ScheduledInternalClose(List<CountDownLatch> failureLatches,
final ActiveMQException me, CountDownLatch latch) {
+ this.failureLatches = failureLatches;
+ this.me = me;
+ this.latch = latch;
+ }
+
+ @Override
+ public void run() {
+ List<CountDownLatch> running = new LinkedList<>();
+ failureLatches.forEach((l) -> {
+ try {
+ //interval is defined during scheduled execution
+ if (!l.await(1, TimeUnit.MILLISECONDS)) {
+ running.add(l);
+ }
+ } catch (InterruptedException e) {
+ ActiveMQClientLogger.LOGGER.warn(e.getMessage(), e);
+ }
+ });
+
+ if (!running.isEmpty()) {
+ //TODO(jondruse) is there constant or propertyF usable for
this kind of wait interval?
+ scheduledExecutorService.schedule(new
ScheduledInternalClose(running, me, latch), 500, TimeUnit.MILLISECONDS);
--- End diff --
I have too use "constant" for repetitive checking, whether action is
already finished. May I use some generic timeout used in project (or define new
attribute, ...)
---