Search in sources :

Example 86 with ActorSystem

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());
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) HelloActor(cn.vobile.akka.actor.HelloActor)

Example 87 with ActorSystem

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());
}
Also used : ActorSystem(akka.actor.ActorSystem) BeforeClass(org.junit.BeforeClass)

Example 88 with ActorSystem

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();
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) Configuration(org.apache.flink.configuration.Configuration) ActorRef(akka.actor.ActorRef) Terminated(akka.actor.Terminated) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 89 with ActorSystem

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);
    }
}
Also used : IntStream(java.util.stream.IntStream) CyclicBarrier(java.util.concurrent.CyclicBarrier) Logger(org.slf4j.Logger) Configuration(org.apache.flink.configuration.Configuration) LoggerFactory(org.slf4j.LoggerFactory) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) BindException(java.net.BindException) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ActorSystem(akka.actor.ActorSystem) TestLogger(org.apache.flink.util.TestLogger) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) CheckedSupplier(org.apache.flink.util.function.CheckedSupplier) ExecutorService(java.util.concurrent.ExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) Configuration(org.apache.flink.configuration.Configuration) ExecutorService(java.util.concurrent.ExecutorService) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 90 with ActorSystem

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) {
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Aggregations

ActorSystem (akka.actor.ActorSystem)91 ActorRef (akka.actor.ActorRef)54 Test (org.junit.Test)51 Configuration (org.apache.flink.configuration.Configuration)27 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 File (java.io.File)11 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)11 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)11 Props (akka.actor.Props)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 TestActorRef (akka.testkit.TestActorRef)8 IOException (java.io.IOException)8 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Deadline (scala.concurrent.duration.Deadline)8 AddressFromURIString (akka.actor.AddressFromURIString)7 ActorMaterializer (akka.stream.ActorMaterializer)7 Materializer (akka.stream.Materializer)7 Sink (akka.stream.javadsl.Sink)7 Source (akka.stream.javadsl.Source)7