Search in sources :

Example 11 with Props

use of akka.actor.Props in project modules.playframework.org by playframework.

the class AbstractController method createHistoricalEvent.

public static void createHistoricalEvent(String category, String message) {
    HistoricalEvent historicalEvent = new HistoricalEvent();
    historicalEvent.creationDate = new Date();
    historicalEvent.category = category;
    historicalEvent.message = message;
    ActorSystem actorSystem = Akka.system();
    ActorRef actor = actorSystem.actorOf(new Props(HistoricalEventActor.class));
    actor.tell(historicalEvent);
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) HistoricalEvent(models.HistoricalEvent) Props(akka.actor.Props) Date(java.util.Date) HistoricalEventActor(actors.HistoricalEventActor)

Example 12 with Props

use of akka.actor.Props in project flink by apache.

the class AkkaRpcService method startServer.

@Override
public <C extends RpcGateway, S extends RpcEndpoint<C>> C startServer(S rpcEndpoint) {
    checkNotNull(rpcEndpoint, "rpc endpoint");
    CompletableFuture<Void> terminationFuture = new FlinkCompletableFuture<>();
    Props akkaRpcActorProps = Props.create(AkkaRpcActor.class, rpcEndpoint, terminationFuture);
    ActorRef actorRef;
    synchronized (lock) {
        checkState(!stopped, "RpcService is stopped");
        actorRef = actorSystem.actorOf(akkaRpcActorProps);
        actors.add(actorRef);
    }
    LOG.info("Starting RPC endpoint for {} at {} .", rpcEndpoint.getClass().getName(), actorRef.path());
    final String address = AkkaUtils.getAkkaURL(actorSystem, actorRef);
    final String hostname;
    Option<String> host = actorRef.path().address().host();
    if (host.isEmpty()) {
        hostname = "localhost";
    } else {
        hostname = host.get();
    }
    InvocationHandler akkaInvocationHandler = new AkkaInvocationHandler(address, hostname, actorRef, timeout, maximumFramesize, terminationFuture);
    // Rather than using the System ClassLoader directly, we derive the ClassLoader
    // from this class . That works better in cases where Flink runs embedded and all Flink
    // code is loaded dynamically (for example from an OSGI bundle) through a custom ClassLoader
    ClassLoader classLoader = getClass().getClassLoader();
    @SuppressWarnings("unchecked") C self = (C) Proxy.newProxyInstance(classLoader, new Class<?>[] { rpcEndpoint.getSelfGatewayType(), SelfGateway.class, MainThreadExecutable.class, StartStoppable.class, AkkaGateway.class }, akkaInvocationHandler);
    return self;
}
Also used : ActorRef(akka.actor.ActorRef) Props(akka.actor.Props) FlinkCompletableFuture(org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture) InvocationHandler(java.lang.reflect.InvocationHandler) MainThreadExecutable(org.apache.flink.runtime.rpc.MainThreadExecutable) SelfGateway(org.apache.flink.runtime.rpc.SelfGateway) StartStoppable(org.apache.flink.runtime.rpc.StartStoppable)

Example 13 with Props

use of akka.actor.Props in project flink by apache.

the class JobClientActorTest method testRegistrationTimeout.

/** Tests that a {@link JobClientActorRegistrationTimeoutException} is thrown when the registration
	 * cannot be performed at the JobManager by the JobAttachmentClientActor. This is here the case, because the
	 * started JobManager never replies to a {@link RegisterJobClient} message.
	 */
@Test(expected = JobClientActorRegistrationTimeoutException.class)
public void testRegistrationTimeout() throws Exception {
    FiniteDuration jobClientActorTimeout = new FiniteDuration(5, TimeUnit.SECONDS);
    FiniteDuration timeout = jobClientActorTimeout.$times(2);
    UUID leaderSessionID = UUID.randomUUID();
    ActorRef jobManager = system.actorOf(Props.create(PlainActor.class, leaderSessionID));
    TestingLeaderRetrievalService testingLeaderRetrievalService = new TestingLeaderRetrievalService(jobManager.path().toString(), leaderSessionID);
    Props jobClientActorProps = JobAttachmentClientActor.createActorProps(testingLeaderRetrievalService, jobClientActorTimeout, false);
    ActorRef jobClientActor = system.actorOf(jobClientActorProps);
    Future<Object> jobExecutionResult = Patterns.ask(jobClientActor, new JobClientMessages.AttachToJobAndWait(testJobGraph.getJobID()), new Timeout(timeout));
    Await.result(jobExecutionResult, timeout);
}
Also used : AttachToJobAndWait(org.apache.flink.runtime.messages.JobClientMessages.AttachToJobAndWait) TestingLeaderRetrievalService(org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService) ActorRef(akka.actor.ActorRef) JobClientMessages(org.apache.flink.runtime.messages.JobClientMessages) Timeout(akka.util.Timeout) FiniteDuration(scala.concurrent.duration.FiniteDuration) UUID(java.util.UUID) Props(akka.actor.Props) Test(org.junit.Test)

Example 14 with Props

use of akka.actor.Props in project flink by apache.

the class JobClientActorTest method testConnectionTimeoutWithoutJobManagerForRegistration.

/** Tests that a {@link org.apache.flink.runtime.client.JobClientActorConnectionTimeoutException}
	 * is thrown when the JobAttachmentClientActor attach to a job at the JobManager
	 * but has not connected to a JobManager.
	 */
@Test(expected = JobClientActorConnectionTimeoutException.class)
public void testConnectionTimeoutWithoutJobManagerForRegistration() throws Exception {
    FiniteDuration jobClientActorTimeout = new FiniteDuration(5, TimeUnit.SECONDS);
    FiniteDuration timeout = jobClientActorTimeout.$times(2);
    TestingLeaderRetrievalService testingLeaderRetrievalService = new TestingLeaderRetrievalService();
    Props jobClientActorProps = JobAttachmentClientActor.createActorProps(testingLeaderRetrievalService, jobClientActorTimeout, false);
    ActorRef jobClientActor = system.actorOf(jobClientActorProps);
    Future<Object> jobExecutionResult = Patterns.ask(jobClientActor, new JobClientMessages.AttachToJobAndWait(testJobGraph.getJobID()), new Timeout(timeout));
    Await.result(jobExecutionResult, timeout);
}
Also used : AttachToJobAndWait(org.apache.flink.runtime.messages.JobClientMessages.AttachToJobAndWait) TestingLeaderRetrievalService(org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService) ActorRef(akka.actor.ActorRef) JobClientMessages(org.apache.flink.runtime.messages.JobClientMessages) Timeout(akka.util.Timeout) FiniteDuration(scala.concurrent.duration.FiniteDuration) Props(akka.actor.Props) Test(org.junit.Test)

Example 15 with Props

use of akka.actor.Props in project flink by apache.

the class JobClientActorTest method testConnectionTimeoutAfterJobRegistration.

/** Tests that a {@link JobClientActorConnectionTimeoutException}
	 * is thrown after a successful registration of the client at the JobManager.
	 */
@Test(expected = JobClientActorConnectionTimeoutException.class)
public void testConnectionTimeoutAfterJobRegistration() throws Exception {
    FiniteDuration jobClientActorTimeout = new FiniteDuration(5, TimeUnit.SECONDS);
    FiniteDuration timeout = jobClientActorTimeout.$times(2);
    UUID leaderSessionID = UUID.randomUUID();
    ActorRef jobManager = system.actorOf(Props.create(JobAcceptingActor.class, leaderSessionID));
    TestingLeaderRetrievalService testingLeaderRetrievalService = new TestingLeaderRetrievalService(jobManager.path().toString(), leaderSessionID);
    Props jobClientActorProps = JobAttachmentClientActor.createActorProps(testingLeaderRetrievalService, jobClientActorTimeout, false);
    ActorRef jobClientActor = system.actorOf(jobClientActorProps);
    Future<Object> jobExecutionResult = Patterns.ask(jobClientActor, new AttachToJobAndWait(testJobGraph.getJobID()), new Timeout(timeout));
    Future<Object> waitFuture = Patterns.ask(jobManager, new RegisterTest(), new Timeout(timeout));
    Await.result(waitFuture, timeout);
    jobManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
    Await.result(jobExecutionResult, timeout);
}
Also used : TestingLeaderRetrievalService(org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) FiniteDuration(scala.concurrent.duration.FiniteDuration) UUID(java.util.UUID) Props(akka.actor.Props) AttachToJobAndWait(org.apache.flink.runtime.messages.JobClientMessages.AttachToJobAndWait) Test(org.junit.Test)

Aggregations

Props (akka.actor.Props)21 ActorRef (akka.actor.ActorRef)20 Test (org.junit.Test)13 FiniteDuration (scala.concurrent.duration.FiniteDuration)10 Timeout (akka.util.Timeout)8 Configuration (org.apache.flink.configuration.Configuration)8 ActorSystem (akka.actor.ActorSystem)7 UUID (java.util.UUID)7 TestingLeaderRetrievalService (org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService)7 JobClientMessages (org.apache.flink.runtime.messages.JobClientMessages)7 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)4 AttachToJobAndWait (org.apache.flink.runtime.messages.JobClientMessages.AttachToJobAndWait)3 JavaTestKit (akka.testkit.JavaTestKit)2 ExecutorService (java.util.concurrent.ExecutorService)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 BlobLibraryCacheManager (org.apache.flink.runtime.execution.librarycache.BlobLibraryCacheManager)2 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)2 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)2