use of akka.actor.ActorSystem in project lzl_workspace by hpulzl.
the class ActorSystemMain method main.
public static void main(String[] args) {
// 创建ActorSystem,初始化数据.有不同的构造方法,也可以读取资源文件
ActorSystem actorSystem = ActorSystem.create("akka-demo");
// 找到具体执行那一个actor
ActorRef actorRef = actorSystem.actorOf(Props.create(HelloActor.class));
// 发送actor传递的数据
actorRef.tell("hello", ActorRef.noSender());
}
use of akka.actor.ActorSystem in project flink by apache.
the class AkkaRpcActorHandshakeTest method setupClass.
@BeforeClass
public static void setupClass() {
final ActorSystem actorSystem1 = AkkaUtils.createDefaultActorSystem();
final ActorSystem actorSystem2 = AkkaUtils.createDefaultActorSystem();
final ActorSystem wrongVersionActorSystem = AkkaUtils.createDefaultActorSystem();
AkkaRpcServiceConfiguration akkaRpcServiceConfig = AkkaRpcServiceConfiguration.defaultConfiguration();
akkaRpcService1 = new AkkaRpcService(actorSystem1, akkaRpcServiceConfig);
akkaRpcService2 = new AkkaRpcService(actorSystem2, akkaRpcServiceConfig);
wrongVersionAkkaRpcService = new WrongVersionAkkaRpcService(wrongVersionActorSystem, AkkaRpcServiceConfiguration.defaultConfiguration());
}
use of akka.actor.ActorSystem in project flink by apache.
the class AkkaActorSystemTest method shutsDownOnActorFailure.
@Test
public void shutsDownOnActorFailure() {
final ActorSystem actorSystem = AkkaUtils.createLocalActorSystem(new Configuration());
try {
final CompletableFuture<Terminated> terminationFuture = actorSystem.getWhenTerminated().toCompletableFuture();
final ActorRef actorRef = actorSystem.actorOf(Props.create(SimpleActor.class));
final FlinkException cause = new FlinkException("Flink test exception");
actorRef.tell(Fail.exceptionally(cause), ActorRef.noSender());
// make sure that the ActorSystem shuts down
terminationFuture.join();
} finally {
AkkaUtils.terminateActorSystem(actorSystem).join();
}
}
use of akka.actor.ActorSystem in project flink by apache.
the class AkkaBootstrapToolsTest method testConcurrentActorSystemCreation.
/**
* Tests that we can concurrently create two {@link ActorSystem} without port conflicts. This
* effectively tests that we don't open a socket to check for a ports availability. See
* FLINK-10580 for more details.
*/
@Test
public void testConcurrentActorSystemCreation() throws Exception {
final int concurrentCreations = 10;
final ExecutorService executorService = Executors.newFixedThreadPool(concurrentCreations);
final CyclicBarrier cyclicBarrier = new CyclicBarrier(concurrentCreations);
try {
final List<CompletableFuture<Void>> actorSystemFutures = IntStream.range(0, concurrentCreations).mapToObj(ignored -> CompletableFuture.supplyAsync(CheckedSupplier.unchecked(() -> {
cyclicBarrier.await();
return AkkaBootstrapTools.startRemoteActorSystem(new Configuration(), "localhost", "0", LOG);
}), executorService)).map(// terminate ActorSystems
actorSystemFuture -> actorSystemFuture.thenCompose(AkkaUtils::terminateActorSystem)).collect(Collectors.toList());
FutureUtils.completeAll(actorSystemFutures).get();
} finally {
ExecutorUtils.gracefulShutdown(10000L, TimeUnit.MILLISECONDS, executorService);
}
}
use of akka.actor.ActorSystem in project flink by apache.
the class SupervisorActorTest method completesTerminationFutureOfSiblingsIfActorFails.
@Test
public void completesTerminationFutureOfSiblingsIfActorFails() throws Exception {
final ActorSystem actorSystem = actorSystemResource.getActorSystem();
final ActorRef supervisor = SupervisorActor.startSupervisorActor(actorSystem, actorSystem.getDispatcher());
final SupervisorActor.ActorRegistration actorRegistration1 = startAkkaRpcActor(supervisor, "foobar1");
final SupervisorActor.ActorRegistration actorRegistration2 = startAkkaRpcActor(supervisor, "foobar2");
final CompletableFuture<Void> terminationFuture = actorRegistration2.getTerminationFuture();
assertThat(terminationFuture.isDone(), is(false));
final FlinkException cause = new FlinkException("Test cause.");
actorRegistration1.getActorRef().tell(Fail.exceptionally(cause), ActorRef.noSender());
try {
terminationFuture.get();
fail("Expected the termination future being completed exceptionally");
} catch (ExecutionException expected) {
}
}
Aggregations