private void applyRedirectionRule(RedirectionRule body) { context() .system() .scheduler() .scheduleOnce(Duration.create(body.ruleTTL, TimeUnit.MILLISECONDS), self(), new RuleTimeoutMessage(body.getRuleId()), context().dispatcher(), self()); redirectionRules.put(body.getRuleId(), body); }
/** Returns the actors to broadcast trace events to. */ private List<Routee> makeRoutes() { return Registry.policies(settings).stream().map(policy -> { ActorRef actorRef = context().actorOf(Props.create(PolicyActor.class, policy)); context().watch(actorRef); return new ActorRefRoutee(actorRef); }).collect(toList()); }
private void scheduleTimeoutMessage(ActorContext context, TimeoutMessage message, long delay) { context.system() .scheduler() .scheduleOnce( Duration.create(delay, TimeUnit.MILLISECONDS), context.self(), message, context.dispatcher(), context.self()); }
public Simulator() { Config config = context().system().settings().config().getConfig("caffeine.simulator"); settings = new BasicSettings(config); List<Routee> routes = makeRoutes(); router = new Router(new BroadcastRoutingLogic(), routes); remaining = routes.size(); batchSize = settings.batchSize(); stopwatch = Stopwatch.createStarted(); reporter = settings.report().format().create(config); }
private ActorRef getOrCreateTenantActorByTokenId(String tenantId) { ActorRef tenantActor = tenants.get(tenantId); if (tenantActor == null) { tenantActor = context().actorOf( Props.create(new TenantActor.ActorCreator(context, tenantId)) .withDispatcher(CORE_DISPATCHER_NAME), tenantId); tenants.put(tenantId, tenantActor); } return tenantActor; }
private ActorRef getInternalConciergeForwarder(final ActorContext actorContext, final ServiceConfigReader configReader, final ActorRef pubSubMediator) { final ActorRef conciergeShardRegionProxy = ClusterSharding.get(actorContext.system()) .startProxy(ConciergeMessagingConstants.SHARD_REGION, Optional.of(ConciergeMessagingConstants.CLUSTER_ROLE), ShardRegionExtractor.of(configReader.cluster().numberOfShards(), actorContext.system())); return actorContext.actorOf( ConciergeForwarderActor.props(pubSubMediator, conciergeShardRegionProxy), "internal" + ConciergeForwarderActor.ACTOR_NAME); }
@Override public void preStart() { if (expr instanceof Const) { Integer value = ((Const) expr).getValue(); context().parent().tell(new Result(expr, value, myPosition), self()); // Don't forget to stop the actor after it has nothing more to do context().stop(self()); } else { context().actorOf(FlakyExpressionCalculator.props(expr.getLeft(), Left), "left"); context().actorOf(FlakyExpressionCalculator.props(expr.getRight(), Right), "right"); } }
/** Broadcast the trace events to all of the policy actors. */ private void broadcast() { try (LongStream events = eventStream()) { LongArrayList batch = new LongArrayList(batchSize); for (PrimitiveIterator.OfLong i = events.iterator(); i.hasNext();) { batch.add(i.nextLong()); if (batch.size() == batchSize) { router.route(batch, self()); batch = new LongArrayList(batchSize); } } router.route(batch, self()); router.route(FINISH, self()); } catch (Exception e) { context().system().log().error(e, ""); context().stop(self()); } }
/** * Returns the execution context associated with this actor. To be used by futures. In unit tests, should be mocked * by a SimpleExecutionContext. * * @return Execution context. */ @Nonnull public ExecutionContext executionContext() { return context.dispatcher(); }
ActorSelection jobManagerSel = context().actorSelection(leaderAddress); Future<Object> future = Patterns.ask(jobManagerSel, registerMessage, new Timeout(messageTimeout)); }, context().dispatcher());
context().become(waitingForAsyncAction, false); context().system().scheduler().scheduleOnce(Duration.create(asyncTimeout, TimeUnit.SECONDS), self(), new ResumeProcessing(), context().system().dispatchers().lookup(asyncDispatcherName), self()); pipe(executionFlow(getState()).getAsyncOnCommand().get(command.getClass()).apply(command, ctx, getState()) .exceptionMsg(throwable.getLocalizedMessage()) .build()) .build()), context().system().dispatchers().lookup(asyncDispatcherName)) .pipeTo(self(), sender()); } else if (executionFlow(getState()).getOnCommand().get(command.getClass()) != null) { .match(Stop.class, msg -> context().stop(self())) .match(Object.class, this::unhandled)
/** Add the stats to the reporter, print if completed, and stop the simulator. */ private void reportStats(PolicyStats stats) throws IOException { reporter.add(stats); if (--remaining == 0) { reporter.print(); context().stop(self()); System.out.println("Executed in " + stopwatch); } }
/** * Process endpoint registration. * * @param message the message */ private void processEndpointUserRegistration(EndpointUserConnectMessage message) { context().parent().tell(message, self()); }
@Override public ActorSelection actorSelection(String path){ return context.actorSelection(path); }
private void process(LongArrayList events) { try { policy.stats().stopwatch().start(); for (int i = 0; i < events.size(); i++) { policy.record(events.getLong(i)); } } catch (Exception e) { sender().tell(ERROR, self()); context().system().log().error(e, ""); } finally { policy.stats().stopwatch().stop(); } }
/** * Gets the or create application actor. * * @param appToken the app token * @return the or create application actor */ private ActorRef getOrCreateApplicationActor(String appToken) { ActorRef applicationActor = applications.get(appToken); if (applicationActor == null) { applicationActor = context().actorOf( Props.create(new ApplicationActor.ActorCreator(context, tenantId, appToken)) .withDispatcher(CORE_DISPATCHER_NAME), appToken); applications.put(appToken, applicationActor); } return applicationActor; }
private ActorRef getNotifierActor() { if(notifierActor == null) { LOG.debug("Creating actor {}", actorName); String dispatcher = new Dispatchers(actorContext.system().dispatchers()).getDispatcherPath( Dispatchers.DispatcherType.Notification); notifierActor = actorContext.actorOf(ShardDataTreeNotificationPublisherActor.props(actorName) .withDispatcher(dispatcher).withMailbox( org.opendaylight.controller.cluster.datastore.utils.ActorContext.BOUNDED_MAILBOX), actorName); } return notifierActor; } }