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);
}
}
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);
}
Aggregations