+act - 15757 - Reworks implementation of ActorSystem shutdown
* deprecates awaitTermination, shutdown and isTerminated * introduces a terminate-method that returns a Future[Unit] * introduces a whenTerminated-method that returns a Future[Unit] * simplifies the implementation by removing blocking constructs * adds tests for terminate() and whenTerminated
This commit is contained in:
parent
3ca27a54ad
commit
cd8e97c060
51 changed files with 183 additions and 169 deletions
|
|
@ -5,8 +5,6 @@
|
|||
package docs.actor;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.event.LoggingAdapter;
|
||||
import akka.event.Logging;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
import akka.testkit.ErrorFilter;
|
||||
import akka.testkit.EventFilter;
|
||||
|
|
@ -65,9 +63,8 @@ public class ActorDocTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
system.shutdown();
|
||||
system.awaitTermination(Duration.create("5 seconds"));
|
||||
public static void afterClass() throws Exception {
|
||||
Await.ready(system.terminate(), Duration.create("5 seconds"));
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -316,7 +313,7 @@ public class ActorDocTest {
|
|||
swapper.tell(Swap, ActorRef.noSender()); // logs Ho
|
||||
swapper.tell(Swap, ActorRef.noSender()); // logs Hi
|
||||
swapper.tell(Swap, ActorRef.noSender()); // logs Ho
|
||||
system.shutdown();
|
||||
system.terminate();
|
||||
}
|
||||
}
|
||||
//#swapper
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import akka.testkit.JavaTestKit;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.PartialFunction;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import scala.concurrent.Await;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class InitializationDocTest {
|
||||
|
||||
|
|
@ -26,9 +26,8 @@ public class InitializationDocTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
system.shutdown();
|
||||
system.awaitTermination(Duration.create("5 seconds"));
|
||||
public static void afterClass() throws Exception {
|
||||
Await.ready(system.terminate(), Duration.create("5 seconds"));
|
||||
}
|
||||
|
||||
public static class MessageInitExample extends AbstractActor {
|
||||
|
|
|
|||
|
|
@ -19,11 +19,8 @@ import akka.util.Timeout;
|
|||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.PartialFunction;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import static akka.japi.Util.classTag;
|
||||
import static akka.actor.SupervisorStrategy.resume;
|
||||
import static akka.actor.SupervisorStrategy.restart;
|
||||
import static akka.actor.SupervisorStrategy.stop;
|
||||
import static akka.actor.SupervisorStrategy.escalate;
|
||||
|
|
@ -79,13 +76,13 @@ public class FaultHandlingDocSample {
|
|||
log().info("Current progress: {} %", progress.percent);
|
||||
if (progress.percent >= 100.0) {
|
||||
log().info("That's all, shutting down");
|
||||
context().system().shutdown();
|
||||
context().system().terminate();
|
||||
}
|
||||
}).
|
||||
matchEquals(ReceiveTimeout.getInstance(), x -> {
|
||||
// No progress within 15 seconds, ServiceUnavailable
|
||||
log().error("Shutting down due to unavailable service");
|
||||
context().system().shutdown();
|
||||
context().system().terminate();
|
||||
}).build(), context()
|
||||
));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue