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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations