Search in sources :

Example 1 with AbstractMessageHandlerMetrics

use of org.springframework.integration.support.management.AbstractMessageHandlerMetrics in project spring-integration by spring-projects.

the class AbstractMessageHandler method handleMessage.

@Override
public void handleMessage(Message<?> message) {
    Assert.notNull(message, "Message must not be null");
    // NOSONAR - false positive
    Assert.notNull(message.getPayload(), "Message payload must not be null");
    if (this.loggingEnabled && this.logger.isDebugEnabled()) {
        this.logger.debug(this + " received message: " + message);
    }
    MetricsContext start = null;
    boolean countsEnabled = this.countsEnabled;
    AbstractMessageHandlerMetrics handlerMetrics = this.handlerMetrics;
    SampleFacade sample = null;
    if (countsEnabled && this.metricsCaptor != null) {
        sample = this.metricsCaptor.start();
    }
    try {
        if (this.shouldTrack) {
            message = MessageHistory.write(message, this, getMessageBuilderFactory());
        }
        if (countsEnabled) {
            start = handlerMetrics.beforeHandle();
            handleMessageInternal(message);
            if (sample != null) {
                sample.stop(sendTimer());
            }
            handlerMetrics.afterHandle(start, true);
        } else {
            handleMessageInternal(message);
        }
    } catch (Exception e) {
        if (sample != null) {
            sample.stop(buildSendTimer(false, e.getClass().getSimpleName()));
        }
        if (countsEnabled) {
            handlerMetrics.afterHandle(start, false);
        }
        throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(message, () -> "error occurred in message handler [" + this + "]", e);
    }
}
Also used : SampleFacade(org.springframework.integration.support.management.metrics.SampleFacade) MetricsContext(org.springframework.integration.support.management.MetricsContext) AbstractMessageHandlerMetrics(org.springframework.integration.support.management.AbstractMessageHandlerMetrics) MessagingException(org.springframework.messaging.MessagingException)

Example 2 with AbstractMessageHandlerMetrics

use of org.springframework.integration.support.management.AbstractMessageHandlerMetrics in project spring-integration by spring-projects.

the class IntegrationManagementConfigurer method configureHandlerMetrics.

@SuppressWarnings("unchecked")
private void configureHandlerMetrics(String name, MessageHandlerMetrics bean) {
    AbstractMessageHandlerMetrics metrics = this.metricsFactory.createHandlerMetrics(name);
    Assert.state(metrics != null, "'metrics' must not be null");
    ManagementOverrides overrides = bean.getOverrides();
    Boolean enabled = PatternMatchUtils.smartMatch(name, this.enabledCountsPatterns);
    if (enabled != null) {
        bean.setCountsEnabled(enabled);
    } else {
        if (!overrides.countsConfigured) {
            bean.setCountsEnabled(this.defaultCountsEnabled);
        }
    }
    enabled = PatternMatchUtils.smartMatch(name, this.enabledStatsPatterns);
    if (enabled != null) {
        bean.setStatsEnabled(enabled);
        metrics.setFullStatsEnabled(enabled);
    } else {
        if (!overrides.statsConfigured) {
            bean.setStatsEnabled(this.defaultStatsEnabled);
            metrics.setFullStatsEnabled(this.defaultStatsEnabled);
        }
    }
    if (bean instanceof ConfigurableMetricsAware && !overrides.metricsConfigured) {
        ((ConfigurableMetricsAware<AbstractMessageHandlerMetrics>) bean).configureMetrics(metrics);
    }
    this.handlersByName.put(bean.getManagedName() != null ? bean.getManagedName() : name, bean);
}
Also used : ConfigurableMetricsAware(org.springframework.integration.support.management.ConfigurableMetricsAware) AbstractMessageHandlerMetrics(org.springframework.integration.support.management.AbstractMessageHandlerMetrics) ManagementOverrides(org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides)

Aggregations

AbstractMessageHandlerMetrics (org.springframework.integration.support.management.AbstractMessageHandlerMetrics)2 ConfigurableMetricsAware (org.springframework.integration.support.management.ConfigurableMetricsAware)1 ManagementOverrides (org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides)1 MetricsContext (org.springframework.integration.support.management.MetricsContext)1 SampleFacade (org.springframework.integration.support.management.metrics.SampleFacade)1 MessagingException (org.springframework.messaging.MessagingException)1