akka.event.LoggingAdapter Java Examples

The following examples show how to use akka.event.LoggingAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AriEventProcessing.java    From ari-proxy with GNU Affero General Public License v3.0 6 votes vote down vote up
private static Try<Source<ProducerRecord<String, String>, NotUsed>> createSource(
		String kafkaCommandsTopic,
		String kafkaEventsAndResponsesTopic,
		AriMessageType type,
		LoggingAdapter log,
		String callContext,
		JsonNode messageBody) {

	final AriMessageEnvelope envelope = new AriMessageEnvelope(
			type,
			kafkaCommandsTopic,
			messageBody,
			callContext
	);

	return Try.of(() -> writer.writeValueAsString(envelope))
			.map(marshalledEnvelope -> {
				log.debug("[ARI MESSAGE TYPE] {}", envelope.getType());
				return Source.single(new ProducerRecord<>(
						kafkaEventsAndResponsesTopic,
						callContext,
						marshalledEnvelope
				));
			});
}
 
Example #2
Source File: JMSPropertyMapper.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Set headers as properties and application properties into an AMQP JMS message according to the rules in the
 * class javadoc.
 *
 * @param message the message.
 * @param headers the mapped headers.
 * @param log the logger.
 */
static void setPropertiesAndApplicationProperties(final Message message,
        final Map<String, String> headers,
        final LoggingAdapter log) {

    headers.forEach((headerName, headerValue) -> {
        try {
            if (isDefinedAmqpProperty(headerName)) {
                setDefinedAmqpProperty(message, headerName, headerValue);
            } else {
                setAmqpApplicationProperty(message, headerName, headerValue);
            }
        } catch (final Exception e) {
            // errors are mostly user error; log them at debug level, then proceed with other properties.
            log.debug("Error setting AMQP property/application property <{}>=<{}>: <{}>",
                    headerName, headerValue, e);
        }
    });
}
 
Example #3
Source File: ConnectionValidator.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Resolve blacklisted hostnames into IP addresses that should not be accessed.
 *
 * @param configuredBlacklistedHostnames blacklisted hostnames.
 * @param log the logger.
 * @return blacklisted IP addresses.
 */
public static Collection<InetAddress> calculateBlacklistedAddresses(
        final Collection<String> configuredBlacklistedHostnames,
        final LoggingAdapter log) {

    return configuredBlacklistedHostnames.stream()
            .filter(host -> !host.isEmpty())
            .flatMap(host -> {
                try {
                    return Stream.of(InetAddress.getAllByName(host));
                } catch (final UnknownHostException e) {
                    log.error(e, "Could not resolve hostname during building blacklisted hostnames set: <{}>",
                            host);
                    return Stream.empty();
                }
            })
            .collect(Collectors.toSet());
}
 
Example #4
Source File: MongoThingsSearchPersistence.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private MongoThingsSearchPersistence(
        final MongoCollection<Document> collection,
        final LoggingAdapter log,
        final IndexInitializer indexInitializer,
        final Duration maxQueryTime,
        final MongoHints hints) {

    this.collection = collection;
    this.log = log;
    this.indexInitializer = indexInitializer;
    this.maxQueryTime = maxQueryTime;
    this.hints = hints;
}
 
Example #5
Source File: DefaultMessageMapperFactory.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private DefaultMessageMapperFactory(final ConnectionId connectionId,
        final MappingConfig mappingConfig,
        final ExtendedActorSystem actorSystem,
        final List<MessageMapperExtension> messageMapperExtensions,
        final LoggingAdapter log) {

    this.connectionId = checkNotNull(connectionId);
    this.mappingConfig = checkNotNull(mappingConfig, "MappingConfig");
    this.actorSystem = checkNotNull(actorSystem);
    this.messageMapperExtensions = checkNotNull(messageMapperExtensions);
    this.log = checkNotNull(log);
}
 
Example #6
Source File: DefaultMessageMapperFactory.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a new factory and returns the instance
 *
 * @param connectionId ID of the connection.
 * @param actorSystem the actor system to use for mapping config + dynamicAccess.
 * @param mappingConfig the configuration of the mapping behaviour.
 * @param log the log adapter used for debug and warning logs.
 * @return the new instance.
 * @throws NullPointerException if any argument is {@code null}.
 */
public static DefaultMessageMapperFactory of(final ConnectionId connectionId,
        final ActorSystem actorSystem,
        final MappingConfig mappingConfig,
        final LoggingAdapter log) {

    final ExtendedActorSystem extendedActorSystem = (ExtendedActorSystem) actorSystem;
    final List<MessageMapperExtension> messageMapperExtensions =
            tryToLoadMessageMappersExtensions(extendedActorSystem);
    return new DefaultMessageMapperFactory(connectionId, mappingConfig, extendedActorSystem,
            messageMapperExtensions, log);
}
 
Example #7
Source File: DefaultHttpPushFactory.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T> Flow<Pair<HttpRequest, T>, Pair<Try<HttpResponse>, T>, ?> createFlow(final ActorSystem system,
        final LoggingAdapter log) {

    final Http http = Http.get(system);
    final ConnectionPoolSettings poolSettings = getConnectionPoolSettings(system);
    final Flow<Pair<HttpRequest, T>, Pair<Try<HttpResponse>, T>, ?> flow;
    if (null != httpsConnectionContext) {
        final ConnectHttp connectHttpsWithCustomSSLContext =
                ConnectHttp.toHostHttps(baseUri).withCustomHttpsContext(httpsConnectionContext);
        // explicitly added <T> as in (some?) IntelliJ idea the line would show an error:
        flow = http.<T>cachedHostConnectionPoolHttps(connectHttpsWithCustomSSLContext, poolSettings, log);
    } else {
        // explicitly added <T> as in (some?) IntelliJ idea the line would show an error:
        // no SSL, hence no need for SSLContextCreator
        flow = http.<T>cachedHostConnectionPool(ConnectHttp.toHost(baseUri), poolSettings, log);
    }
    return flow.buffer(parallelism, OverflowStrategy.backpressure());
}
 
Example #8
Source File: DeviceActorMessageProcessor.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public DeviceActorMessageProcessor(ActorSystemContext systemContext, LoggingAdapter logger, DeviceId deviceId) {
  super(systemContext, logger);
  this.deviceId = deviceId;
  this.sessions = new HashMap<>();
  this.attributeSubscriptions = new HashMap<>();
  this.rpcSubscriptions = new HashMap<>();
  this.rpcPendingMap = new HashMap<>();
  initAttributes();
}
 
Example #9
Source File: RuleContextAwareMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected RuleContextAwareMsgProcessor(ActorSystemContext systemContext, LoggingAdapter logger, RuleId ruleId) {
  super(systemContext, logger);
  this.ruleId = ruleId;
}
 
Example #10
Source File: RuleActorMessageProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected RuleActorMessageProcessor(TenantId tenantId, RuleId ruleId, ActorSystemContext systemContext,
    LoggingAdapter logger) {
  super(systemContext, logger, tenantId, ruleId);
  this.pendingMsgMap = new HashMap<>();
  this.ruleCtx = new RuleProcessingContext(systemContext, ruleId);
}
 
Example #11
Source File: AbstractSessionActorMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected AbstractSessionActorMsgProcessor(ActorSystemContext ctx, LoggingAdapter logger, SessionId sessionId) {
  super(ctx, logger);
  this.sessionId = sessionId;
}
 
Example #12
Source File: SyncMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
public SyncMsgProcessor(ActorSystemContext ctx, LoggingAdapter logger, SessionId sessionId) {
  super(ctx, logger, sessionId);
}
 
Example #13
Source File: ASyncMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
public ASyncMsgProcessor(ActorSystemContext ctx, LoggingAdapter logger, SessionId sessionId) {
  super(ctx, logger, sessionId);
}
 
Example #14
Source File: ComponentMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected ComponentMsgProcessor(ActorSystemContext systemContext, LoggingAdapter logger, TenantId tenantId, T id) {
  super(systemContext, logger);
  this.tenantId = tenantId;
  this.entityId = id;
}
 
Example #15
Source File: AbstractContextAwareMsgProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected AbstractContextAwareMsgProcessor(ActorSystemContext systemContext, LoggingAdapter logger) {
  super();
  this.systemContext = systemContext;
  this.logger = logger;
}
 
Example #16
Source File: PluginActorMessageProcessor.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
protected PluginActorMessageProcessor(TenantId tenantId, PluginId pluginId, ActorSystemContext systemContext,
    LoggingAdapter logger, ActorRef parent, ActorRef self) {
  super(systemContext, logger, tenantId, pluginId);
  this.pluginCtx = new SharedPluginProcessingContext(systemContext, tenantId, pluginId, parent, self);
  this.trustedCtx = new PluginProcessingContext(pluginCtx, null);
}
 
Example #17
Source File: HttpPublisherActorTest.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public <T> Flow<Pair<HttpRequest, T>, Pair<Try<HttpResponse>, T>, ?> createFlow(final ActorSystem system,
        final LoggingAdapter log) {
    return Flow.<Pair<HttpRequest, T>>create()
            .map(pair -> Pair.create(Try.apply(() -> mapper.apply(pair.first())), pair.second()));
}
 
Example #18
Source File: AriEventProcessing.java    From ari-proxy with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Source<ProducerRecord<String, String>, NotUsed> generateProducerRecordFromEvent(
		String kafkaCommandsTopic,
		String kafkaEventsAndResponsesTopic,
		Message message,
		ActorRef callContextProvider,
		LoggingAdapter log,
		Runnable applicationReplacedHandler) {

	final JsonNode messageBody = Try.of(() -> reader.readTree(message.asTextMessage().getStrictText())).getOrElseThrow(t -> new RuntimeException(t));

	final String eventTypeString = getValueFromMessageByPath(message, "/type").getOrElseThrow(t -> t);
	final AriMessageType ariMessageType = AriMessageType.fromType(eventTypeString);

	if (AriMessageType.APPLICATION_REPLACED.equals(ariMessageType)) {
		log.info("Got APPLICATION_REPLACED event, shutting down...");
		applicationReplacedHandler.run();
		return Source.empty();
	}

	return ariMessageType.extractResourceIdFromBody(messageBody)
			.map(resourceIdTry -> resourceIdTry
					.flatMap(id -> getCallContext(
							id,
							callContextProvider,
							AriMessageType.STASIS_START.equals(ariMessageType)
									? ProviderPolicy.CREATE_IF_MISSING
									: ProviderPolicy.LOOKUP_ONLY
					))
					.flatMap(callContext -> createSource(
							kafkaCommandsTopic,
							kafkaEventsAndResponsesTopic,
							ariMessageType,
							log,
							callContext,
							messageBody
					))
			)
			.toTry()
			.flatMap(Function.identity())
			.getOrElseThrow(t -> new RuntimeException(t));
}
 
Example #19
Source File: CreditDecisionSource.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private Logger(final GraphDSL.Builder<NotUsed> builder, final LoggingAdapter loggingAdapter) {
    this.builder = builder;
    this.loggingAdapter = loggingAdapter;
}
 
Example #20
Source File: RootSupervisorStrategyFactory.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
public static OneForOneStrategy createStrategy(final LoggingAdapter log) {
    return new OneForOneStrategy(true, DeciderBuilder
            .match(NullPointerException.class, e -> {
                log.error(e, "NullPointer in child actor: {}", e.getMessage());
                log.info(RESTARTING_CHILD_MSG);
                return SupervisorStrategy.restart();
            }).match(IllegalArgumentException.class, e -> {
                log.warning("Illegal Argument in child actor: {}", e.getMessage());
                return SupervisorStrategy.resume();
            }).match(IndexOutOfBoundsException.class, e -> {
                log.warning("IndexOutOfBounds in child actor: {}", e.getMessage());
                return SupervisorStrategy.resume();
            }).match(IllegalStateException.class, e -> {
                log.warning("Illegal State in child actor: {}", e.getMessage());
                return SupervisorStrategy.resume();
            }).match(NoSuchElementException.class, e -> {
                log.warning("NoSuchElement in child actor: {}", e.getMessage());
                return SupervisorStrategy.resume();
            }).match(AskTimeoutException.class, e -> {
                log.warning("AskTimeoutException in child actor: {}", e.getMessage());
                return SupervisorStrategy.resume();
            }).match(ConnectException.class, e -> {
                log.warning("ConnectException in child actor: {}", e.getMessage());
                log.info(RESTARTING_CHILD_MSG);
                return SupervisorStrategy.restart();
            }).match(InvalidActorNameException.class, e -> {
                log.warning("InvalidActorNameException in child actor: {}", e.getMessage());
                return SupervisorStrategy.resume();
            }).match(ActorKilledException.class, e -> {
                log.error(e, "ActorKilledException in child actor: {}", e.message());
                log.info(RESTARTING_CHILD_MSG);
                return SupervisorStrategy.restart();
            }).match(DittoRuntimeException.class, e -> {
                log.error(e,
                        "DittoRuntimeException '{}' should not be escalated to RootActor. Simply resuming Actor.",
                        e.getErrorCode());
                return SupervisorStrategy.resume();
            }).match(Throwable.class, e -> {
                log.error(e, "Escalating above root actor!");
                return SupervisorStrategy.escalate();
            }).matchAny(e -> {
                log.error("Unknown message:'{}'! Escalating above root actor!", e);
                return SupervisorStrategy.escalate();
            }).build());
}
 
Example #21
Source File: HttpPushFactory.java    From ditto with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Create a flow to send HTTP(S) requests.
 *
 * @param system the actor system with the default Akka HTTP configuration.
 * @param log logger for the flow.
 * @param <T> type of additional object flowing through flow.
 * @return flow from request-correlationId pairs to response-correlationId pairs.
 */
<T> Flow<Pair<HttpRequest, T>, Pair<Try<HttpResponse>, T>, ?> createFlow(ActorSystem system, LoggingAdapter log);
 
Example #22
Source File: HealthRouteSupplier.java    From ditto with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Constructs a new {@code HealthRouteFunction}.
 *
 * @param healthCheckingActor the Actor selection to the health-checking actor to use.
 */
public HealthRouteSupplier(final ActorRef healthCheckingActor, final LoggingAdapter log) {
    this.healthCheckingActor = healthCheckingActor;
    this.log = log;
}