@Inject public MetricsServiceImpl(CircuitBreakerMetricsProvider metricsProvider, ActorSystem system) { // TODO it would be better to do this in ServiceGuiceSupport.bindService, // but I'm not sure how to access config from there boolean statusEnabled = system.settings().config().getBoolean("lagom.status-endpoint.enabled"); if (statusEnabled && metricsProvider instanceof CircuitBreakerMetricsProviderImpl) provider = Optional.of((CircuitBreakerMetricsProviderImpl) metricsProvider); else provider = Optional.empty(); }
this.snapshotAdapter = snapshotAdapter; final Config config = getContext().system().settings().config(); activityCheckInterval = config.getDuration(ConfigKeys.Policy.ACTIVITY_CHECK_INTERVAL); activityCheckDeletedInterval = config.getDuration(ConfigKeys.Policy.ACTIVITY_CHECK_DELETED_INTERVAL);
this.snapshotAdapter = snapshotAdapter; final Config config = getContext().system().settings().config(); activityCheckInterval = config.getDuration(ConfigKeys.Policy.ACTIVITY_CHECK_INTERVAL); activityCheckDeletedInterval = config.getDuration(ConfigKeys.Policy.ACTIVITY_CHECK_DELETED_INTERVAL);
this.httpResponseFuture = httpResponseFuture; final Config config = getContext().system().settings().config(); serverRequestTimeout = config.getDuration(ConfigKeys.AKKA_HTTP_SERVER_REQUEST_TIMEOUT); getContext().setReceiveTimeout(serverRequestTimeout);
final Config config = actorSystem.settings().config();
return extractActorSystem(actorSystem -> extractRequestContext( requestContext -> enhanceLogWithCorrelationId(correlationId, () -> { final Config config = actorSystem.settings().config();
private ConnectionActor(final String connectionId, final ActorRef pubSubMediator, final ActorRef conciergeForwarder, final ClientActorPropsFactory propsFactory, @Nullable final Consumer<ConnectivityCommand<?>> customCommandValidator) { this.connectionId = connectionId; this.pubSubMediator = pubSubMediator; this.conciergeForwarder = conciergeForwarder; this.propsFactory = propsFactory; final DittoConnectivityCommandValidator dittoCommandValidator = new DittoConnectivityCommandValidator(propsFactory, conciergeForwarder, CONNECTION_VALIDATOR); if (customCommandValidator != null) { this.commandValidator = new CompoundConnectivityCommandInterceptor(dittoCommandValidator, customCommandValidator); } else { this.commandValidator = dittoCommandValidator; } final ConnectionConfigReader configReader = ConnectionConfigReader.fromRawConfig(getContext().system().settings().config()); snapshotThreshold = configReader.snapshotThreshold(); snapshotAdapter = new ConnectionMongoSnapshotAdapter(); connectionCreatedBehaviour = createConnectionCreatedBehaviour(); final java.time.Duration javaFlushTimeout = configReader.flushPendingResponsesTimeout(); flushPendingResponsesTimeout = Duration.create(javaFlushTimeout.toMillis(), TimeUnit.MILLISECONDS); clientActorAskTimeout = configReader.clientActorAskTimeout(); LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); }
final Config config = actorSystem.settings().config();
/** * Authenticates with the Basic Authentication. * * @param realm the realm to apply * @param inner the inner route, which will be performed on successful authentication * @return the inner route wrapped with authentication */ public static Route authenticateDevopsBasic(final String realm, final Route inner) { return Directives.extractActorSystem(actorSystem -> { final Config config = actorSystem.settings().config(); if (REALM_DEVOPS.equals(realm)) { final boolean devopsSecureStatus = config.getBoolean(ConfigKeys.DEVOPS_SECURE_STATUS); if (!devopsSecureStatus) { LOGGER.warn("DevOps resource is not secured by BasicAuth"); return inner; } final String devOpsPassword = config.getString(ConfigKeys.SECRETS_DEVOPS_PASSWORD); LOGGER.debug("Devops authentication is enabled."); return Directives.authenticateBasic(REALM_DEVOPS, new Authenticator(USER_DEVOPS, devOpsPassword), userName -> inner); } else { LOGGER.warn("Did not know realm '{}'. NOT letting the inner Route pass ..", realm); return Directives.complete(StatusCodes.UNAUTHORIZED); } }); }
final Config config = actorSystem.settings().config();
this.actorSystem = actorSystem; final Config config = actorSystem.settings().config(); final ProtocolConfigReader protocolConfig = ProtocolConfigReader.fromRawConfig(config); final ProtocolAdapterProvider protocolAdapterProvider =
private ConnectionActor(final String connectionId, final ActorRef pubSubMediator, final ActorRef conciergeForwarder, final ClientActorPropsFactory propsFactory, @Nullable final Consumer<ConnectivityCommand<?>> customCommandValidator) { this.connectionId = connectionId; this.pubSubMediator = pubSubMediator; this.conciergeForwarder = conciergeForwarder; this.propsFactory = propsFactory; final DittoConnectivityCommandValidator dittoCommandValidator = new DittoConnectivityCommandValidator(propsFactory, conciergeForwarder, CONNECTION_VALIDATOR); if (customCommandValidator != null) { this.commandValidator = new CompoundConnectivityCommandInterceptor(dittoCommandValidator, customCommandValidator); } else { this.commandValidator = dittoCommandValidator; } final ConnectionConfigReader configReader = ConnectionConfigReader.fromRawConfig(getContext().system().settings().config()); snapshotThreshold = configReader.snapshotThreshold(); snapshotAdapter = new ConnectionMongoSnapshotAdapter(); connectionCreatedBehaviour = createConnectionCreatedBehaviour(); final java.time.Duration javaFlushTimeout = configReader.flushPendingResponsesTimeout(); flushPendingResponsesTimeout = Duration.create(javaFlushTimeout.toMillis(), TimeUnit.MILLISECONDS); }
/** * Actor system singleton for this application. */ @Bean public ActorSystem actorSystem() { // load the Akka configuration String seedNodes = "["; for (String seed : clusterConfig.getSeedNodes()) { seedNodes += "\"akka.tcp://" + clusterConfig.getName() + "@" + seed.trim() + "\","; } seedNodes += "]"; final Config applicationConf = ConfigFactory.load(); final Config config = ConfigFactory.parseString("akka.cluster.seed-nodes=" + seedNodes). withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.bind-port=" + clusterConfig.getLocalPort())). withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + clusterConfig.getNodeHost())). withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.port=" + clusterConfig.getLocalPort())). withFallback(ConfigFactory.parseString("akka.cluster.roles=[core]")). withFallback(ConfigFactory.load(applicationConf)); ActorSystem system = ActorSystem.create(clusterConfig.getName(), config); LoggingAdapter log = Logging.getLogger(system, this); log.info("Using Akka system settings: " + system.settings().toString()); // initialize the application context in the Akka Spring Extension SpringExtension.SpringExtProvider.get(system).initialize(applicationContext); return system; }
/** * Enables CORS - Cross-Origin Resource Sharing - for the wrapped {@code inner} Route. * * @param inner the inner route to be wrapped with the CORS enabling * @return the new route wrapping {@code inner} with the CORS enabling */ public static Route enableCors(final Supplier<Route> inner) { return extractActorSystem(actorSystem -> { final boolean enableCors = actorSystem.settings().config().getBoolean(ConfigKeys.ENABLE_CORS); if (enableCors) { return Directives.optionalHeaderValueByType(AccessControlRequestHeaders.class, corsRequestHeaders -> { final ArrayList<HttpHeader> newHeaders = new ArrayList<>(CORS_HEADERS); corsRequestHeaders.ifPresent(toAdd -> newHeaders.add(AccessControlAllowHeaders.create( StreamSupport.stream(toAdd.getHeaders().spliterator(), false) .toArray(String[]::new)) ) ); return route( options(() -> complete(HttpResponse.create().withStatus(StatusCodes.OK).addHeaders(newHeaders)) ), respondWithHeaders(newHeaders, inner) ); }); } else { return inner.get(); } }); }
protected BaseClientActor(final Connection connection, final ConnectionStatus desiredConnectionStatus, final ActorRef conciergeForwarder) { checkNotNull(connection, "connection"); final Config config = getContext().getSystem().settings().config(); final java.time.Duration javaInitTimeout = config.getDuration(ConfigKeys.Client.INIT_TIMEOUT); this.conciergeForwarder = conciergeForwarder; final BaseClientData startingData = new BaseClientData(connection.getId(), connection, ConnectionStatus.UNKNOWN, desiredConnectionStatus, "initialized", Instant.now(), null, null); final FiniteDuration initTimeout = Duration.create(javaInitTimeout.toMillis(), TimeUnit.MILLISECONDS); final FiniteDuration connectingTimeout = Duration.create(CONNECTING_TIMEOUT, TimeUnit.SECONDS); startWith(UNKNOWN, startingData, initTimeout); // stable states when(UNKNOWN, inUnknownState()); when(CONNECTED, inConnectedState()); when(DISCONNECTED, inDisconnectedState()); // volatile states that time out when(CONNECTING, connectingTimeout, inConnectingState()); when(DISCONNECTING, connectingTimeout, inDisconnectingState()); when(TESTING, connectingTimeout, inTestingState()); onTransition(this::onTransition); whenUnhandled(inAnyState().anyEvent(this::onUnknownEvent)); initialize(); }
/** * Initializes a new command processor with mappers defined in mapping mappingContext. The dynamic access is needed * to instantiate message mappers for an actor system * * @param mappingContext the mapping Context * @param actorSystem the dynamic access used for message mapper instantiation * @param log the log adapter * @return the processor instance * @throws org.eclipse.ditto.model.connectivity.MessageMapperConfigurationInvalidException if the configuration of * one of the {@code mappingContext} is invalid * @throws org.eclipse.ditto.model.connectivity.MessageMapperConfigurationFailedException if the configuration of * one of the {@code mappingContext} failed for a mapper specific reason */ public static MessageMappingProcessor of(final String connectionId, @Nullable final MappingContext mappingContext, final ActorSystem actorSystem, final DiagnosticLoggingAdapter log) { final MessageMapperRegistry registry = DefaultMessageMapperFactory.of(actorSystem, MessageMappers.class, log) .registryOf(DittoMessageMapper.CONTEXT, mappingContext); final ProtocolConfigReader protocolConfigReader = ProtocolConfigReader.fromRawConfig(actorSystem.settings().config()); final ProtocolAdapter protocolAdapter = protocolConfigReader.loadProtocolAdapterProvider(actorSystem).getProtocolAdapter(null); return new MessageMappingProcessor(connectionId, registry, log, protocolAdapter); }
protected BaseClientActor(final Connection connection, final ConnectionStatus desiredConnectionStatus, final ActorRef conciergeForwarder) { checkNotNull(connection, "connection"); final Config config = getContext().getSystem().settings().config(); final java.time.Duration javaInitTimeout = config.getDuration(ConfigKeys.Client.INIT_TIMEOUT); this.conciergeForwarder = conciergeForwarder; final BaseClientData startingData = new BaseClientData(connection.getId(), connection, ConnectionStatus.UNKNOWN, desiredConnectionStatus, "initialized", Instant.now(), null, null); final FiniteDuration initTimeout = Duration.create(javaInitTimeout.toMillis(), TimeUnit.MILLISECONDS); final FiniteDuration connectingTimeout = Duration.create(CONNECTING_TIMEOUT, TimeUnit.SECONDS); startWith(UNKNOWN, startingData, initTimeout); // stable states when(UNKNOWN, inUnknownState()); when(CONNECTED, inConnectedState()); when(DISCONNECTED, inDisconnectedState()); // volatile states that time out when(CONNECTING, connectingTimeout, inConnectingState()); when(DISCONNECTING, connectingTimeout, inDisconnectingState()); when(TESTING, connectingTimeout, inTestingState()); onTransition(this::onTransition); whenUnhandled(inAnyState().anyEvent(this::onUnknownEvent)); initialize(); }
/** * Initializes a new command processor with mappers defined in mapping mappingContext. The dynamic access is needed * to instantiate message mappers for an actor system * * @param mappingContext the mapping Context * @param actorSystem the dynamic access used for message mapper instantiation * @param log the log adapter * @return the processor instance * @throws org.eclipse.ditto.model.connectivity.MessageMapperConfigurationInvalidException if the configuration of * one of the {@code mappingContext} is invalid * @throws org.eclipse.ditto.model.connectivity.MessageMapperConfigurationFailedException if the configuration of * one of the {@code mappingContext} failed for a mapper specific reason */ public static MessageMappingProcessor of(final String connectionId, @Nullable final MappingContext mappingContext, final ActorSystem actorSystem, final DiagnosticLoggingAdapter log) { final MessageMapperRegistry registry = DefaultMessageMapperFactory.of(actorSystem, MessageMappers.class, log) .registryOf(DittoMessageMapper.CONTEXT, mappingContext); final ProtocolConfigReader protocolConfigReader = ProtocolConfigReader.fromRawConfig(actorSystem.settings().config()); final ProtocolAdapter protocolAdapter = protocolConfigReader.loadProtocolAdapterProvider(actorSystem).getProtocolAdapter(null); return new MessageMappingProcessor(connectionId, registry, log, protocolAdapter); }
ThingPersistenceActor(final String thingId, final ActorRef pubSubMediator, final ThingSnapshotter.Create thingSnapshotterCreate) { this.thingId = thingId; this.pubSubMediator = pubSubMediator; log = LogUtil.obtain(this); thing = null; final Config config = getContext().system().settings().config(); activityCheckInterval = config.getDuration(ConfigKeys.Thing.ACTIVITY_CHECK_INTERVAL); activityCheckDeletedInterval = config.getDuration(ConfigKeys.Thing.ACTIVITY_CHECK_DELETED_INTERVAL); // Activity checking snapshotThreshold = getSnapshotThreshold(config); // Snapshotting thingSnapshotter = getSnapshotter(config, thingSnapshotterCreate); final Runnable becomeCreatedRunnable = this::becomeThingCreatedHandler; final Runnable becomeDeletedRunnable = this::becomeThingDeletedHandler; defaultContext = DefaultContext.getInstance(thingId, log, thingSnapshotter, becomeCreatedRunnable, becomeDeletedRunnable); handleThingEvents = ReceiveBuilder.create() .match(ThingEvent.class, event -> { final EventStrategy<ThingEvent> eventHandleStrategy = EventHandleStrategy.getInstance(); thing = eventHandleStrategy.handle(event, thing, getRevisionNumber()); }).build(); }