Created
September 5, 2017 13:17
-
-
Save iaintshine/0b72b33dcf06146976a6c639a368f9c0 to your computer and use it in GitHub Desktop.
Graceful Stop example in akkka
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
long timeout = 5L; | |
try { | |
// https://petabridge.com/blog/how-to-stop-an-actor-akkadotnet/ | |
// http://doc.akka.io/docs/akka/current/java/actors.html - "Graceful Stop" | |
// | |
// I don't specify stopMessage as by default it's PoisonPill, I want the processing of messages to be finished | |
// by the target actor. | |
CompletionStage<Boolean> stopped = gracefulStop(queueActor, Duration.create(5, TimeUnit.SECONDS)); | |
stopped.toCompletableFuture().get(timeout + 1, TimeUnit.SECONDS); | |
} catch (AskTimeoutException e) { | |
log.warning("shutdownQueue - the actor for queue {} wasn't stopped within {} seconds", queueName, timeout); | |
} catch (TimeoutException e) { | |
log.warning("shutdownQueue - gracefulStop for queue {} was unsuccessful. This shouldn't even happen.", queueName); | |
} catch (ExecutionException e) { | |
throw new QueueShutdownFailedException(queueName, e.getCause()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment