Skip to content

Commit

Permalink
Issue #87: Shutdown AdaptableBus Executor when closing MessagingProvi…
Browse files Browse the repository at this point in the history
…der to prevent blocked threads after closing the client

Signed-off-by: David Schwilk <david.schwilk@bosch.io>
  • Loading branch information
DerSchwilk committed Sep 28, 2020
1 parent 3d257c7 commit 99311fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ SubscriptionId subscribeForAdaptableWithTimeout(Classification tag,
*/
boolean unsubscribe(@Nullable SubscriptionId subscriptionId);

/**
* Closes the executor of the adaptable bus .
*
* @since 1.2.2
*/
void shutdownExecutor();

/**
* Publish a string message that may or may not be an adaptable.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public void publish(final String message) {
singleThreadedExecutorService.submit(() -> doPublish(message));
}

@Override
public void shutdownExecutor() {
LOGGER.trace("Shutting down AdaptableBus Executor");
singleThreadedExecutorService.shutdownNow();
}

// call this in a single-threaded executor so that ordering is preserved
private void doPublish(final String message) {
if (publishToOneTimeStringSubscribers(message)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public void close() {

cancelScheduledReconnect();
authenticationProvider.destroy();
adaptableBus.shutdownExecutor();
final WebSocket ws = webSocket.get();
if (ws != null) {
ws.disconnect();
Expand Down

0 comments on commit 99311fc

Please sign in to comment.