+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
|
|
@ -22,7 +22,6 @@ import com.typesafe.config.ConfigFactory;
|
|||
|
||||
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;
|
||||
|
|
@ -76,12 +75,12 @@ public class FaultHandlingDocSample {
|
|||
log.info("Current progress: {} %", progress.percent);
|
||||
if (progress.percent >= 100.0) {
|
||||
log.info("That's all, shutting down");
|
||||
getContext().system().shutdown();
|
||||
getContext().system().terminate();
|
||||
}
|
||||
} else if (msg == ReceiveTimeout.getInstance()) {
|
||||
// No progress within 15 seconds, ServiceUnavailable
|
||||
log.error("Shutting down due to unavailable service");
|
||||
getContext().system().shutdown();
|
||||
getContext().system().terminate();
|
||||
} else {
|
||||
unhandled(msg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class EchoServer {
|
|||
watcher.tell(ackServer, ActorRef.noSender());
|
||||
latch.await(10, TimeUnit.MINUTES);
|
||||
} finally {
|
||||
system.shutdown();
|
||||
system.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ actors does not respond (i.e. processing a message for extended periods of time
|
|||
and therefore not receiving the stop command), this whole process will be
|
||||
stuck.
|
||||
|
||||
Upon :meth:`ActorSystem.shutdown()`, the system guardian actors will be
|
||||
Upon :meth:`ActorSystem.terminate()`, the system guardian actors will be
|
||||
stopped, and the aforementioned process will ensure proper termination of the
|
||||
whole system.
|
||||
|
||||
|
|
|
|||
|
|
@ -621,7 +621,7 @@ actors does not respond (i.e. processing a message for extended periods of time
|
|||
and therefore not receiving the stop command), this whole process will be
|
||||
stuck.
|
||||
|
||||
Upon :meth:`ActorSystem.shutdown()`, the system guardian actors will be
|
||||
Upon :meth:`ActorSystem.terminate()`, the system guardian actors will be
|
||||
stopped, and the aforementioned process will ensure proper termination of the
|
||||
whole system.
|
||||
|
||||
|
|
|
|||
|
|
@ -672,7 +672,7 @@ actors does not respond (i.e. processing a message for extended periods of time
|
|||
and therefore not receiving the stop command), this whole process will be
|
||||
stuck.
|
||||
|
||||
Upon :meth:`ActorSystem.shutdown()`, the system guardian actors will be
|
||||
Upon :meth:`ActorSystem.terminate()`, the system guardian actors will be
|
||||
stopped, and the aforementioned process will ensure proper termination of the
|
||||
whole system.
|
||||
|
||||
|
|
|
|||
|
|
@ -53,13 +53,13 @@ class Listener extends Actor with ActorLogging {
|
|||
log.info("Current progress: {} %", percent)
|
||||
if (percent >= 100.0) {
|
||||
log.info("That's all, shutting down")
|
||||
context.system.shutdown()
|
||||
context.system.terminate()
|
||||
}
|
||||
|
||||
case ReceiveTimeout =>
|
||||
// No progress within 15 seconds, ServiceUnavailable
|
||||
log.error("Shutting down due to unavailable service")
|
||||
context.system.shutdown()
|
||||
context.system.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ object EchoServer extends App {
|
|||
|
||||
// make sure to stop the system so that the application stops
|
||||
try run()
|
||||
finally system.shutdown()
|
||||
finally system.terminate()
|
||||
|
||||
def run(): Unit = {
|
||||
import ActorDSL._
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import java.net.InetSocketAddress
|
|||
import akka.testkit.{ ImplicitSender, TestProbe, AkkaSpec }
|
||||
import akka.util.ByteString
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
object PullReadingExample {
|
||||
|
||||
class Listener(monitor: ActorRef) extends Actor {
|
||||
|
|
@ -77,7 +80,6 @@ class PullReadingSpec extends AkkaSpec with ImplicitSender {
|
|||
client.send(connection, ResumeReading)
|
||||
client.expectMsg(Received(ByteString("hello")))
|
||||
|
||||
system.shutdown()
|
||||
system.awaitTermination
|
||||
Await.ready(system.terminate(), Duration.Inf)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ trait PersistenceDocSpec {
|
|||
|
||||
processor ! PersistentBatch(List(Persistent("a"), Persistent("b")))
|
||||
//#batch-write
|
||||
system.shutdown()
|
||||
system.terminate()
|
||||
}
|
||||
|
||||
new AnyRef {
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ class TestkitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
//#put-your-test-code-here
|
||||
val probe = TestProbe()
|
||||
probe.send(testActor, "hello")
|
||||
try expectMsg("hello") catch { case NonFatal(e) => system.shutdown(); throw e }
|
||||
try expectMsg("hello") catch { case NonFatal(e) => system.terminate(); throw e }
|
||||
//#put-your-test-code-here
|
||||
|
||||
shutdown(system)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue