This PR is dependent on #26 (therefore this many commits - only the last one is related to this PR).
Previously, some started Futures in TaskActionsQueue were not properly finished in case of shutdown of Worker.
The core issue was that in TaskActionsQueue we run() TaskActions, which return a CompleteableFuture, but no one waited on that Future or checked its status.
The other issue was that sleeps generated by ScheduledExecutorService were not immediately stopped in case of Worker stop. One unwanted effect of this was that after we closed Driver3's Session, a few seconds later some Futures "sleeping" on that Executor would "wake up" and start to use recently closed Session, causing many exceptions.
This commit fixes the first issue by saving started Futures into a set of running Futures. Those Futures delete themselves from that set after they have finished running. When closing TaskActionsQueue we wait for this set to get empty (with some timeout).
This commit also adds DelayedFutureService which generates "sleeping" futures and allows to immediately complete them in case of shutdown (so that the shutdown is very quick).
This PR is dependent on #26 (therefore this many commits - only the last one is related to this PR).
Previously, some started
Futures
inTaskActionsQueue
were not properly finished in case of shutdown ofWorker
.The core issue was that in
TaskActionsQueue
we run()TaskActions
, which return aCompleteableFuture
, but no one waited on thatFuture
or checked its status.The other issue was that sleeps generated by
ScheduledExecutorService
were not immediately stopped in case ofWorker
stop. One unwanted effect of this was that after we closed Driver3's Session, a few seconds later someFutures
"sleeping" on thatExecutor
would "wake up" and start to use recently closed Session, causing many exceptions.This commit fixes the first issue by saving started
Futures
into a set of runningFutures
. ThoseFutures
delete themselves from that set after they have finished running. When closingTaskActionsQueue
we wait for this set to get empty (with some timeout).This commit also adds
DelayedFutureService
which generates "sleeping" futures and allows to immediately complete them in case of shutdown (so that the shutdown is very quick).