private CompletionStage<Status.Status> testMessageMappingProcessor(@Nullable final MappingContext mappingContext) { try { // this one throws DittoRuntimeExceptions when the mapper could not be configured MessageMappingProcessor.of(connectionId(), mappingContext, getContext().getSystem(), log); return CompletableFuture.completedFuture(new Status.Success("mapping")); } catch (final DittoRuntimeException dre) { log.info("Got DittoRuntimeException during initialization of MessageMappingProcessor: {} {} - desc: {}", dre.getClass().getSimpleName(), dre.getMessage(), dre.getDescription().orElse("")); getSender().tell(dre, getSelf()); return CompletableFuture.completedFuture(new Status.Failure(dre)); } }
/** * 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); }
private CompletionStage<Status.Status> testMessageMappingProcessor(@Nullable final MappingContext mappingContext) { try { // this one throws DittoRuntimeExceptions when the mapper could not be configured MessageMappingProcessor.of(connectionId(), mappingContext, getContext().getSystem(), log); return CompletableFuture.completedFuture(new Status.Success("mapping")); } catch (final DittoRuntimeException dre) { log.info("Got DittoRuntimeException during initialization of MessageMappingProcessor: {} {} - desc: {}", dre.getClass().getSimpleName(), dre.getMessage(), dre.getDescription().orElse("")); getSender().tell(dre, getSelf()); return CompletableFuture.completedFuture(new Status.Failure(dre)); } }
private void bindHttpStatusRoute(final ActorRef healthCheckingActor, final HttpConfigReader httpConfig, final ActorMaterializer materializer) { String hostname = httpConfig.getHostname(); if (hostname.isEmpty()) { hostname = ConfigUtil.getLocalHostAddress(); log.info("No explicit hostname configured, using HTTP hostname: {}", hostname); } final CompletionStage<ServerBinding> binding = Http.get(getContext().system()) .bindAndHandle(createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(), materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer); binding.thenAccept(theBinding -> CoordinatedShutdown.get(getContext().getSystem()).addTask( CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> { log.info("Gracefully shutting down status/health HTTP endpoint.."); return theBinding.terminate(Duration.ofSeconds(1)) .handle((httpTerminated, e) -> Done.getInstance()); }) ).exceptionally(failure -> { log.error(failure, "Something very bad happened: {}", failure.getMessage()); getContext().system().terminate(); return null; }); }
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 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); }
/** * 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); }
private ReconnectActor(final ActorRef connectionShardRegion, final Supplier<Source<String, NotUsed>> currentPersistenceIdsSourceSupplier) { this.connectionShardRegion = connectionShardRegion; this.currentPersistenceIdsSourceSupplier = currentPersistenceIdsSourceSupplier; final Config config = getContext().system().settings().config(); materializer = ActorMaterializer.create(getContext().getSystem()); reconnectInitialDelay = config.getDuration(ConfigKeys.Reconnect.RECONNECT_INITIAL_DELAY); reconnectInterval = config.getDuration(ConfigKeys.Reconnect.RECONNECT_INTERVAL); reconnectRateFrequency = config.getDuration(ConfigKeys.Reconnect.RECONNECT_RATE_FREQUENCY); reconnectRateEntities = config.getInt(ConfigKeys.Reconnect.RECONNECT_RATE_ENTITIES); }
private Cancellable scheduleActivityCheck(final StreamConsumerSettings streamConsumerSettings) { final FiniteDuration initialDelay = fromDuration(streamConsumerSettings.getOutdatedWarningOffset()); final FiniteDuration interval = fromDuration(streamConsumerSettings.getStreamInterval()); final CheckForActivity message = CheckForActivity.INSTANCE; return getContext().getSystem() .scheduler() .schedule(initialDelay, interval, getSelf(), message, getContext().dispatcher(), ActorRef.noSender()); }
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 Cancellable scheduleReconnect() { final FiniteDuration initialDelay = FiniteDuration.apply(reconnectInitialDelay.toMillis(), TimeUnit.MILLISECONDS); final FiniteDuration interval = FiniteDuration.apply(reconnectInterval.toMillis(), TimeUnit.MILLISECONDS); final ReconnectMessages message = ReconnectMessages.START_RECONNECT; log.info("Scheduling reconnect for all connections with initial delay {} and interval {}.", reconnectInitialDelay, reconnectInterval); return getContext().getSystem() .scheduler() .schedule(initialDelay, interval, getSelf(), message, getContext().dispatcher(), ActorRef.noSender()); }
private ReconnectActor(final ActorRef connectionShardRegion, final Supplier<Source<String, NotUsed>> currentPersistenceIdsSourceSupplier) { this.connectionShardRegion = connectionShardRegion; this.currentPersistenceIdsSourceSupplier = currentPersistenceIdsSourceSupplier; final Config config = getContext().system().settings().config(); materializer = ActorMaterializer.create(getContext().getSystem()); reconnectInitialDelay = config.getDuration(ConfigKeys.Reconnect.RECONNECT_INITIAL_DELAY); reconnectInterval = config.getDuration(ConfigKeys.Reconnect.RECONNECT_INTERVAL); reconnectRateFrequency = config.getDuration(ConfigKeys.Reconnect.RECONNECT_RATE_FREQUENCY); reconnectRateEntities = config.getInt(ConfigKeys.Reconnect.RECONNECT_RATE_ENTITIES); }
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); }
@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()); }
private Cancellable scheduleReconnect() { final FiniteDuration initialDelay = FiniteDuration.apply(reconnectInitialDelay.toMillis(), TimeUnit.MILLISECONDS); final FiniteDuration interval = FiniteDuration.apply(reconnectInterval.toMillis(), TimeUnit.MILLISECONDS); final ReconnectMessages message = ReconnectMessages.START_RECONNECT; log.info("Scheduling reconnect for all connections with initial delay {} and interval {}.", reconnectInitialDelay, reconnectInterval); return getContext().getSystem() .scheduler() .schedule(initialDelay, interval, getSelf(), message, getContext().dispatcher(), ActorRef.noSender()); }
private void scheduleInternalRetrieveHotEntities() { initHotMetrics(); getContext().getSystem() .scheduler() .schedule(FiniteDuration.apply(WAIT_TIME_MS, TimeUnit.MILLISECONDS), FiniteDuration.apply(SCHEDULE_INTERNAL_RETRIEVE_COMMAND, TimeUnit.MILLISECONDS), getSelf(), InternalRetrieveStatistics.newInstance(), getContext().getSystem().dispatcher(), ActorRef.noSender()); }
private StatisticsActor(final ActorRef pubSubMediator) { this.pubSubMediator = pubSubMediator; hotThings = DittoMetrics.gauge(Statistics.HOT_THINGS); hotPolicies = DittoMetrics.gauge(Statistics.HOT_POLICIES); hotConciergeEnforcers = DittoMetrics.gauge(Statistics.HOT_CONCIERGE_ENFORCERS); hotSearchUpdaters = DittoMetrics.gauge(Statistics.HOT_SEARCH_UPDATERS); clusterSharding = ClusterSharding.get(getContext().getSystem()); scheduleInternalRetrieveHotEntities(); }
private Cancellable scheduleActivityCheck(final StreamConsumerSettings streamConsumerSettings) { final FiniteDuration initialDelay = fromDuration(streamConsumerSettings.getOutdatedWarningOffset()); final FiniteDuration interval = fromDuration(streamConsumerSettings.getStreamInterval()); final CheckForActivity message = CheckForActivity.INSTANCE; return getContext().getSystem() .scheduler() .schedule(initialDelay, interval, getSelf(), message, getContext().dispatcher(), ActorRef.noSender()); }
private void scheduleShutdown() { shutdownCancellable = getContext().getSystem().scheduler() .scheduleOnce(SHUTDOWN_DELAY, getSelf(), Shutdown.getInstance(), getContext().dispatcher(), ActorRef.noSender()); }
@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()); }