Provide cancellation for CoordinatedShutdown tasks #27335
This commit is contained in:
parent
b5eb18a033
commit
3e71b8a8b8
5 changed files with 441 additions and 75 deletions
|
|
@ -13,7 +13,6 @@ import static jdocs.actor.Messages.Swap.Swap;
|
|||
import static jdocs.actor.Messages.*;
|
||||
import akka.actor.CoordinatedShutdown;
|
||||
|
||||
import akka.util.Timeout;
|
||||
import akka.Done;
|
||||
|
||||
import java.util.Optional;
|
||||
|
|
@ -848,6 +847,10 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
};
|
||||
}
|
||||
|
||||
private CompletionStage<Done> cleanup() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void coordinatedShutdown() {
|
||||
final ActorRef someActor = system.actorOf(Props.create(FirstActor.class));
|
||||
|
|
@ -862,6 +865,15 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
});
|
||||
// #coordinated-shutdown-addTask
|
||||
|
||||
// #coordinated-shutdown-cancellable
|
||||
Cancellable cancellable =
|
||||
CoordinatedShutdown.get(system)
|
||||
.addCancellableTask(
|
||||
CoordinatedShutdown.PhaseBeforeServiceUnbind(), "someTaskCleanup", () -> cleanup());
|
||||
// much later...
|
||||
cancellable.cancel();
|
||||
// #coordinated-shutdown-cancellable
|
||||
|
||||
// #coordinated-shutdown-jvm-hook
|
||||
CoordinatedShutdown.get(system)
|
||||
.addJvmShutdownHook(() -> System.out.println("custom JVM shutdown hook..."));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue