@Override public void preStart() { log().info("Starting up..."); // --- basic initializations --- processedAcksAccumulator = new ArrayList<>(); // --- initialize scheduler events --- getContext().system().scheduler().scheduleOnce( Duration.apply(20, TimeUnit.SECONDS) /* Note: this is actually the timeout */, getSelf(), new CheckAllAcks(), getContext().system().dispatcher(), getSelf() ); // --- initialize router --- final List<Routee> routees = new ArrayList<>(childrenToCreate); for (int i = 0; i < childrenToCreate; i++) { ActorRef crimeRecordsProcessorChild = actorSystem.actorOf(springAkkaExtension .props(SpringAkkaExtension.classNameToSpringName(CrimeRecordsProcessor.class)) .withDispatcher("akka.blocking-io-dispatcher")); getContext().watch(crimeRecordsProcessorChild); routees.add(new ActorRefRoutee(crimeRecordsProcessorChild)); } router = new Router(new SmallestMailboxRoutingLogic(), routees); }
public AkkaJobStateInfoActor(Plugin<?> plugin, ActorRef jobCreator, ActorRef jobsManager, String jobId, int numberOfJobsWorkers) { super(); jobInfo = new JobInfo(); this.plugin = plugin; this.jobCreator = jobCreator; this.jobsManager = jobsManager; this.jobId = jobId; LOGGER.debug("Starting AkkaJobStateInfoActor router with {} actors", numberOfJobsWorkers); Props workersProps = new RoundRobinPool(numberOfJobsWorkers).props(Props.create(AkkaWorkerActor.class)); workersRouter = getContext().actorOf(workersProps, "WorkersRouter"); // 20160914 hsilva: watch child events, so when they stop we can react getContext().watch(workersRouter); JobsHelper.createJobWorkingDirectory(jobId); String className = AkkaJobStateInfoActor.class.getSimpleName(); // stateMessagesMetrics = new HashMap<>(); stateMessagesMetricsHistogram = getMetricRegistry() .histogram(MetricRegistry.name(className, "msgCreationToProcessingStartedInMilis")); }
@Override public void preStart() { final Instant now = Instant.now(); final Duration initialDelay = calculateInitialDelay(now, firstIntervalHour); log.info("Initial deletion is scheduled at <{}>", now.plus(initialDelay)); scheduler = getContext().getSystem().scheduler() .schedule(initialDelay, runInterval, getSelf(), PERFORM_DELETION_MESSAGE, getContext().dispatcher(), getSelf()); }
.withDispatcher("akka.blocking-io-dispatcher")); getContext().watch(crimeRecordsProcessorChild);
@Override public Receive createReceive() { return receiveBuilder() .match(TransformationJob.class, job -> backends.isEmpty(), job -> { sender().tell(new JobFailed("Service unavailable, try again later", job), sender()); }) .match(TransformationJob.class, job -> { jobCounter++; backends.get(jobCounter % backends.size()) .forward(job, getContext()); }) .matchEquals(BACKEND_REGISTRATION, message -> { getContext().watch(sender()); backends.add(sender()); }) .match(Terminated.class, terminated -> { backends.remove(terminated.getActor()); }) .build(); } }
private ActorRef createOrGetForwarder() { final Option<ActorRef> refOption = getContext().child(STREAM_FORWARDER_ACTOR_NAME); final ActorRef forwarderRef; if (refOption.isDefined()) { forwarderRef = refOption.get(); } else { forwarderRef = startStreamForwarder(); log.debug("Watching forwarder: {}", forwarderRef); // important: watch the child to get notified when it terminates getContext().watch(forwarderRef); } return forwarderRef; }
private DevOpsCommandsActor(final LoggingFacade loggingFacade, final String serviceName, final String instance) { this.loggingFacade = loggingFacade; this.serviceName = serviceName; this.instance = instance; pubSubMediator = DistributedPubSub.get(getContext().system()).mediator(); serviceMappingStrategy = MappingStrategy.loadMappingStrategy(getContext().getSystem()).determineStrategy(); getContext().actorOf( PubSubSubscriberActor.props(pubSubMediator, serviceName, instance, RetrieveLoggerConfig.TYPE, ChangeLogLevel.TYPE, ExecutePiggybackCommand.TYPE ), "pubSubSubscriber"); }
private ActorRef startChildActor(final String actorName, final Props props) { log.info("Starting child actor '{}'", actorName); return getContext().actorOf(props, actorName); }
private ThingsSearchIndexDeletionActor(final MongoClientWrapper mongoClientWrapper) { final Config config = getContext().getSystem().settings().config(); age = config.getDuration(ConfigKeys.DELETION_AGE); runInterval = config.getDuration(ConfigKeys.DELETION_RUN_INTERVAL); firstIntervalHour = config.getInt(ConfigKeys.DELETION_FIRST_INTERVAL_HOUR); if (firstIntervalHour < 0 || firstIntervalHour > 23) { throw new ConfigurationException( "The configured <" + ConfigKeys.DELETION_FIRST_INTERVAL_HOUR + "> must be" + "between 0 and 23"); } actorMaterializer = ActorMaterializer.create(getContext()); collection = mongoClientWrapper.getDatabase().getCollection(THINGS_COLLECTION_NAME); }
private ActorRef startChildActor(final String actorName, final Props props) { log.info("Starting child actor '{}'", actorName); return getContext().actorOf(props, actorName); }
private ThingsSearchIndexDeletionActor(final MongoClientWrapper mongoClientWrapper) { final Config config = getContext().getSystem().settings().config(); age = config.getDuration(ConfigKeys.DELETION_AGE); runInterval = config.getDuration(ConfigKeys.DELETION_RUN_INTERVAL); firstIntervalHour = config.getInt(ConfigKeys.DELETION_FIRST_INTERVAL_HOUR); if (firstIntervalHour < 0 || firstIntervalHour > 23) { throw new ConfigurationException( "The configured <" + ConfigKeys.DELETION_FIRST_INTERVAL_HOUR + "> must be" + "between 0 and 23"); } actorMaterializer = ActorMaterializer.create(getContext()); collection = mongoClientWrapper.getDatabase().getCollection(THINGS_COLLECTION_NAME); }
private ActorRef startStreamForwarder() { streamForwarderStartedOrStopped(); return getContext().actorOf(getStreamForwarderProps(), STREAM_FORWARDER_ACTOR_NAME); }
private Receive hasNextBehavior(final ActorRef elementSender) { return ReceiveBuilder.create() .matchEquals(STREAM_ACK_MSG, unit -> updateLastMessageReceived()) .matchEquals(DOES_NOT_HAVE_NEXT_MSG, unit -> { updateLastMessageReceived(); getContext().become(iteratingBehavior()); log.debug("sending ack {} to streaming actor {}", STREAM_ACK_MSG, elementSender); elementSender.tell(STREAM_ACK_MSG, getSelf()); }) .matchEquals(STREAM_FAILED, this::streamFailed) .match(CheckForActivity.class, this::checkForActivity) .build(); }
private void becomeAwaitingSyncPolicyResponse(final Thing syncedThing) { log.debug("Becoming 'awaitingSyncPolicyResponse' for policy <{}> ...", policyId); getContext().become(createAwaitSyncPolicyBehavior(syncSessionId, syncedThing)); }
private ActorRef startChildActor(final String actorName, final Props props) { log.info("Starting child actor '{}'", actorName); return getContext().actorOf(props, actorName); }
private void becomeSupervising() { log.debug("becoming supervising..."); getContext().become(createSupervisingBehavior()); }
private ActorRef createOrGetForwarder() { final Option<ActorRef> refOption = getContext().child(STREAM_FORWARDER_ACTOR_NAME); final ActorRef forwarderRef; if (refOption.isDefined()) { forwarderRef = refOption.get(); } else { forwarderRef = startStreamForwarder(); log.debug("Watching forwarder: {}", forwarderRef); // important: watch the child to get notified when it terminates getContext().watch(forwarderRef); } return forwarderRef; }
private void handleJobStop(Object msg) { Messages.JobStop message = (Messages.JobStop) msg; markMessageProcessingAsStarted(message); getSelf().tell(Messages.newJobStateUpdated(plugin, JOB_STATE.STOPPING), getSelf()); stopping = true; getContext().getChildren().forEach(e -> getContext().stop(e)); markMessageProcessingAsEnded(message); }
public Terminator(ActorRef ref) { this.ref = ref; getContext().watch(ref); }
/** * Indicates whether the logging of incoming messages is enabled by config or not. * * @return {@code true} if information about incoming messages should be logged, {@code false} else. */ private boolean isLogIncomingMessages() { final ActorSystem actorSystem = getContext().getSystem(); final Config config = actorSystem.settings().config(); return config.hasPath(ConfigKeys.THINGS_LOG_INCOMING_MESSAGES) && config.getBoolean(ConfigKeys.THINGS_LOG_INCOMING_MESSAGES); }