private Status sendMessageToLocalRouters( QakkaMessage message ) { int maxRetries = 5; int retries = 0; while ( retries++ < maxRetries ) { try { Timeout t = new Timeout( 1, TimeUnit.SECONDS ); // ask ClientActor and wait (up to timeout) for response Future<Object> fut = Patterns.ask( actorSystemManager.getClientActor(), message, t ); final QakkaMessage response = (QakkaMessage)Await.result( fut, t.duration() ); if ( response != null && response instanceof QueueAckResponse) { QueueAckResponse qprm = (QueueAckResponse)response; return qprm.getStatus(); } else if ( response != null ) { logger.debug("UNKNOWN RESPONSE sending message, retrying {}", retries ); } else { logger.trace("TIMEOUT sending message, retrying {}", retries ); } } catch ( TimeoutException e ) { logger.trace( "TIMEOUT sending message, retrying " + retries, e ); } catch ( Exception e ) { logger.debug("ERROR sending message, retrying " + retries, e ); } } throw new QakkaRuntimeException( "Error sending message " + message + "after " + retries ); }
LOG.debug("keytabPath: {}", keytabPath); config.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, keytabPath); config.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, remoteKeytabPrincipal); final String amPortRange = config.getString( YarnConfigOptions.APPLICATION_MASTER_PORT); LOG); ActorRef resourceMaster = actorSystem.actorOf(resourceMasterProps); actorSystem.actorOf( Props.create(ProcessReaper.class, resourceMaster, LOG, ACTOR_DIED_EXIT_CODE), "YARN_Resource_Master_Process_Reaper"); actorSystem.actorOf( Props.create(ProcessReaper.class, jobManager, LOG, ACTOR_DIED_EXIT_CODE), "JobManager_Process_Reaper"); Await.ready(actorSystem.whenTerminated(), Duration.Inf()); } catch (InterruptedException | TimeoutException e) { LOG.error("Error shutting down actor system", e); AkkaUtils.getTimeout(config).toMillis(), TimeUnit.MILLISECONDS, futureExecutor,
new JavaTestKit(system) {{ final Deadline deadline = new FiniteDuration(3, TimeUnit.MINUTES).fromNow(); Configuration flinkConfig = new Configuration(); YarnConfiguration yarnConfig = new YarnConfiguration(); SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService( leader1 = system.actorOf( Props.create( TestingUtils.ForwardingActor.class, )); resourceManager = system.actorOf( Props.create( TestingYarnFlinkResourceManager.class, Await.ready(taskManagerRegisteredFuture, deadline.timeLeft()); int numberOfRegisteredResources = (Integer) Await.result(numberOfRegisteredResourcesFuture, deadline.timeLeft());
zkServer.getConnectString(), rootFolder.getPath()); configuration.setString(HighAvailabilityOptions.HA_CLUSTER_ID, UUID.randomUUID().toString()); configuration.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, numJMs); configuration.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, numTMs); configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, numSlotsPerTM); configuration.setString(AkkaOptions.ASK_TIMEOUT, AkkaUtils.INF_TIMEOUT().toString()); receiver.setSlotSharingGroup(slotSharingGroup); final JobGraph graph = new JobGraph("Blocking test job", sender, receiver); cluster.start(); clientActorSystem = cluster.startJobClientActorSystem(graph.getJobID()); Deadline deadline = timeout.$times(3).fromNow(); Future<Object> future = jm.ask(new WaitForAllVerticesToBeRunningOrFinished(graph.getJobID()), deadline.timeLeft()); Await.ready(future, deadline.timeLeft()); Await.result(jobSubmission.resultPromise.future(), deadline.timeLeft());
public static void main(String[] args) throws Exception { ActorSystem system = ActorSystem.create("calculator-system"); ActorRef calculatorService = system.actorOf(Props.create(ArithmeticService.class), "arithmetic-service"); // (3 + 5) / (2 * (1 + 1)) Expression task = new Divide( new Add(new Const(3), new Const(5)), new Multiply( new Const(2), new Add(new Const(1), new Const(1)) ) ); FiniteDuration duration = Duration.create(1, TimeUnit.SECONDS); Integer result = Await.result(ask(calculatorService, task, new Timeout(duration)).mapTo(classTag(Integer.class)), duration); System.out.println("Got result: " + result); Await.ready(system.terminate(), Duration.Inf()); } }
Configuration config = new Configuration(); config.setInteger(CheckpointingOptions.MAX_RETAINED_CHECKPOINTS, retainedCheckpoints); config.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, numJMs); config.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, numTMs); config.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, numSlots); system.terminate(); Await.ready(system.whenTerminated(), Duration.Inf());
FiniteDuration askTimeout; Duration lookupDuration = FiniteDuration.create(lookupTimeoutStr); Duration duration = FiniteDuration.create(queryTimeoutStr); askTimeout = queryTimeout.mul(queryAttempts); ActorSystem actorSystem = ActorSystem.create("AkkaStateQuery", AkkaUtils.getDefaultAkkaConfig("", 0)); ActorRef queryActor = actorSystem.actorOf( Props.create( QueryActor.class, Future<Object> futureResult = Patterns.ask( queryActor, new QueryState<>(time, campaigns.get(campaignId++)), new Timeout(askTimeout)); Object result = Await.result(futureResult, askTimeout); Future<Object> futureResult = Patterns.ask( queryActor, new QueryState<>(timestamp, key), new Timeout(askTimeout)); Object result = Await.result(futureResult, askTimeout);
public static void main(String[] args) throws Exception { ActorSystem system = ActorSystem.create("strategy", ConfigFactory.load("akka.config")); ActorRef printActor = system.actorOf(Props.create(PrintActor.class), "PrintActor"); ActorRef workerActor = system.actorOf(Props.create(WorkerActor.class), "WorkerActor"); // 等待 Future 返回 Future<Object> future = Patterns.ask(workerActor, 5, 1000); int result = (int) Await.result(future, Duration.create(3, TimeUnit.SECONDS)); System.out.println("result:" + result); // 不等待返回值,直接重定向到其他 actor,有返回值来的时候将会重定向到 printActor Future<Object> future1 = Patterns.ask(workerActor, 8, 1000); Patterns.pipe(future1, system.dispatcher()).to(printActor); workerActor.tell(PoisonPill.getInstance(), ActorRef.noSender()); } }
.collect(Collectors.joining(", ")); Config config = ConfigFactory.parseString(configText); ActorSystem system = ActorSystem.create(AkkaActorRingBenchmark.class.getSimpleName() + "System", config); Props actorProps = Props.create(InternalActor.class, workerIndex, promise); String actorName = "AkkaActor-" + workerIndex; actors[workerIndex] = system.actorOf( actorProps, actorName); Iterable<Integer> sequences = Await.result( Futures.sequence(futures, system.dispatcher()), Duration.apply(10, TimeUnit.MINUTES));
+ PcDateUtils.getNowDateTimeStr()); executionManager = ActorConfig.createAndGetActorSystem().actorOf( Props.create(ExecutionManager.class, task), "ExecutionManager-" + task.getTaskId()); Future<Object> future = Patterns.ask(executionManager, new InitialRequestToManager(task), new Timeout(duration)); commandResponseFromManager = (ResponseFromManager) Await.result( future, duration); ActorConfig.createAndGetActorSystem().stop(executionManager);
private static Object blockedResponse(ActorRef actorRef, long delayIntervalMillis) throws Exception { Timeout callTimeout = Timeout.durationToTimeout(FiniteDuration.create(delayIntervalMillis, TimeUnit.MILLISECONDS)); Future<Object> futureResult = ask(actorRef, GET_RESPONSE, callTimeout); FiniteDuration duration = FiniteDuration.create(delayIntervalMillis, TimeUnit.MILLISECONDS); return Await.result(futureResult, duration); } }
@Override public void run(String[] args) throws Exception { try { ActorRef workerActor = actorSystem.actorOf(springExtension.props("workerActor"), "worker-actor"); workerActor.tell(new WorkerActor.Request(), null); workerActor.tell(new WorkerActor.Request(), null); workerActor.tell(new WorkerActor.Request(), null); FiniteDuration duration = FiniteDuration.create(1, TimeUnit.SECONDS); Future<Object> awaitable = Patterns.ask(workerActor, new WorkerActor.Response(), Timeout.durationToTimeout(duration)); logger.info("Response: " + Await.result(awaitable, duration)); } finally { actorSystem.terminate(); Await.result(actorSystem.whenTerminated(), Duration.Inf()); } } }
Await.ready(jobSubmissionFuture, askTimeout); } catch (InterruptedException e) { throw new JobExecutionException( } catch (TimeoutException e) { try { Await.result( Patterns.ask( jobClientActor, Timeout.durationToTimeout(askTimeout)), askTimeout); try { answer = Await.result(jobSubmissionFuture, Duration.Zero());
zkServer.getConnectString(), rootFolder.getPath()); configuration.setString(HighAvailabilityOptions.HA_CLUSTER_ID, UUID.randomUUID().toString()); configuration.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, numJMs); configuration.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, numTMs); timeout); int numRegisteredTMs = (Integer) Await.result(registeredTMs, timeout);
@Override public void shutdown() { LOGGER.info("Going to shutdown JOBS actor system"); Future<Terminated> terminate = jobsSystem.terminate(); terminate.onComplete(new OnComplete<Terminated>() { @Override public void onComplete(Throwable failure, Terminated result) { if (failure != null) { LOGGER.error("Error while shutting down JOBS actor system", failure); } else { LOGGER.info("Done shutting down JOBS actor system"); } } }, jobsSystem.dispatcher()); try { LOGGER.info("Waiting up to 30 seconds for JOBS actor system to shutdown"); Await.result(jobsSystem.whenTerminated(), Duration.create(30, "seconds")); } catch (TimeoutException e) { LOGGER.warn("JOBS Actor system shutdown wait timed out, continuing..."); } catch (Exception e) { LOGGER.error("Error while shutting down JOBS actor system", e); } }
0); port = configuration.getInteger(JobManagerOptions.PORT); TaskManager.class); Future<Object> registrationFuture = Patterns.ask( taskManager, TaskManagerMessages.getNotifyWhenRegisteredAtJobManagerMessage(), timeout.toMillis()); Await.ready(registrationFuture, timeout);
@Override public void close() throws Exception { if (isLoaded()) { actorSystem.terminate(); Await.ready(actorSystem.whenTerminated(), Duration.Inf()); actorSystem = null; } }