2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
|
2013-04-16 22:31:09 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-03-16 09:30:00 +01:00
|
|
|
package jdocs.io.japi;
|
2013-04-16 22:31:09 +02:00
|
|
|
|
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
2022-11-12 10:21:24 +01:00
|
|
|
import org.apache.pekko.actor.ActorRef;
|
|
|
|
|
import org.apache.pekko.actor.ActorSystem;
|
|
|
|
|
import org.apache.pekko.actor.Props;
|
2013-04-16 22:31:09 +02:00
|
|
|
|
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
|
|
|
|
|
public class EchoServer {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws InterruptedException {
|
2022-12-02 04:53:48 -08:00
|
|
|
final Config config = ConfigFactory.parseString("pekko.loglevel=DEBUG");
|
2013-04-16 22:31:09 +02:00
|
|
|
final ActorSystem system = ActorSystem.create("EchoServer", config);
|
|
|
|
|
try {
|
|
|
|
|
final CountDownLatch latch = new CountDownLatch(1);
|
|
|
|
|
final ActorRef watcher = system.actorOf(Props.create(Watcher.class, latch), "watcher");
|
2019-01-12 04:00:53 +08:00
|
|
|
final ActorRef nackServer =
|
|
|
|
|
system.actorOf(Props.create(EchoManager.class, EchoHandler.class), "nack");
|
|
|
|
|
final ActorRef ackServer =
|
|
|
|
|
system.actorOf(Props.create(EchoManager.class, SimpleEchoHandler.class), "ack");
|
2013-06-05 16:59:25 +02:00
|
|
|
watcher.tell(nackServer, ActorRef.noSender());
|
|
|
|
|
watcher.tell(ackServer, ActorRef.noSender());
|
2013-04-16 22:31:09 +02:00
|
|
|
latch.await(10, TimeUnit.MINUTES);
|
|
|
|
|
} finally {
|
2014-08-25 15:49:28 +02:00
|
|
|
system.terminate();
|
2013-04-16 22:31:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|