diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java index 5498d654c3..802fb980d7 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractSubscribableAmqpChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer; import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.amqp.support.converter.SimpleMessageConverter; -import org.springframework.context.SmartLifecycle; import org.springframework.integration.MessageDispatchingException; import org.springframework.integration.amqp.support.AmqpHeaderMapper; import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper; @@ -38,6 +37,7 @@ import org.springframework.integration.dispatcher.AbstractDispatcher; import org.springframework.integration.dispatcher.MessageDispatcher; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.integration.support.MessageBuilderFactory; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; @@ -52,7 +52,7 @@ import org.springframework.util.Assert; * @since 2.1 */ abstract class AbstractSubscribableAmqpChannel extends AbstractAmqpChannel - implements SubscribableChannel, SmartLifecycle { + implements SubscribableChannel, ManageableSmartLifecycle { private final String channelName; diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java index 284858098e..a5a9d68aac 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java @@ -50,10 +50,8 @@ import org.springframework.util.Assert; * * @since 2.1 */ -@SuppressWarnings("deprecation") public class PollableAmqpChannel extends AbstractAmqpChannel - implements PollableChannel, org.springframework.integration.support.management.PollableChannelManagement, - ExecutorChannelInterceptorAware { + implements PollableChannel, ExecutorChannelInterceptorAware { private final String channelName; @@ -115,50 +113,6 @@ public class PollableAmqpChannel extends AbstractAmqpChannel setAdmin(amqpAdmin); } - /** - * Deprecated. - * @return receive count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getReceiveCount() { - return getMetrics().getReceiveCount(); - } - - /** - * Deprecated. - * @return receive count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getReceiveCountLong() { - return getMetrics().getReceiveCountLong(); - } - - /** - * Deprecated. - * @return receive error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getReceiveErrorCount() { - return getMetrics().getReceiveErrorCount(); - } - - /** - * Deprecated. - * @return receive error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getReceiveErrorCountLong() { - return getMetrics().getReceiveErrorCountLong(); - } - @Override protected String getRoutingKey() { return this.queue != null ? this.queue.getName() : super.getRoutingKey(); @@ -208,7 +162,6 @@ public class PollableAmqpChannel extends AbstractAmqpChannel ChannelInterceptorList interceptorList = getIChannelInterceptorList(); Deque interceptorStack = null; AtomicBoolean counted = new AtomicBoolean(); - boolean countsEnabled = isCountsEnabled(); boolean traceEnabled = isLoggingEnabled() && logger.isTraceEnabled(); try { if (traceEnabled) { @@ -221,8 +174,7 @@ public class PollableAmqpChannel extends AbstractAmqpChannel } } Object object = performReceive(timeout); - Message message = buildMessageFromResult(object, traceEnabled, countsEnabled ? counted : null); - + Message message = buildMessageFromResult(object, traceEnabled, counted); if (message != null) { message = interceptorList.postReceive(message, this); @@ -231,7 +183,7 @@ public class PollableAmqpChannel extends AbstractAmqpChannel return message; } catch (RuntimeException ex) { - if (countsEnabled && !counted.get()) { + if (!counted.get()) { incrementReceiveErrorCounter(ex); } interceptorList.afterReceiveCompletion(null, this, ex, interceptorStack); @@ -279,16 +231,10 @@ public class PollableAmqpChannel extends AbstractAmqpChannel } } - private Message buildMessageFromResult(@Nullable Object object, boolean traceEnabled, - @Nullable AtomicBoolean counted) { + private Message buildMessageFromResult(@Nullable Object object, boolean traceEnabled, AtomicBoolean counted) { Message message = null; if (object != null) { - if (counted != null) { - incrementReceiveCounter(); - getMetrics().afterReceive(); - counted.set(true); - } if (object instanceof Message) { message = (Message) object; } @@ -298,6 +244,8 @@ public class PollableAmqpChannel extends AbstractAmqpChannel .build(); } } + incrementReceiveCounter(); + counted.set(true); if (traceEnabled) { logger.trace("postReceive on channel '" + this @@ -322,7 +270,6 @@ public class PollableAmqpChannel extends AbstractAmqpChannel if (metricsCaptor != null) { buildReceiveCounter(metricsCaptor, ex).increment(); } - getMetrics().afterError(); } private CounterFacade buildReceiveCounter(MetricsCaptor metricsCaptor, @Nullable Exception ex) { diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java index 64e54ace16..d70c130fef 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java @@ -32,7 +32,6 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.AmqpHeaders; import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.expression.Expression; import org.springframework.integration.amqp.support.AmqpHeaderMapper; import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper; @@ -46,6 +45,7 @@ import org.springframework.integration.mapping.AbstractHeaderMapper; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.integration.support.DefaultErrorMessageStrategy; import org.springframework.integration.support.ErrorMessageStrategy; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -61,7 +61,7 @@ import org.springframework.util.concurrent.SettableListenableFuture; * */ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler - implements Lifecycle { + implements ManageableLifecycle { private static final String NO_ID = new UUID(0L, 0L).toString(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java index 8217b1f721..a367c1eb79 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java @@ -53,6 +53,7 @@ import org.springframework.integration.store.UniqueExpiryCallback; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.integration.support.locks.DefaultLockRegistry; import org.springframework.integration.support.locks.LockRegistry; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.util.UUIDConverter; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -103,7 +104,7 @@ import org.springframework.util.ObjectUtils; * @since 2.0 */ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageProducingHandler - implements DiscardingMessageHandler, ApplicationEventPublisherAware, Lifecycle { + implements DiscardingMessageHandler, ApplicationEventPublisherAware, ManageableLifecycle { private final Comparator> sequenceNumberComparator = new MessageSequenceComparator(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/DelegatingMessageGroupProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/DelegatingMessageGroupProcessor.java index 6674e0e6ac..d6ed43cf8c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/DelegatingMessageGroupProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/DelegatingMessageGroupProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.springframework.integration.store.MessageGroup; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.integration.support.DefaultMessageBuilderFactory; import org.springframework.integration.support.MessageBuilderFactory; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -49,7 +50,8 @@ import org.springframework.util.Assert; * * @since 5.2 */ -public class DelegatingMessageGroupProcessor implements MessageGroupProcessor, BeanFactoryAware, Lifecycle { +public class DelegatingMessageGroupProcessor implements MessageGroupProcessor, BeanFactoryAware, + ManageableLifecycle { private final MessageGroupProcessor delegate; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandler.java index 4f90edd02a..97591b3f54 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/FluxAggregatorMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +21,11 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.function.Predicate; -import org.springframework.context.Lifecycle; import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.channel.ReactiveStreamsSubscribableChannel; import org.springframework.integration.handler.AbstractMessageProducingHandler; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; @@ -53,7 +53,7 @@ import reactor.core.publisher.Mono; * * @since 5.2 */ -public class FluxAggregatorMessageHandler extends AbstractMessageProducingHandler implements Lifecycle { +public class FluxAggregatorMessageHandler extends AbstractMessageProducingHandler implements ManageableLifecycle { private final AtomicBoolean subscribed = new AtomicBoolean(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingCorrelationStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingCorrelationStrategy.java index 3141860bf7..c78e056a02 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingCorrelationStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingCorrelationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ import java.lang.reflect.Method; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.Lifecycle; import org.springframework.integration.handler.MethodInvokingMessageProcessor; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -34,7 +34,7 @@ import org.springframework.util.Assert; * @author Artem Bilan * @author Gary Russell */ -public class MethodInvokingCorrelationStrategy implements CorrelationStrategy, BeanFactoryAware, Lifecycle { +public class MethodInvokingCorrelationStrategy implements CorrelationStrategy, BeanFactoryAware, ManageableLifecycle { private final MethodInvokingMessageProcessor processor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessor.java index 343f55119a..773601ca58 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageGroupProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,10 @@ import java.util.Collection; import java.util.Map; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.core.convert.ConversionService; import org.springframework.integration.annotation.Aggregator; import org.springframework.integration.store.MessageGroup; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; /** @@ -39,7 +39,7 @@ import org.springframework.messaging.Message; * @since 2.0 */ public class MethodInvokingMessageGroupProcessor extends AbstractAggregatingMessageGroupProcessor - implements Lifecycle { + implements ManageableLifecycle { private final MethodInvokingMessageListProcessor processor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java index bd67868b8e..792ae3b0f3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import java.util.Collection; import java.util.Map; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.integration.handler.support.MessagingMethodInvokerHelper; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.util.AbstractExpressionEvaluator; import org.springframework.lang.NonNull; import org.springframework.messaging.Message; @@ -38,7 +38,7 @@ import org.springframework.messaging.Message; * @since 2.0 */ public class MethodInvokingMessageListProcessor extends AbstractExpressionEvaluator - implements Lifecycle { + implements ManageableLifecycle { private final MessagingMethodInvokerHelper delegate; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategy.java index 0c231157d1..76a6425c96 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,9 @@ import java.lang.reflect.Method; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.Lifecycle; import org.springframework.core.convert.ConversionService; import org.springframework.integration.store.MessageGroup; +import org.springframework.integration.support.management.ManageableLifecycle; /** * A {@link ReleaseStrategy} that invokes a method on a plain old Java object. @@ -31,7 +31,7 @@ import org.springframework.integration.store.MessageGroup; * @author Dave Syer * @author Artme Bilan */ -public class MethodInvokingReleaseStrategy implements ReleaseStrategy, BeanFactoryAware, Lifecycle { +public class MethodInvokingReleaseStrategy implements ReleaseStrategy, BeanFactoryAware, ManageableLifecycle { private final MethodInvokingMessageListProcessor adapter; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index e55caea849..93208df87b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -36,6 +36,7 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.support.management.IntegrationManagedResource; +import org.springframework.integration.support.management.IntegrationManagement; import org.springframework.integration.support.management.TrackableComponent; import org.springframework.integration.support.management.metrics.MeterFacade; import org.springframework.integration.support.management.metrics.MetricsCaptor; @@ -66,13 +67,9 @@ import org.springframework.util.StringUtils; @IntegrationManagedResource @SuppressWarnings("deprecation") public abstract class AbstractMessageChannel extends IntegrationObjectSupport - implements MessageChannel, TrackableComponent, InterceptableChannel, - org.springframework.integration.support.management.MessageChannelMetrics, - org.springframework.integration.support.management.ConfigurableMetricsAware< - org.springframework.integration.support.management.AbstractMessageChannelMetrics>, - IntegrationPattern { + implements MessageChannel, TrackableComponent, InterceptableChannel, IntegrationManagement, IntegrationPattern { - protected final ChannelInterceptorList interceptors; // NOSONAR + protected final ChannelInterceptorList interceptors = new ChannelInterceptorList(logger); // NOSONAR private final Comparator orderComparator = new OrderComparator(); @@ -88,25 +85,14 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport private volatile MessageConverter messageConverter; - private volatile boolean countsEnabled; - - private volatile boolean statsEnabled; - private volatile boolean loggingEnabled = true; - private volatile org.springframework.integration.support.management.AbstractMessageChannelMetrics channelMetrics - = new org.springframework.integration.support.management.DefaultMessageChannelMetrics(); - private MetricsCaptor metricsCaptor; private TimerFacade successTimer; private TimerFacade failureTimer; - public AbstractMessageChannel() { - this.interceptors = new ChannelInterceptorList(logger); - } - @Override public String getComponentType() { return "channel"; @@ -132,37 +118,6 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport return this.metricsCaptor; } - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.countsEnabled = countsEnabled; - this.managementOverrides.countsConfigured = true; - if (!countsEnabled) { - this.statsEnabled = false; - this.managementOverrides.statsConfigured = true; - } - } - - @Override - public boolean isCountsEnabled() { - return this.countsEnabled; - } - - @Override - public void setStatsEnabled(boolean statsEnabled) { - if (statsEnabled) { - this.countsEnabled = true; - this.managementOverrides.countsConfigured = true; - } - this.statsEnabled = statsEnabled; - this.channelMetrics.setFullStatsEnabled(statsEnabled); - this.managementOverrides.statsConfigured = true; - } - - @Override - public boolean isStatsEnabled() { - return this.statsEnabled; - } - @Override public boolean isLoggingEnabled() { return this.loggingEnabled; @@ -174,31 +129,6 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport this.managementOverrides.loggingConfigured = true; } - /** - * Deprecated. - * @return channel metrics. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - protected org.springframework.integration.support.management.AbstractMessageChannelMetrics getMetrics() { - return this.channelMetrics; - } - - /** - * Deprecated. - * @param metrics the metrics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void configureMetrics( - org.springframework.integration.support.management.AbstractMessageChannelMetrics metrics) { - - Assert.notNull(metrics, "'metrics' must not be null"); - this.channelMetrics = metrics; - this.managementOverrides.metricsConfigured = true; - } - /** * Specify the Message payload datatype(s) supported by this channel. If a * payload type does not match directly, but the 'conversionService' is @@ -289,181 +219,6 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport return this.interceptors; } - /** - * Deprecated. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void reset() { - this.channelMetrics.reset(); - } - - /** - * Deprecated. - * @return send count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getSendCount() { - return this.channelMetrics.getSendCount(); - } - - /** - * Deprecated. - * @return send count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getSendCountLong() { - return this.channelMetrics.getSendCountLong(); - } - - /** - * Deprecated. - * @return send error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getSendErrorCount() { - return this.channelMetrics.getSendErrorCount(); - } - - /** - * Deprecated. - * @return send error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getSendErrorCountLong() { - return this.channelMetrics.getSendErrorCountLong(); - } - - /** - * Deprecated. - * @return time since last - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getTimeSinceLastSend() { - return this.channelMetrics.getTimeSinceLastSend(); - } - - /** - * Deprecated. - * @return mean send rate - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanSendRate() { - return this.channelMetrics.getMeanSendRate(); - } - - /** - * Deprecated. - * @return mean error rate - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanErrorRate() { - return this.channelMetrics.getMeanErrorRate(); - } - - /** - * Deprecated. - * @return mean error ratio - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanErrorRatio() { - return this.channelMetrics.getMeanErrorRatio(); - } - - /** - * Deprecated. - * @return mean send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanSendDuration() { - return this.channelMetrics.getMeanSendDuration(); - } - - /** - * Deprecated. - * @return min send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMinSendDuration() { - return this.channelMetrics.getMinSendDuration(); - } - - /** - * Deprecated. - * @return max send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMaxSendDuration() { - return this.channelMetrics.getMaxSendDuration(); - } - - /** - * Deprecated. - * @return standard deviation send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getStandardDeviationSendDuration() { - return this.channelMetrics.getStandardDeviationSendDuration(); - } - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getSendDuration() { - return this.channelMetrics.getSendDuration(); - } - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getSendRate() { - return this.channelMetrics.getSendRate(); - } - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getErrorRate() { - return this.channelMetrics.getErrorRate(); - } - @Override public ManagementOverrides getOverrides() { return this.managementOverrides; @@ -484,9 +239,6 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport MessageConverter.class); } } - if (this.statsEnabled) { - this.channelMetrics.setFullStatsEnabled(true); - } this.fullChannelName = null; } @@ -544,10 +296,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport Deque interceptorStack = null; boolean sent = false; boolean metricsProcessed = false; - org.springframework.integration.support.management.MetricsContext metricsContext = null; - boolean countsAreEnabled = this.countsEnabled; ChannelInterceptorList interceptorList = this.interceptors; - org.springframework.integration.support.management.AbstractMessageChannelMetrics metrics = this.channelMetrics; SampleFacade sample = null; try { message = convertPayloadIfNecessary(message); @@ -562,21 +311,14 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport return false; } } - if (countsAreEnabled) { - metricsContext = metrics.beforeSend(); - if (this.metricsCaptor != null) { - sample = this.metricsCaptor.start(); - } - sent = doSend(message, timeout); - if (sample != null) { - sample.stop(sendTimer(sent)); - } - metrics.afterSend(metricsContext, sent); - metricsProcessed = true; + if (this.metricsCaptor != null) { + sample = this.metricsCaptor.start(); } - else { - sent = doSend(message, timeout); + sent = doSend(message, timeout); + if (sample != null) { + sample.stop(sendTimer(sent)); } + metricsProcessed = true; if (debugEnabled) { logger.debug("postSend (sent=" + sent + ") on channel '" + this + "', message: " + message); @@ -588,11 +330,10 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport return sent; } catch (Exception ex) { - if (countsAreEnabled && !metricsProcessed) { + if (!metricsProcessed) { if (sample != null) { sample.stop(buildSendTimer(false, ex.getClass().getSimpleName())); } - metrics.afterSend(metricsContext, false); } if (interceptorStack != null) { interceptorList.afterSendCompletion(message, this, sent, ex, interceptorStack); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractPollableChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractPollableChannel.java index 100f4c432d..51199a8f6d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractPollableChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractPollableChannel.java @@ -39,57 +39,12 @@ import org.springframework.messaging.support.ExecutorChannelInterceptor; */ @SuppressWarnings("deprecation") public abstract class AbstractPollableChannel extends AbstractMessageChannel - implements PollableChannel, org.springframework.integration.support.management.PollableChannelManagement, - ExecutorChannelInterceptorAware { + implements PollableChannel, ExecutorChannelInterceptorAware { private int executorInterceptorsSize; private CounterFacade receiveCounter; - /** - * Deprecated. - * @return receive count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getReceiveCount() { - return getMetrics().getReceiveCount(); - } - - /** - * Deprecated. - * @return receive count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getReceiveCountLong() { - return getMetrics().getReceiveCountLong(); - } - - /** - * Deprecated. - * @return error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getReceiveErrorCount() { - return getMetrics().getReceiveErrorCount(); - } - - /** - * Deprecated. - * @return error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getReceiveErrorCountLong() { - return getMetrics().getReceiveErrorCountLong(); - } - @Override public IntegrationPatternType getIntegrationPatternType() { return IntegrationPatternType.pollable_channel; @@ -124,7 +79,6 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel ChannelInterceptorList interceptorList = getIChannelInterceptorList(); Deque interceptorStack = null; boolean counted = false; - boolean countsEnabled = isCountsEnabled(); boolean traceEnabled = isLoggingEnabled() && logger.isTraceEnabled(); try { if (traceEnabled) { @@ -144,11 +98,8 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel } } else { - if (countsEnabled) { - incrementReceiveCounter(); - getMetrics().afterReceive(); - counted = true; - } + incrementReceiveCounter(); + counted = true; if (logger.isDebugEnabled()) { logger.debug("postReceive on channel '" + this + "', message: " + message); @@ -162,7 +113,7 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel return message; } catch (RuntimeException ex) { - if (countsEnabled && !counted) { + if (!counted) { incrementReceiveErrorCounter(ex); } interceptorList.afterReceiveCompletion(null, this, ex, interceptorStack); @@ -185,7 +136,6 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel if (metricsCaptor != null) { buildReceiveCounter(metricsCaptor, ex).increment(); } - getMetrics().afterError(); } private CounterFacade buildReceiveCounter(MetricsCaptor metricsCaptor, @Nullable Exception ex) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/DefaultHeaderChannelRegistry.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/DefaultHeaderChannelRegistry.java index 7af6f4df51..c508e5e48c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/DefaultHeaderChannelRegistry.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/DefaultHeaderChannelRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicLong; -import org.springframework.context.Lifecycle; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.support.channel.HeaderChannelRegistry; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; @@ -48,7 +48,7 @@ import org.springframework.util.Assert; * */ public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport - implements HeaderChannelRegistry, Lifecycle, Runnable { + implements HeaderChannelRegistry, ManageableLifecycle, Runnable { private static final int DEFAULT_REAPER_DELAY = 60000; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/NullChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/NullChannel.java index 85c5786f72..09d28aec2e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/NullChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/NullChannel.java @@ -24,15 +24,14 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanNameAware; import org.springframework.integration.IntegrationPattern; import org.springframework.integration.IntegrationPatternType; -import org.springframework.integration.support.context.NamedComponent; import org.springframework.integration.support.management.IntegrationManagedResource; +import org.springframework.integration.support.management.IntegrationManagement; import org.springframework.integration.support.management.metrics.CounterFacade; import org.springframework.integration.support.management.metrics.MetricsCaptor; import org.springframework.integration.support.management.metrics.TimerFacade; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; -import org.springframework.util.Assert; /** * A channel implementation that essentially behaves like "/dev/null". @@ -45,24 +44,13 @@ import org.springframework.util.Assert; * @author Artyem Bilan */ @IntegrationManagedResource -@SuppressWarnings("deprecation") public class NullChannel implements PollableChannel, - org.springframework.integration.support.management.MessageChannelMetrics, - org.springframework.integration.support.management.ConfigurableMetricsAware< - org.springframework.integration.support.management.AbstractMessageChannelMetrics>, - BeanNameAware, NamedComponent, IntegrationPattern { + BeanNameAware, IntegrationManagement, IntegrationPattern { private final Log logger = LogFactory.getLog(getClass()); private final ManagementOverrides managementOverrides = new ManagementOverrides(); - private org.springframework.integration.support.management.AbstractMessageChannelMetrics channelMetrics - = new org.springframework.integration.support.management.DefaultMessageChannelMetrics("nullChannel"); - - private boolean countsEnabled; - - private boolean statsEnabled; - private boolean loggingEnabled = true; private String beanName; @@ -76,8 +64,6 @@ public class NullChannel implements PollableChannel, @Override public void setBeanName(String beanName) { this.beanName = beanName; - this.channelMetrics = - new org.springframework.integration.support.management.DefaultMessageChannelMetrics(this.beanName); } @Override @@ -118,246 +104,6 @@ public class NullChannel implements PollableChannel, this.metricsCaptor = registry; } - @Override - public void configureMetrics( - org.springframework.integration.support.management.AbstractMessageChannelMetrics metrics) { - - Assert.notNull(metrics, "'metrics' must not be null"); - this.channelMetrics = metrics; - this.managementOverrides.metricsConfigured = true; - } - - /** - * Deprecated. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void reset() { - this.channelMetrics.reset(); - } - - /** - * Deprecated. - * @param countsEnabled the countsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.countsEnabled = countsEnabled; - this.managementOverrides.countsConfigured = true; - if (!countsEnabled) { - this.statsEnabled = false; - this.managementOverrides.statsConfigured = true; - } - } - - /** - * Deprecated. - * @return counts enabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public boolean isCountsEnabled() { - return this.countsEnabled; - } - - /** - * Deprecated. - * @param statsEnabled the statsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void setStatsEnabled(boolean statsEnabled) { - if (statsEnabled) { - this.countsEnabled = true; - this.managementOverrides.countsConfigured = true; - } - this.statsEnabled = statsEnabled; - this.channelMetrics.setFullStatsEnabled(statsEnabled); - this.managementOverrides.statsConfigured = true; - } - - /** - * Deprecated. - * @return stats enabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public boolean isStatsEnabled() { - return this.statsEnabled; - } - - /** - * Deprecated. - * @return send count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getSendCount() { - return this.channelMetrics.getSendCount(); - } - - /** - * Deprecated. - * @return send count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getSendCountLong() { - return this.channelMetrics.getSendCountLong(); - } - - /** - * Deprecated. - * @return error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getSendErrorCount() { - return this.channelMetrics.getSendErrorCount(); - } - - /** - * Deprecated. - * @return error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getSendErrorCountLong() { - return this.channelMetrics.getSendErrorCountLong(); - } - - /** - * Deprecated. - * @return time since last send - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getTimeSinceLastSend() { - return this.channelMetrics.getTimeSinceLastSend(); - } - - /** - * Deprecated. - * @return mean send rate - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanSendRate() { - return this.channelMetrics.getMeanSendRate(); - } - - /** - * Deprecated. - * @return mean error rate - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanErrorRate() { - return this.channelMetrics.getMeanErrorRate(); - } - - /** - * Deprecated. - * @return mean error ratio - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanErrorRatio() { - return this.channelMetrics.getMeanErrorRatio(); - } - - /** - * Deprecated. - * @return mean send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanSendDuration() { - return this.channelMetrics.getMeanSendDuration(); - } - - /** - * Deprecated. - * @return min send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMinSendDuration() { - return this.channelMetrics.getMinSendDuration(); - } - - /** - * Deprecated. - * @return max send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMaxSendDuration() { - return this.channelMetrics.getMaxSendDuration(); - } - - /** - * Deprecated. - * @return standard deviation send duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getStandardDeviationSendDuration() { - return this.channelMetrics.getStandardDeviationSendDuration(); - } - - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getSendDuration() { - return this.channelMetrics.getSendDuration(); - } - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getSendRate() { - return this.channelMetrics.getSendRate(); - } - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getErrorRate() { - return this.channelMetrics.getErrorRate(); - } - @Override public ManagementOverrides getOverrides() { return this.managementOverrides; @@ -373,11 +119,8 @@ public class NullChannel implements PollableChannel, if (this.loggingEnabled && this.logger.isDebugEnabled()) { this.logger.debug("message sent to null channel: " + message); } - if (this.countsEnabled) { - if (this.metricsCaptor != null) { - sendTimer().record(0, TimeUnit.MILLISECONDS); - } - this.channelMetrics.afterSend(this.channelMetrics.beforeSend(), true); + if (this.metricsCaptor != null) { + sendTimer().record(0, TimeUnit.MILLISECONDS); } return true; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java index 09f5e89661..e4a00cfa01 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannel.java @@ -44,8 +44,7 @@ import org.springframework.util.Assert; * @author Artem Bilan */ @SuppressWarnings("deprecation") -public class QueueChannel extends AbstractPollableChannel implements QueueChannelOperations, - org.springframework.integration.support.management.QueueChannelManagement { +public class QueueChannel extends AbstractPollableChannel implements QueueChannelOperations { private final Queue> queue; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannelOperations.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannelOperations.java index 2989034053..e17dc8cd89 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannelOperations.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/QueueChannelOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.integration.channel; import java.util.List; import org.springframework.integration.core.MessageSelector; +import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -50,12 +51,14 @@ public interface QueueChannelOperations { * Obtain the current number of queued {@link Message Messages} in this channel. * @return The current number of queued {@link Message Messages} in this channel. */ + @ManagedAttribute(description = "Queue size") int getQueueSize(); /** * Obtain the remaining capacity of this channel. * @return The remaining capacity of this channel. */ + @ManagedAttribute(description = "Queue remaining capacity") int getRemainingCapacity(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java index 75c9e7a6cc..038b4b6d55 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java @@ -22,9 +22,9 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.Lifecycle; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.support.channel.ChannelResolverUtils; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; @@ -43,7 +43,7 @@ import org.springframework.util.Assert; * @author Artem Bilan */ @ManagedResource -public class WireTap implements ChannelInterceptor, Lifecycle, VetoCapableInterceptor, BeanFactoryAware { +public class WireTap implements ChannelInterceptor, ManageableLifecycle, VetoCapableInterceptor, BeanFactoryAware { private static final Log LOGGER = LogFactory.getLog(WireTap.class); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java index bd30a54e47..bafaedc46a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegrationManagement.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.Import; -import org.springframework.core.annotation.AliasFor; /** * Enables default configuring of management in Spring Integration components in an existing application. @@ -41,83 +40,6 @@ import org.springframework.core.annotation.AliasFor; @Import(IntegrationManagementConfiguration.class) public @interface EnableIntegrationManagement { - /** - * A list of simple patterns for component names for which message counts will be - * enabled (defaults to '*'). Enables message - * counting (`sendCount`, `errorCount`, `receiveCount`) for those components that - * support counters (channels, message handlers, etc). This is the initial setting - * only, individual components can have counts enabled/disabled at runtime. May be - * overridden by an entry in {@link #statsEnabled() statsEnabled} which is additional - * functionality over simple counts. If a pattern starts with `!`, counts are disabled - * for matches. For components that match multiple patterns, the first pattern wins. - * Disabling counts at runtime also disables stats. - * Defaults to no components, unless JMX is enabled in which case, defaults to all - * components. Overrides {@link #defaultCountsEnabled()} for matching bean names. - * @return the patterns. - * @deprecated in favor of 'metersEnabled'. - */ - @Deprecated - @AliasFor("metersEnabled") - String[] countsEnabled() default "*"; - - /** - * A list of simple patterns for component names for which message counts will be - * enabled (defaults to '*'). Enables message - * counting (`sendCount`, `errorCount`, `receiveCount`) for those components that - * support counters (channels, message handlers, etc). This is the initial setting - * only, individual components can have counts enabled/disabled at runtime. May be - * overridden by an entry in {@link #statsEnabled() statsEnabled} which is additional - * functionality over simple counts. If a pattern starts with `!`, counts are disabled - * for matches. For components that match multiple patterns, the first pattern wins. - * Disabling counts at runtime also disables stats. - * Defaults to no components, unless JMX is enabled in which case, defaults to all - * components. Overrides {@link #defaultCountsEnabled()} for matching bean names. - * @return the patterns. - */ - @AliasFor("countsEnabled") - String[] metersEnabled() default "*"; - - /** - * A list of simple patterns for component names for which message statistics will be - * enabled (response times, rates etc), as well as counts (a positive match here - * overrides {@link #countsEnabled() countsEnabled}, you can't have statistics without - * counts). (defaults to '*'). Enables - * statistics for those components that support statistics (channels - when sending, - * message handlers, etc). This is the initial setting only, individual components can - * have stats enabled/disabled at runtime. If a pattern starts with `!`, stats (and - * counts) are disabled for matches. Note: this means that '!foo' here will disable - * stats and counts for 'foo' even if counts are enabled for 'foo' in - * {@link #countsEnabled() countsEnabled}. For components - * that match multiple patterns, the first pattern wins. Enabling stats at runtime - * also enables counts. - * Defaults to no components, unless JMX is enabled in which case, defaults to all - * components. - * @return the patterns. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - */ - @Deprecated - String[] statsEnabled() default "*"; - - /** - * The default setting for enabling counts when a bean name is not matched by - * {@link #countsEnabled() countsEnabled}. - * @return the value; false by default, or true when JMX is enabled. - */ - String defaultCountsEnabled() default "false"; - - /** - * The default setting for enabling statistics when a bean name is not matched by - * {@link #statsEnabled() statsEnabled}. - * @return the value; false by default, or true when JMX is enabled. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - */ - @Deprecated - String defaultStatsEnabled() default "false"; - /** * Use to disable all logging in the main message flow in framework components. When 'false', such logging will be * skipped, regardless of logging level. When 'true', the logging is controlled as normal by the logging @@ -138,15 +60,4 @@ public @interface EnableIntegrationManagement { */ String defaultLoggingEnabled() default "true"; - /** - * The bean name of a {@code MetricsFactory}. The {@code DefaultMetricsFactory} is used - * if omitted. - * @return the bean name. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - */ - @Deprecated - String metricsFactory() default ""; - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java index ef790cee7a..0527eda525 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,6 @@ package org.springframework.integration.config; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Map; import org.springframework.beans.factory.config.BeanDefinition; @@ -31,7 +28,6 @@ import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotationMetadata; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; /** * {@code @Configuration} class that registers a {@link IntegrationManagementConfigurer} bean. @@ -64,45 +60,14 @@ public class IntegrationManagementConfiguration implements ImportAware, Environm "@EnableIntegrationManagement is not present on importing class " + importMetadata.getClassName()); } - @SuppressWarnings("deprecation") @Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME) @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public IntegrationManagementConfigurer managementConfigurer() { IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer(); - setupCountsEnabledNamePatterns(configurer); - setupStatsEnabledNamePatterns(configurer); configurer.setDefaultLoggingEnabled( Boolean.parseBoolean(this.environment.resolvePlaceholders( (String) this.attributes.get("defaultLoggingEnabled")))); - configurer.setDefaultCountsEnabled( - Boolean.parseBoolean(this.environment.resolvePlaceholders( - (String) this.attributes.get("defaultCountsEnabled")))); - configurer.setDefaultStatsEnabled( - Boolean.parseBoolean(this.environment.resolvePlaceholders( - (String) this.attributes.get("defaultStatsEnabled")))); - configurer.setMetricsFactoryBeanName((String) this.attributes.get("metricsFactory")); return configurer; } - private void setupCountsEnabledNamePatterns(IntegrationManagementConfigurer configurer) { - List patterns = new ArrayList<>(); - String[] countsEnabled = this.attributes.getStringArray("countsEnabled"); - for (String managedComponent : countsEnabled) { - String pattern = this.environment.resolvePlaceholders(managedComponent); - patterns.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(pattern))); - } - configurer.setEnabledCountsPatterns(patterns.toArray(new String[0])); - } - - @SuppressWarnings("deprecation") - private void setupStatsEnabledNamePatterns(IntegrationManagementConfigurer configurer) { - List patterns = new ArrayList<>(); - String[] statsEnabled = this.attributes.getStringArray("statsEnabled"); - for (String managedComponent : statsEnabled) { - String pattern = this.environment.resolvePlaceholders(managedComponent); - patterns.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(pattern))); - } - configurer.setEnabledStatsPatterns(patterns.toArray(new String[0])); - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java index fecbeb45f1..7b8bf62203 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java @@ -16,18 +16,15 @@ package org.springframework.integration.config; -import java.util.Arrays; -import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.SmartInitializingSingleton; -import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.integration.core.MessageSource; @@ -35,12 +32,10 @@ import org.springframework.integration.support.management.IntegrationManagement; import org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides; import org.springframework.integration.support.management.metrics.MetricsCaptor; import org.springframework.integration.support.management.micrometer.MicrometerMetricsCaptor; -import org.springframework.integration.support.utils.PatternMatchUtils; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; /** @@ -55,46 +50,20 @@ import org.springframework.util.StringUtils; * @since 4.2 * */ -@SuppressWarnings("deprecation") public class IntegrationManagementConfigurer - implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware, - DestructionAwareBeanPostProcessor { - - private static final Log LOGGER = LogFactory.getLog(IntegrationManagementConfigurer.class); + implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware, BeanPostProcessor { + /** + * Bean name of tehe configurer. + */ public static final String MANAGEMENT_CONFIGURER_NAME = "integrationManagementConfigurer"; - private final Map - channelsByName = new HashMap<>(); - - private final Map - handlersByName = new HashMap<>(); - - private final Map - sourcesByName = new HashMap<>(); - - private final Map - sourceConfigurers = new HashMap<>(); - private ApplicationContext applicationContext; private String beanName; private boolean defaultLoggingEnabled = true; - private Boolean defaultCountsEnabled = false; - - private Boolean defaultStatsEnabled = false; - - private org.springframework.integration.support.management.MetricsFactory metricsFactory; - - private String metricsFactoryBeanName; - - private String[] enabledCountsPatterns = { }; - - private String[] enabledStatsPatterns = { }; - private volatile boolean singletonsInstantiated; private MetricsCaptor metricsCaptor; @@ -109,115 +78,6 @@ public class IntegrationManagementConfigurer this.beanName = name; } - /** - * Set a metrics factory. - * Has a precedence over {@link #metricsFactoryBeanName}. - * Defaults to {@link org.springframework.integration.support.management.DefaultMetricsFactory}. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @param metricsFactory the factory. - * @since 4.2 - */ - @Deprecated - public void setMetricsFactory(org.springframework.integration.support.management.MetricsFactory metricsFactory) { - this.metricsFactory = metricsFactory; - } - - /** - * Set a metrics factory bean name. - * Is used if {@link #metricsFactory} isn't specified. - * @param metricsFactory the factory. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @since 4.2 - */ - @Deprecated - public void setMetricsFactoryBeanName(String metricsFactory) { - this.metricsFactoryBeanName = metricsFactory; - } - - /** - * Set the array of simple patterns for component names for which message counts will - * be enabled (defaults to '*'). - * Enables message counting (`sendCount`, `errorCount`, `receiveCount`) - * for those components that support counters (channels, message handlers, etc). - * This is the initial setting only, individual components can have counts - * enabled/disabled at runtime. May be overridden by an entry in - * {@link #setEnabledStatsPatterns(String[]) enabledStatsPatterns} which is additional - * functionality over simple counts. If a pattern starts with `!`, counts are disabled - * for matches. For components that match multiple patterns, the first pattern wins. - * Disabling counts at runtime also disables stats. - * @param enabledCountsPatterns the patterns. - */ - public void setEnabledCountsPatterns(String[] enabledCountsPatterns) { - Assert.notEmpty(enabledCountsPatterns, "enabledCountsPatterns must not be empty"); - this.enabledCountsPatterns = Arrays.copyOf(enabledCountsPatterns, enabledCountsPatterns.length); - } - - /** - * Set the array of simple patterns for component names for which message statistics - * will be enabled (response times, rates etc), as well as counts (a positive match - * here overrides {@link #setEnabledCountsPatterns(String[]) enabledCountsPatterns}, - * you can't have statistics without counts). (defaults to '*'). - * Enables statistics for those components that support statistics - * (channels - when sending, message handlers, etc). This is the initial setting only, - * individual components can have stats enabled/disabled at runtime. If a pattern - * starts with `!`, stats (and counts) are disabled for matches. Note: this means that - * '!foo' here will disable stats and counts for 'foo' even if counts are enabled for - * 'foo' in {@link #setEnabledCountsPatterns(String[]) enabledCountsPatterns}. For - * components that match multiple patterns, the first pattern wins. Enabling stats at - * runtime also enables counts. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @param enabledStatsPatterns the patterns. - */ - @Deprecated - public void setEnabledStatsPatterns(String[] enabledStatsPatterns) { - Assert.notEmpty(enabledStatsPatterns, "enabledStatsPatterns must not be empty"); - this.enabledStatsPatterns = Arrays.copyOf(enabledStatsPatterns, enabledStatsPatterns.length); - } - - /** - * Set whether managed components maintain message counts by default. - * Defaults to false, unless an Integration MBean Exporter is configured. - * @param defaultCountsEnabled true to enable. - */ - public void setDefaultCountsEnabled(Boolean defaultCountsEnabled) { - this.defaultCountsEnabled = defaultCountsEnabled; - } - - public Boolean getDefaultCountsEnabled() { - return this.defaultCountsEnabled; - } - - /** - * Set whether managed components maintain message statistics by default. - * Defaults to false, unless an Integration MBean Exporter is configured. - * @param defaultStatsEnabled true to enable. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - */ - @Deprecated - public void setDefaultStatsEnabled(Boolean defaultStatsEnabled) { - this.defaultStatsEnabled = defaultStatsEnabled; - } - - /** - * Return true if stats are enabled by default. - * @return the stats enabled. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - */ - @Deprecated - public Boolean getDefaultStatsEnabled() { - return this.defaultStatsEnabled; - } - /** * Disable all logging in the normal message flow in framework components. When 'false', such logging will be * skipped, regardless of logging level. When 'true', the logging is controlled as normal by the logging @@ -254,23 +114,6 @@ public class IntegrationManagementConfigurer injectCaptor(); registerComponentGauges(); } - if (this.metricsFactory == null && StringUtils.hasText(this.metricsFactoryBeanName)) { - this.metricsFactory = this.applicationContext.getBean(this.metricsFactoryBeanName, - org.springframework.integration.support.management.MetricsFactory.class); - } - if (this.metricsFactory == null) { - Map - factories = this.applicationContext - .getBeansOfType(org.springframework.integration.support.management.MetricsFactory.class); - if (factories.size() == 1) { - this.metricsFactory = factories.values().iterator().next(); - } - } - if (this.metricsFactory == null) { - this.metricsFactory = new org.springframework.integration.support.management.DefaultMetricsFactory(); - } - this.sourceConfigurers.putAll(this.applicationContext.getBeansOfType( - org.springframework.integration.support.management.MessageSourceMetricsConfigurer.class)); Map managed = this.applicationContext .getBeansOfType(IntegrationManagement.class); for (Entry entry : managed.entrySet()) { @@ -279,7 +122,6 @@ public class IntegrationManagementConfigurer bean.setLoggingEnabled(this.defaultLoggingEnabled); } String name = entry.getKey(); - doConfigureMetrics(bean, name); } this.singletonsInstantiated = true; } @@ -302,147 +144,10 @@ public class IntegrationManagementConfigurer if (this.metricsCaptor != null && bean instanceof IntegrationManagement) { ((IntegrationManagement) bean).registerMetricsCaptor(this.metricsCaptor); } - return doConfigureMetrics(bean, name); } return bean; } - @Override - public boolean requiresDestruction(Object bean) { - return bean instanceof org.springframework.integration.support.management.MessageChannelMetrics || - bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics || - bean instanceof org.springframework.integration.support.management.MessageSourceMetrics; - } - - @Override - public void postProcessBeforeDestruction(Object bean, String nameOfBean) throws BeansException { - if (bean instanceof org.springframework.integration.support.management.MessageChannelMetrics) { - this.channelsByName.remove(nameOfBean); - } - else if (bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics) { - if (this.handlersByName.remove(nameOfBean) == null) { - this.handlersByName.remove(nameOfBean + ".handler"); - } - } - else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics && - this.sourcesByName.remove(nameOfBean) == null) { - - this.sourcesByName.remove(nameOfBean + ".source"); - } - } - - private Object doConfigureMetrics(Object bean, String name) { - if (bean instanceof org.springframework.integration.support.management.MessageChannelMetrics) { - configureChannelMetrics(name, - (org.springframework.integration.support.management.MessageChannelMetrics) bean); - } - else if (bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics) { - configureHandlerMetrics(name, - (org.springframework.integration.support.management.MessageHandlerMetrics) bean); - } - else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics) { - configureSourceMetrics(name, - (org.springframework.integration.support.management.MessageSourceMetrics) bean); - this.sourceConfigurers.values().forEach(c -> c - .configure((org.springframework.integration.support.management.MessageSourceMetrics) bean, name)); - } - return bean; - } - - @SuppressWarnings("unchecked") - private void configureChannelMetrics(String name, - org.springframework.integration.support.management.MessageChannelMetrics bean) { - - org.springframework.integration.support.management.AbstractMessageChannelMetrics metrics; - if (bean instanceof org.springframework.integration.support.management.PollableChannelManagement) { - metrics = this.metricsFactory.createPollableChannelMetrics(name); - } - else { - metrics = this.metricsFactory.createChannelMetrics(name); - } - Assert.state(metrics != null, "'metrics' must not be null"); - ManagementOverrides overrides = getOverrides(bean); - 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 org.springframework.integration.support.management.ConfigurableMetricsAware - && !overrides.metricsConfigured) { - ((org.springframework.integration.support.management.ConfigurableMetricsAware< - org.springframework.integration.support.management.AbstractMessageChannelMetrics>) bean) - .configureMetrics(metrics); - } - this.channelsByName.put(name, bean); - } - - @SuppressWarnings("unchecked") - private void configureHandlerMetrics(String name, - org.springframework.integration.support.management.MessageHandlerMetrics bean) { - org.springframework.integration.support.management.AbstractMessageHandlerMetrics metrics - = this.metricsFactory.createHandlerMetrics(name); - Assert.state(metrics != null, "'metrics' must not be null"); - ManagementOverrides overrides = getOverrides(bean); - 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 org.springframework.integration.support.management.ConfigurableMetricsAware - && !overrides.metricsConfigured) { - ((org.springframework.integration.support.management.ConfigurableMetricsAware< - org.springframework.integration.support.management.AbstractMessageHandlerMetrics>) bean) - .configureMetrics(metrics); - } - - this.handlersByName.put(bean.getManagedName() != null ? bean.getManagedName() : name, bean); - } - - private void configureSourceMetrics(String name, - org.springframework.integration.support.management.MessageSourceMetrics bean) { - - Boolean enabled = PatternMatchUtils.smartMatch(name, this.enabledCountsPatterns); - if (enabled != null) { - bean.setCountsEnabled(enabled); - } - else { - if (!getOverrides(bean).countsConfigured) { - bean.setCountsEnabled(this.defaultCountsEnabled); - } - } - this.sourcesByName.put(bean.getManagedName() != null ? bean.getManagedName() : name, bean); - } - private void registerComponentGauges() { this.metricsCaptor.gaugeBuilder("spring.integration.channels", this, (c) -> this.applicationContext.getBeansOfType(MessageChannel.class).size()) @@ -460,56 +165,6 @@ public class IntegrationManagementConfigurer .build(); } - public String[] getChannelNames() { - return this.channelsByName.keySet().toArray(new String[0]); - } - - public String[] getHandlerNames() { - return this.handlersByName.keySet().toArray(new String[0]); - } - - public String[] getSourceNames() { - return this.sourcesByName.keySet().toArray(new String[0]); - } - - public org.springframework.integration.support.management.MessageChannelMetrics getChannelMetrics(String name) { - if (this.channelsByName.containsKey(name)) { - return this.channelsByName.get(name); - } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("No channel found for (" + name + ")"); - } - return null; - } - - public org.springframework.integration.support.management.MessageHandlerMetrics getHandlerMetrics(String name) { - if (this.handlersByName.containsKey(name)) { - return this.handlersByName.get(name); - } - if (this.handlersByName.containsKey(name + ".handler")) { - return this.handlersByName.get(name + ".handler"); - } - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("No handler found for (" + name + ")"); - } - return null; - } - - public org.springframework.integration.support.management.MessageSourceMetrics getSourceMetrics(String name) { - if (this.sourcesByName.containsKey(name)) { - return this.sourcesByName.get(name); - } - if (this.sourcesByName.containsKey(name + ".source")) { - return this.sourcesByName.get(name + ".source"); - } - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("No source found for (" + name + ")"); - } - return null; - } - private static ManagementOverrides getOverrides(IntegrationManagement bean) { return bean.getOverrides() != null ? bean.getOverrides() : new ManagementOverrides(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationManagementParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationManagementParser.java index d8f5e14600..f9aa727433 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationManagementParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationManagementParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,13 +46,6 @@ public class IntegrationManagementParser extends AbstractBeanDefinitionParser { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationManagementConfigurer.class); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-logging-enabled"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-counts-enabled"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-stats-enabled"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "counts-enabled-patterns", - "enabledCountsPatterns"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "stats-enabled-patterns", - "enabledStatsPatterns"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "metrics-factory"); return builder.getBeanDefinition(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/Pausable.java b/spring-integration-core/src/main/java/org/springframework/integration/core/Pausable.java index 9883648dae..4fb4fb1325 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/Pausable.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/Pausable.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ package org.springframework.integration.core; -import org.springframework.context.Lifecycle; +import org.springframework.integration.support.management.ManageableLifecycle; +import org.springframework.jmx.export.annotation.ManagedOperation; /** * Endpoints implementing this interface can be paused/resumed. A paused endpoint might @@ -27,16 +28,18 @@ import org.springframework.context.Lifecycle; * @since 5.0.3 * */ -public interface Pausable extends Lifecycle { +public interface Pausable extends ManageableLifecycle { /** * Pause the endpoint. */ + @ManagedOperation(description = "Pause the component") void pause(); /** * Resume the endpoint if paused. */ + @ManagedOperation(description = "Resume the component") void resume(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowAdapter.java index 22865db52a..229fc18881 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowAdapter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowAdapter.java @@ -22,10 +22,10 @@ import java.util.function.Supplier; import org.reactivestreams.Publisher; -import org.springframework.context.SmartLifecycle; import org.springframework.integration.core.MessageSource; import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.gateway.MessagingGatewaySupport; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -58,7 +58,7 @@ import org.springframework.util.Assert; * * @since 5.0 */ -public abstract class IntegrationFlowAdapter implements IntegrationFlow, SmartLifecycle { +public abstract class IntegrationFlowAdapter implements IntegrationFlow, ManageableSmartLifecycle { private final AtomicBoolean running = new AtomicBoolean(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java index c3af2f9e61..4bed3678d1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/StandardIntegrationFlow.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import org.springframework.context.SmartLifecycle; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.messaging.MessageChannel; /** @@ -65,7 +66,7 @@ import org.springframework.messaging.MessageChannel; * @see org.springframework.integration.dsl.context.IntegrationFlowContext * @see SmartLifecycle */ -public class StandardIntegrationFlow implements IntegrationFlow, SmartLifecycle { +public class StandardIntegrationFlow implements IntegrationFlow, ManageableSmartLifecycle { private final Map integrationComponents; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java index 5bdde86d77..f4b940e416 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.context.IntegrationProperties; import org.springframework.integration.support.SmartLifecycleRoleController; +import org.springframework.integration.support.management.IntegrationManagedResource; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.util.PatternMatchUtils; import org.springframework.util.StringUtils; @@ -44,8 +46,9 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @author Artem Bilan */ +@IntegrationManagedResource public abstract class AbstractEndpoint extends IntegrationObjectSupport - implements SmartLifecycle, DisposableBean { + implements ManageableSmartLifecycle, DisposableBean { private boolean autoStartupSetExplicitly; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java index e6badc42e3..8ee5140fa5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java @@ -28,6 +28,7 @@ import org.springframework.integration.core.MessageSource; import org.springframework.integration.expression.ExpressionEvalMap; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.integration.support.context.NamedComponent; +import org.springframework.integration.support.management.IntegrationInboundManagement; import org.springframework.integration.support.management.IntegrationManagedResource; import org.springframework.integration.support.management.metrics.CounterFacade; import org.springframework.integration.support.management.metrics.MeterFacade; @@ -38,6 +39,10 @@ import org.springframework.messaging.Message; import org.springframework.util.CollectionUtils; /** + * Abstract message source. + * + * @param The payload type. + * * @author Mark Fisher * @author Oleg Zhurakousky * @author Gary Russell @@ -45,11 +50,9 @@ import org.springframework.util.CollectionUtils; * * @since 2.0 */ -@SuppressWarnings("deprecation") @IntegrationManagedResource public abstract class AbstractMessageSource extends AbstractExpressionEvaluator - implements MessageSource, org.springframework.integration.support.management.MessageSourceMetrics, - NamedComponent, BeanNameAware { + implements MessageSource, IntegrationInboundManagement, NamedComponent, BeanNameAware { private final AtomicLong messageCount = new AtomicLong(); @@ -65,8 +68,6 @@ public abstract class AbstractMessageSource extends AbstractExpressionEvaluat private String managedName; - private boolean countsEnabled; - private boolean loggingEnabled = true; private MetricsCaptor metricsCaptor; @@ -119,17 +120,6 @@ public abstract class AbstractMessageSource extends AbstractExpressionEvaluat return this.beanName; } - @Override - public boolean isCountsEnabled() { - return this.countsEnabled; - } - - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.countsEnabled = countsEnabled; - this.managementOverrides.countsConfigured = true; - } - @Override public boolean isLoggingEnabled() { return this.loggingEnabled; @@ -141,38 +131,6 @@ public abstract class AbstractMessageSource extends AbstractExpressionEvaluat this.managementOverrides.loggingConfigured = true; } - /** - * Deprecated. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void reset() { - this.messageCount.set(0); - } - - /** - * Deprecated. - * @return count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getMessageCount() { - return (int) this.messageCount.get(); - } - - /** - * Deprecated. - * @return count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getMessageCountLong() { - return this.messageCount.get(); - } - @Override public ManagementOverrides getOverrides() { return this.managementOverrides; @@ -222,12 +180,10 @@ public abstract class AbstractMessageSource extends AbstractExpressionEvaluat .copyHeaders(headers) .build(); } - if (this.countsEnabled) { - if (this.metricsCaptor != null) { - incrementReceiveCounter(); - } - this.messageCount.incrementAndGet(); + if (this.metricsCaptor != null) { + incrementReceiveCounter(); } + this.messageCount.incrementAndGet(); return (Message) message; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java index 92251a4183..28acc65ef9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/MethodInvokingMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.integration.endpoint; import java.lang.reflect.Method; import org.springframework.context.Lifecycle; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -31,7 +32,7 @@ import org.springframework.util.ReflectionUtils; * @author Gary Russell * @author Artem Bilan */ -public class MethodInvokingMessageSource extends AbstractMessageSource implements Lifecycle { +public class MethodInvokingMessageSource extends AbstractMessageSource implements ManageableLifecycle { private volatile Object object; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/AbstractMessageProcessingSelector.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/AbstractMessageProcessingSelector.java index cb4937c9f5..39bc7f17cf 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/AbstractMessageProcessingSelector.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/AbstractMessageProcessingSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.core.convert.ConversionService; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.handler.AbstractMessageProcessor; import org.springframework.integration.handler.MessageProcessor; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -35,7 +36,7 @@ import org.springframework.util.Assert; * @author Artem Bilan */ public abstract class AbstractMessageProcessingSelector - implements MessageSelector, BeanFactoryAware, Lifecycle { + implements MessageSelector, BeanFactoryAware, ManageableLifecycle { private final MessageProcessor messageProcessor; @@ -52,12 +53,14 @@ public abstract class AbstractMessageProcessingSelector } } + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (this.messageProcessor instanceof BeanFactoryAware) { ((BeanFactoryAware) this.messageProcessor).setBeanFactory(beanFactory); } } + @Override public final boolean accept(Message message) { Object result = this.messageProcessor.processMessage(message); Assert.notNull(result, "result must not be null"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java index 2c87872402..049018db24 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/filter/MessageFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.integration.MessageRejectedException; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.handler.AbstractReplyProducingPostProcessingMessageHandler; import org.springframework.integration.handler.DiscardingMessageHandler; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; @@ -45,7 +46,7 @@ import org.springframework.util.Assert; * @author David Liu */ public class MessageFilter extends AbstractReplyProducingPostProcessingMessageHandler - implements DiscardingMessageHandler, Lifecycle { + implements DiscardingMessageHandler, ManageableLifecycle { private final MessageSelector selector; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java index 839ec77404..3bfce1f45c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ package org.springframework.integration.gateway; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -31,7 +31,7 @@ import org.springframework.messaging.MessageChannel; * * @since 5.0 */ -public class GatewayMessageHandler extends AbstractReplyProducingMessageHandler implements Lifecycle { +public class GatewayMessageHandler extends AbstractReplyProducingMessageHandler implements ManageableLifecycle { private final GatewayProxyFactoryBean gatewayProxyFactoryBean; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java index 18be66e860..72d7d31ec9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java @@ -17,7 +17,6 @@ package org.springframework.integration.gateway; import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; @@ -46,6 +45,7 @@ import org.springframework.integration.support.ErrorMessageUtils; import org.springframework.integration.support.MessageBuilderFactory; import org.springframework.integration.support.MutableMessageBuilder; import org.springframework.integration.support.converter.SimpleMessageConverter; +import org.springframework.integration.support.management.IntegrationInboundManagement; import org.springframework.integration.support.management.IntegrationManagedResource; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -77,7 +77,7 @@ import reactor.core.publisher.MonoProcessor; @IntegrationManagedResource public abstract class MessagingGatewaySupport extends AbstractEndpoint implements org.springframework.integration.support.management.TrackableComponent, - org.springframework.integration.support.management.MessageSourceMetrics, IntegrationPattern { + IntegrationInboundManagement, IntegrationPattern { private static final long DEFAULT_TIMEOUT = 1000L; @@ -92,8 +92,6 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint private boolean errorOnTimeout; - private final AtomicLong messageCount = new AtomicLong(); - private final ManagementOverrides managementOverrides = new ManagementOverrides(); private ErrorMessageStrategy errorMessageStrategy = new DefaultErrorMessageStrategy(); @@ -114,14 +112,12 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint private InboundMessageMapper requestMapper = new DefaultRequestMapper(); + private boolean loggingEnabled = true; + private String managedType; private String managedName; - private boolean countsEnabled; - - private boolean loggingEnabled = true; - private volatile AbstractEndpoint replyMessageCorrelator; private volatile boolean initialized; @@ -274,36 +270,6 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint this.historyWritingPostProcessor.setShouldTrack(shouldTrack); } - @Override - public int getMessageCount() { - return (int) this.messageCount.get(); - } - - @Override - public long getMessageCountLong() { - return this.messageCount.get(); - } - - @Override - public void setManagedName(String name) { - this.managedName = name; - } - - @Override - public String getManagedName() { - return this.managedName; - } - - @Override - public void setManagedType(String type) { - this.managedType = type; - } - - @Override - public String getManagedType() { - return this.managedType; - } - @Override public String getComponentType() { return "gateway"; @@ -320,17 +286,6 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint return this.loggingEnabled; } - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.countsEnabled = countsEnabled; - this.managementOverrides.countsConfigured = true; - } - - @Override - public boolean isCountsEnabled() { - return this.countsEnabled; - } - /** * Set an {@link ErrorMessageStrategy} to use to build an error message when a exception occurs. * Default is the {@link DefaultErrorMessageStrategy}. @@ -347,6 +302,26 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint return this.managementOverrides; } + @Override + public void setManagedType(String managedType) { + this.managedType = managedType; + } + + @Override + public String getManagedType() { + return this.managedType; + } + + @Override + public void setManagedName(String managedName) { + this.managedName = managedName; + } + + @Override + public String getManagedName() { + return this.managedName; + } + @Override public IntegrationPatternType getIntegrationPatternType() { return IntegrationPatternType.inbound_gateway; @@ -430,9 +405,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint Assert.state(channel != null, "send is not supported, because no request channel has been configured"); try { - if (this.countsEnabled) { - this.messageCount.incrementAndGet(); - } + // TODO Micrometer counter this.messagingTemplate.convertAndSend(channel, object, this.historyWritingPostProcessor); } catch (Exception e) { @@ -507,9 +480,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint Object reply; Message requestMessage = null; try { - if (this.countsEnabled) { - this.messageCount.incrementAndGet(); - } + // TODO Micrometer counter if (shouldConvert) { reply = this.messagingTemplate.convertSendAndReceive(channel, object, Object.class, this.historyWritingPostProcessor); @@ -675,8 +646,8 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint return reply .doOnSubscribe(s -> { - if (!error && this.countsEnabled) { - this.messageCount.incrementAndGet(); + if (!error) { + // TODO Micrometer counter } }) .>map(replyMessage -> { @@ -831,12 +802,6 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint } } - @Override - public void reset() { - this.messageCount.set(0); - } - - private static class DefaultRequestMapper implements InboundMessageMapper { private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/EndpointNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/EndpointNode.java index 973938301b..5a831d12ee 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/EndpointNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/EndpointNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ public abstract class EndpointNode extends IntegrationNode { private final String output; - protected EndpointNode(int nodeId, String name, Object nodeObject, String output, Stats stats) { - super(nodeId, name, nodeObject, stats); + protected EndpointNode(int nodeId, String name, Object nodeObject, String output) { + super(nodeId, name, nodeObject); this.output = output; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableEndpointNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableEndpointNode.java index 7cfdb97828..04d3f29c30 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableEndpointNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/ErrorCapableEndpointNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,8 @@ public class ErrorCapableEndpointNode extends EndpointNode implements ErrorCapab private final String errors; - protected ErrorCapableEndpointNode(int nodeId, String name, Object nodeObject, String output, String errors, - Stats stats) { - - super(nodeId, name, nodeObject, output, stats); + protected ErrorCapableEndpointNode(int nodeId, String name, Object nodeObject, String output, String errors) { + super(nodeId, name, nodeObject, output); this.errors = errors; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationNode.java index 1064e262e1..3b74bde5a8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,6 @@ public abstract class IntegrationNode { private final String nodeName; - private final Stats stats; - private final String componentType; @Nullable @@ -59,14 +57,13 @@ public abstract class IntegrationNode { private final Map unmodifiableProperties = Collections.unmodifiableMap(this.properties); - protected IntegrationNode(int nodeId, String name, Object nodeObject, Stats stats) { + protected IntegrationNode(int nodeId, String name, Object nodeObject) { this.nodeId = nodeId; this.nodeName = name; this.componentType = nodeObject instanceof NamedComponent ? ((NamedComponent) nodeObject).getComponentType() : nodeObject.getClass().getSimpleName(); - this.stats = stats; if (nodeObject instanceof ExpressionCapable) { Expression expression = ((ExpressionCapable) nodeObject).getExpression(); if (expression != null) { @@ -117,10 +114,6 @@ public abstract class IntegrationNode { return this.integrationPatternCategory; } - public Stats getStats() { - return this.stats.isAvailable() ? this.stats : null; - } - public Map getProperties() { return this.unmodifiableProperties; } @@ -147,16 +140,4 @@ public abstract class IntegrationNode { } } - public static class Stats { - - protected boolean isAvailable() { - return false; - } - - public String getDeprecated() { - return "stats are deprecated in favor of sendTimers and receiveCounters"; - } - - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageChannelNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageChannelNode.java index 4688b3531d..0d07cfc76e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageChannelNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageChannelNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,10 +36,7 @@ public class MessageChannelNode extends IntegrationNode implements SendTimersAwa private Supplier sendTimers; public MessageChannelNode(int nodeId, String name, MessageChannel channel) { - super(nodeId, name, channel, - channel instanceof org.springframework.integration.support.management.MessageChannelMetrics - ? new Stats((org.springframework.integration.support.management.MessageChannelMetrics) channel) - : new IntegrationNode.Stats()); + super(nodeId, name, channel); } @Nullable @@ -52,83 +49,4 @@ public class MessageChannelNode extends IntegrationNode implements SendTimersAwa this.sendTimers = timers; } - public static final class Stats extends IntegrationNode.Stats { - - private final org.springframework.integration.support.management.MessageChannelMetrics channel; - - Stats(org.springframework.integration.support.management.MessageChannelMetrics channel) { - this.channel = channel; - } - - @Override - protected boolean isAvailable() { - return this.channel.isCountsEnabled(); - } - - public boolean isCountsEnabled() { - return this.channel.isCountsEnabled(); - } - - public boolean isLoggingEnabled() { - return this.channel.isLoggingEnabled(); - } - - public long getSendCount() { - return this.channel.getSendCountLong(); - } - - public long getSendErrorCount() { - return this.channel.getSendErrorCountLong(); - } - - public double getTimeSinceLastSend() { - return this.channel.getTimeSinceLastSend(); - } - - public double getMeanSendRate() { - return this.channel.getMeanSendRate(); - } - - public double getMeanErrorRate() { - return this.channel.getMeanErrorRate(); - } - - public double getMeanErrorRatio() { - return this.channel.getMeanErrorRatio(); - } - - public double getMeanSendDuration() { - return this.channel.getMeanSendDuration(); - } - - public double getMinSendDuration() { - return this.channel.getMinSendDuration(); - } - - public double getMaxSendDuration() { - return this.channel.getMaxSendDuration(); - } - - public double getStandardDeviationSendDuration() { - return this.channel.getStandardDeviationSendDuration(); - } - - public org.springframework.integration.support.management.Statistics getSendDuration() { - return this.channel.getSendDuration(); - } - - public org.springframework.integration.support.management.Statistics getSendRate() { - return this.channel.getSendRate(); - } - - public org.springframework.integration.support.management.Statistics getErrorRate() { - return this.channel.getErrorRate(); - } - - public boolean isStatsEnabled() { - return this.channel.isStatsEnabled(); - } - - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageGatewayNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageGatewayNode.java index 0829326d3e..64d9bca501 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageGatewayNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageGatewayNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,27 +29,7 @@ import org.springframework.integration.gateway.MessagingGatewaySupport; public class MessageGatewayNode extends ErrorCapableEndpointNode { public MessageGatewayNode(int nodeId, String name, MessagingGatewaySupport gateway, String output, String errors) { - super(nodeId, name, gateway, output, errors, new Stats(gateway)); - } - - - public static final class Stats extends IntegrationNode.Stats { - - private final MessagingGatewaySupport gateway; - - Stats(MessagingGatewaySupport gateway) { - this.gateway = gateway; - } - - @Override - protected boolean isAvailable() { - return this.gateway.isCountsEnabled(); - } - - public long getSendCount() { - return this.gateway.getMessageCountLong(); - } - + super(nodeId, name, gateway, output, errors); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageHandlerNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageHandlerNode.java index c23ef1dc5d..1474343638 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageHandlerNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageHandlerNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.springframework.messaging.MessageHandler; * @since 4.3 * */ -@SuppressWarnings("deprecation") public class MessageHandlerNode extends EndpointNode implements SendTimersAware { private final String input; @@ -38,10 +37,7 @@ public class MessageHandlerNode extends EndpointNode implements SendTimersAware private Supplier sendTimers; public MessageHandlerNode(int nodeId, String name, MessageHandler handler, String input, String output) { - super(nodeId, name, handler, output, - handler instanceof org.springframework.integration.support.management.MessageHandlerMetrics - ? new Stats((org.springframework.integration.support.management.MessageHandlerMetrics) handler) - : new IntegrationNode.Stats()); + super(nodeId, name, handler, output); this.input = input; } @@ -59,64 +55,5 @@ public class MessageHandlerNode extends EndpointNode implements SendTimersAware this.sendTimers = timers; } - public static final class Stats extends IntegrationNode.Stats { - - private final org.springframework.integration.support.management.MessageHandlerMetrics handler; - - Stats(org.springframework.integration.support.management.MessageHandlerMetrics handler) { - this.handler = handler; - } - - @Override - protected boolean isAvailable() { - return this.handler.isCountsEnabled(); - } - - public boolean isLoggingEnabled() { - return this.handler.isLoggingEnabled(); - } - - public long getHandleCount() { - return this.handler.getHandleCountLong(); - } - - public long getErrorCount() { - return this.handler.getErrorCountLong(); - } - - public double getMeanDuration() { - return this.handler.getMeanDuration(); - } - - public double getMinDuration() { - return this.handler.getMinDuration(); - } - - public double getMaxDuration() { - return this.handler.getMaxDuration(); - } - - public double getStandardDeviationDuration() { - return this.handler.getStandardDeviationDuration(); - } - - public long getActiveCount() { - return this.handler.getActiveCountLong(); - } - - public org.springframework.integration.support.management.Statistics getDuration() { - return this.handler.getDuration(); - } - - public boolean isStatsEnabled() { - return this.handler.isStatsEnabled(); - } - - public boolean isCountsEnabled() { - return this.handler.isCountsEnabled(); - } - - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageProducerNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageProducerNode.java index 96c81b9d46..e59658afcd 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageProducerNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageProducerNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import org.springframework.integration.endpoint.MessageProducerSupport; public class MessageProducerNode extends ErrorCapableEndpointNode { public MessageProducerNode(int nodeId, String name, MessageProducerSupport producer, String output, String errors) { - super(nodeId, name, producer, output, errors, new IntegrationNode.Stats()); + super(nodeId, name, producer, output, errors); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageSourceNode.java b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageSourceNode.java index 10e4bdad19..b4f0e00922 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageSourceNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/graph/MessageSourceNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,17 +30,12 @@ import org.springframework.lang.Nullable; * @since 4.3 * */ -@SuppressWarnings("deprecation") public class MessageSourceNode extends ErrorCapableEndpointNode implements ReceiveCountersAware { private Supplier receiveCounters; public MessageSourceNode(int nodeId, String name, MessageSource messageSource, String output, String errors) { - super(nodeId, name, messageSource, output, errors, - messageSource instanceof org.springframework.integration.support.management.MessageSourceMetrics - ? new Stats( - (org.springframework.integration.support.management.MessageSourceMetrics) messageSource) - : new IntegrationNode.Stats()); + super(nodeId, name, messageSource, output, errors); } @Nullable @@ -53,24 +48,5 @@ public class MessageSourceNode extends ErrorCapableEndpointNode implements Recei this.receiveCounters = counters; } - public static final class Stats extends IntegrationNode.Stats { - - private final org.springframework.integration.support.management.MessageSourceMetrics source; - - Stats(org.springframework.integration.support.management.MessageSourceMetrics source) { - this.source = source; - } - - @Override - protected boolean isAvailable() { - return this.source.isCountsEnabled(); - } - - public long getMessageCount() { - return this.source.getMessageCountLong(); - } - - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java index 05f7062d9f..074385b876 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java @@ -38,44 +38,30 @@ public abstract class AbstractMessageHandler extends MessageHandlerSupport implements MessageHandler, CoreSubscriber> { @Override // NOSONAR - @SuppressWarnings("deprecation") public void handleMessage(Message message) { Message messageToUse = message; Assert.notNull(messageToUse, "Message must not be null"); if (isLoggingEnabled() && this.logger.isDebugEnabled()) { this.logger.debug(this + " received message: " + messageToUse); } - org.springframework.integration.support.management.MetricsContext start = null; SampleFacade sample = null; MetricsCaptor metricsCaptor = getMetricsCaptor(); - if (metricsCaptor != null && isCountsEnabled()) { + if (metricsCaptor != null) { sample = metricsCaptor.start(); } try { if (shouldTrack()) { messageToUse = MessageHistory.write(messageToUse, this, getMessageBuilderFactory()); } - org.springframework.integration.support.management.AbstractMessageHandlerMetrics handlerMetrics - = getHandlerMetrics(); - if (isCountsEnabled()) { - start = handlerMetrics.beforeHandle(); - handleMessageInternal(messageToUse); - if (sample != null) { - sample.stop(sendTimer()); - } - handlerMetrics.afterHandle(start, true); - } - else { - handleMessageInternal(messageToUse); + handleMessageInternal(messageToUse); + if (sample != null) { + sample.stop(sendTimer()); } } catch (Exception e) { if (sample != null) { sample.stop(buildSendTimer(false, e.getClass().getSimpleName())); } - if (isCountsEnabled()) { - getHandlerMetrics().afterHandle(start, false); - } throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(messageToUse, () -> "error occurred in message handler [" + this + "]", e); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java index 992bd147da..a05656d043 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.util.concurrent.locks.ReentrantLock; import org.springframework.context.Lifecycle; import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.core.MessageProducer; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -66,7 +67,7 @@ import org.springframework.util.Assert; * @author Artem Bilan */ public class MessageHandlerChain extends AbstractMessageProducingHandler - implements CompositeMessageHandler, Lifecycle { + implements CompositeMessageHandler, ManageableLifecycle { private final Object initializationMonitor = new Object(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerSupport.java index eb0fb04eee..6b3f5812a6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerSupport.java @@ -25,11 +25,11 @@ import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.context.Orderable; import org.springframework.integration.support.management.IntegrationManagedResource; +import org.springframework.integration.support.management.IntegrationManagement; import org.springframework.integration.support.management.TrackableComponent; import org.springframework.integration.support.management.metrics.MeterFacade; import org.springframework.integration.support.management.metrics.MetricsCaptor; import org.springframework.integration.support.management.metrics.TimerFacade; -import org.springframework.util.Assert; /** * Base class for Message handling components that provides basic validation and error @@ -47,13 +47,9 @@ import org.springframework.util.Assert; * @since 5.3 * */ -@SuppressWarnings("deprecation") @IntegrationManagedResource public abstract class MessageHandlerSupport extends IntegrationObjectSupport - implements org.springframework.integration.support.management.MessageHandlerMetrics, - org.springframework.integration.support.management.ConfigurableMetricsAware< - org.springframework.integration.support.management.AbstractMessageHandlerMetrics>, - TrackableComponent, Orderable, IntegrationPattern { + implements TrackableComponent, Orderable, IntegrationManagement, IntegrationPattern { private final ManagementOverrides managementOverrides = new ManagementOverrides(); @@ -61,19 +57,12 @@ public abstract class MessageHandlerSupport extends IntegrationObjectSupport private boolean shouldTrack = false; - private org.springframework.integration.support.management.AbstractMessageHandlerMetrics handlerMetrics - = new org.springframework.integration.support.management.DefaultMessageHandlerMetrics(); - - private boolean countsEnabled; - private boolean loggingEnabled = true; private MetricsCaptor metricsCaptor; private int order = Ordered.LOWEST_PRECEDENCE; - private boolean statsEnabled; - private String managedName; private String managedType; @@ -96,16 +85,6 @@ public abstract class MessageHandlerSupport extends IntegrationObjectSupport this.metricsCaptor = metricsCaptorToRegister; } - /** - * Deprecated. - * @return handler metrics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - protected org.springframework.integration.support.management.AbstractMessageHandlerMetrics getHandlerMetrics() { - return this.handlerMetrics; - } - protected MetricsCaptor getMetricsCaptor() { return this.metricsCaptor; } @@ -134,20 +113,6 @@ public abstract class MessageHandlerSupport extends IntegrationObjectSupport return this.shouldTrack; } - /** - * Deprecated. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void configureMetrics( - org.springframework.integration.support.management.AbstractMessageHandlerMetrics metrics) { - - Assert.notNull(metrics, "'metrics' must not be null"); - this.handlerMetrics = metrics; - this.managementOverrides.metricsConfigured = true; - } - @Override public ManagementOverrides getOverrides() { return this.managementOverrides; @@ -158,13 +123,6 @@ public abstract class MessageHandlerSupport extends IntegrationObjectSupport return IntegrationPatternType.outbound_channel_adapter; } - @Override - protected void onInit() { - if (this.statsEnabled) { - this.handlerMetrics.setFullStatsEnabled(true); - } - } - protected TimerFacade sendTimer() { if (this.successTimer == null) { this.successTimer = buildSendTimer(true, "none"); @@ -184,210 +142,18 @@ public abstract class MessageHandlerSupport extends IntegrationObjectSupport return timer; } - /** - * Deprecated. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void reset() { - this.handlerMetrics.reset(); - } - - /** - * Deprecated. - * @return handle count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getHandleCountLong() { - return this.handlerMetrics.getHandleCountLong(); - } - - /** - * Deprecated. - * @return handle count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getHandleCount() { - return this.handlerMetrics.getHandleCount(); - } - - /** - * Deprecated. - * @return error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getErrorCount() { - return this.handlerMetrics.getErrorCount(); - } - - /** - * Deprecated. - * @return error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getErrorCountLong() { - return this.handlerMetrics.getErrorCountLong(); - } - - /** - * Deprecated. - * @return mean duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMeanDuration() { - return this.handlerMetrics.getMeanDuration(); - } - - /** - * Deprecated. - * @return min duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMinDuration() { - return this.handlerMetrics.getMinDuration(); - } - - /** - * Deprecated. - * @return max duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getMaxDuration() { - return this.handlerMetrics.getMaxDuration(); - } - - /** - * Deprecated. - * @return standard deviation duration - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public double getStandardDeviationDuration() { - return this.handlerMetrics.getStandardDeviationDuration(); - } - - /** - * Deprecated. - * @return active count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getActiveCount() { - return this.handlerMetrics.getActiveCount(); - } - - /** - * Deprecated. - * @return active count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getActiveCountLong() { - return this.handlerMetrics.getActiveCountLong(); - } - - /** - * Deprecated. - * @return statistics - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public org.springframework.integration.support.management.Statistics getDuration() { - return this.handlerMetrics.getDuration(); - } - - /** - * Deprecated. - * @param statsEnabled the statsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void setStatsEnabled(boolean statsEnabled) { - if (statsEnabled) { - this.countsEnabled = true; - this.managementOverrides.countsConfigured = true; - } - this.statsEnabled = statsEnabled; - if (this.handlerMetrics != null) { - this.handlerMetrics.setFullStatsEnabled(statsEnabled); - } - this.managementOverrides.statsConfigured = true; - } - - /** - * Deprecated. - * @return statsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public boolean isStatsEnabled() { - return this.statsEnabled; - } - - /** - * Deprecated. - * @param countsEnabled the countsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.countsEnabled = countsEnabled; - this.managementOverrides.countsConfigured = true; - if (!countsEnabled) { - this.statsEnabled = false; - this.managementOverrides.statsConfigured = true; - } - } - - /** - * Deprecated. - * @return countsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public boolean isCountsEnabled() { - return this.countsEnabled; - } - - @Override public void setManagedName(String managedName) { this.managedName = managedName; } - @Override public String getManagedName() { return this.managedName; } - @Override public void setManagedType(String managedType) { this.managedType = managedType; } - @Override public String getManagedType() { return this.managedType; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java index 60e4a6cd42..a76b64576e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.integration.handler; import java.lang.reflect.Method; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.Lifecycle; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; @@ -32,7 +32,7 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Artem Bilan */ -public class MethodInvokingMessageHandler extends AbstractMessageHandler implements Lifecycle { +public class MethodInvokingMessageHandler extends AbstractMessageHandler implements ManageableLifecycle { private final MethodInvokingMessageProcessor processor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java index 2b7bfbcabb..aa5b5a2868 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,9 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.core.convert.ConversionService; import org.springframework.integration.handler.support.MessagingMethodInvokerHelper; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -42,7 +42,7 @@ import org.springframework.messaging.Message; * * @since 2.0 */ -public class MethodInvokingMessageProcessor extends AbstractMessageProcessor implements Lifecycle { +public class MethodInvokingMessageProcessor extends AbstractMessageProcessor implements ManageableLifecycle { private final MessagingMethodInvokerHelper delegate; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java index a36487ee8d..82ef0e1976 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.integration.handler; import org.springframework.context.Lifecycle; import org.springframework.integration.IntegrationPattern; import org.springframework.integration.IntegrationPatternType; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; @@ -37,7 +38,7 @@ import org.springframework.util.Assert; * @since 5.0 */ public class ReplyProducingMessageHandlerWrapper extends AbstractReplyProducingMessageHandler - implements Lifecycle { + implements ManageableLifecycle { private final MessageHandler target; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java index 25a9d88368..fa3e497810 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.core.convert.ConversionService; import org.springframework.integration.IntegrationPattern; import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -32,7 +33,7 @@ import org.springframework.messaging.Message; * @author Artem Bilan * @author Gary Russell */ -public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandler implements Lifecycle { +public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandler implements ManageableLifecycle { private final MessageProcessor processor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java index 94616b3b78..abf1fb398e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java @@ -77,6 +77,7 @@ import org.springframework.integration.support.NullAwarePayloadArgumentResolver; import org.springframework.integration.support.converter.ConfigurableCompositeMessageConverter; import org.springframework.integration.support.json.JsonObjectMapper; import org.springframework.integration.support.json.JsonObjectMapperProvider; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.util.AbstractExpressionEvaluator; import org.springframework.integration.util.AnnotatedMethodFilter; import org.springframework.integration.util.FixedMethodFilter; @@ -120,7 +121,7 @@ import org.springframework.util.StringUtils; * * @since 2.0 */ -public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator implements Lifecycle { +public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator implements ManageableLifecycle { private static final String CANDIDATE_METHODS = "CANDIDATE_METHODS"; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java index c237ed749b..013793ff75 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java @@ -31,8 +31,8 @@ import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; import org.springframework.beans.factory.support.BeanDefinitionValidationException; -import org.springframework.context.SmartLifecycle; import org.springframework.integration.support.management.IntegrationManagedResource; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.integration.support.management.TrackableComponent; import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.jmx.export.annotation.ManagedOperation; @@ -50,7 +50,8 @@ import org.springframework.util.StringUtils; */ @ManagedResource @IntegrationManagedResource -public class MessageHistoryConfigurer implements SmartLifecycle, BeanFactoryAware, DestructionAwareBeanPostProcessor { +public class MessageHistoryConfigurer implements ManageableSmartLifecycle, BeanFactoryAware, + DestructionAwareBeanPostProcessor { private static final Log LOGGER = LogFactory.getLog(MessageHistoryConfigurer.class); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java index 858c4f8669..c285aa2f9c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.context.Lifecycle; import org.springframework.core.convert.ConversionService; import org.springframework.integration.handler.AbstractMessageProcessor; import org.springframework.integration.handler.MessageProcessor; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -35,7 +36,7 @@ import org.springframework.util.Assert; * @since 2.0 */ class AbstractMessageProcessingRouter extends AbstractMappingMessageRouter - implements Lifecycle { + implements ManageableLifecycle { private final MessageProcessor messageProcessor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java index f43d642316..f8145e8eee 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java @@ -19,7 +19,6 @@ package org.springframework.integration.scattergather; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.context.Lifecycle; import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.channel.FixedSubscriberChannel; import org.springframework.integration.channel.QueueChannel; @@ -31,6 +30,7 @@ import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.endpoint.PollingConsumer; import org.springframework.integration.endpoint.ReactiveStreamsConsumer; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -53,7 +53,7 @@ import org.springframework.util.ClassUtils; * * @since 4.1 */ -public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler implements Lifecycle { +public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler implements ManageableLifecycle { private static final String GATHER_RESULT_CHANNEL = "gatherResultChannel"; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java index 4d4e724dab..6dacd40565 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.springframework.context.Lifecycle; import org.springframework.core.convert.ConversionService; import org.springframework.integration.handler.AbstractMessageProcessor; import org.springframework.integration.handler.MessageProcessor; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -35,7 +36,7 @@ import org.springframework.util.Assert; * @since 2.0 */ abstract class AbstractMessageProcessingSplitter extends AbstractMessageSplitter - implements Lifecycle { + implements ManageableLifecycle { private final MessageProcessor> messageProcessor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java index 3160c48d99..b17ec50d26 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupStoreReaper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java b/spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java index af525d5c56..f3f5718434 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java @@ -36,6 +36,7 @@ import org.springframework.integration.leader.DefaultCandidate; import org.springframework.integration.leader.event.DefaultLeaderEventPublisher; import org.springframework.integration.leader.event.LeaderEventPublisher; import org.springframework.integration.support.locks.LockRegistry; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.springframework.util.Assert; @@ -60,7 +61,8 @@ import org.springframework.util.Assert; * * @since 4.3.1 */ -public class LockRegistryLeaderInitiator implements SmartLifecycle, DisposableBean, ApplicationEventPublisherAware { +public class LockRegistryLeaderInitiator implements ManageableSmartLifecycle, DisposableBean, + ApplicationEventPublisherAware { public static final long DEFAULT_HEART_BEAT_TIME = 500L; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AbstractMessageChannelMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/AbstractMessageChannelMetrics.java deleted file mode 100644 index 690f9d6c19..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AbstractMessageChannelMetrics.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Abstract base class for channel metrics implementations. - * - * @author Gary Russell - * - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - **/ -@Deprecated -public abstract class AbstractMessageChannelMetrics implements ConfigurableMetrics { - - private static final String DEPRECATION = "deprecation"; - - protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR - final - - protected final String name; // NOSONAR - final - - private volatile boolean fullStatsEnabled; - - /** - * Construct an instance with the provided name. - * @param name the name. - */ - public AbstractMessageChannelMetrics(String name) { - this.name = name; - } - - /** - * When false, simple counts are maintained; when true complete statistics - * are maintained. - * @param fullStatsEnabled true for complete statistics. - */ - public void setFullStatsEnabled(boolean fullStatsEnabled) { - this.fullStatsEnabled = fullStatsEnabled; - } - - protected boolean isFullStatsEnabled() { - return this.fullStatsEnabled; - } - - /** - * Begin a send event. - * @return the context to be used in a subsequent {@link #afterSend(MetricsContext, boolean)} - * call. - */ - @SuppressWarnings(DEPRECATION) - public abstract MetricsContext beforeSend(); - - /** - * End a send event. Note that implementations typically will not validate that the - * context is of the correct type and not null; callers should take care to ensure - * the context is the object returned by the previous {@link #beforeSend()} call. - * @param context the context. - * @param result true for success, false otherwise. - */ - public abstract void afterSend(@SuppressWarnings(DEPRECATION) MetricsContext context, boolean result); - - /** - * Reset all counters/statistics. - */ - public abstract void reset(); - - public abstract int getSendCount(); - - public abstract long getSendCountLong(); - - public abstract int getSendErrorCount(); - - public abstract long getSendErrorCountLong(); - - public abstract double getTimeSinceLastSend(); - - public abstract double getMeanSendRate(); - - public abstract double getMeanErrorRate(); - - public abstract double getMeanErrorRatio(); - - public abstract double getMeanSendDuration(); - - public abstract double getMinSendDuration(); - - public abstract double getMaxSendDuration(); - - public abstract double getStandardDeviationSendDuration(); - - @SuppressWarnings(DEPRECATION) - public abstract Statistics getSendDuration(); - - @SuppressWarnings(DEPRECATION) - public abstract Statistics getSendRate(); - - @SuppressWarnings(DEPRECATION) - public abstract Statistics getErrorRate(); - - public abstract void afterReceive(); - - public abstract void afterError(); - - public abstract int getReceiveCount(); - - public abstract long getReceiveCountLong(); - - public abstract int getReceiveErrorCount(); - - public abstract long getReceiveErrorCountLong(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AbstractMessageHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/AbstractMessageHandlerMetrics.java deleted file mode 100644 index f1fc6510ec..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AbstractMessageHandlerMetrics.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Abstract base class for handler metrics implementations. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public abstract class AbstractMessageHandlerMetrics implements ConfigurableMetrics { - - protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR final - - protected final String name; // NOSONAR final - - private boolean fullStatsEnabled; - - public AbstractMessageHandlerMetrics(String name) { - this.name = name; - } - - /** - * When false, simple counts are maintained; when true complete statistics - * are maintained. - * @param fullStatsEnabled true for complete statistics. - */ - public void setFullStatsEnabled(boolean fullStatsEnabled) { - this.fullStatsEnabled = fullStatsEnabled; - } - - protected boolean isFullStatsEnabled() { - return this.fullStatsEnabled; - } - - /** - * Begin a handle event. - * @return the context to be used in the {@link #afterHandle(MetricsContext, boolean)}. - */ - public abstract MetricsContext beforeHandle(); - - /** - * End a handle event - * @param context the context from the previous {@link #beforeHandle()}. - * @param success true for success, false otherwise. - */ - public abstract void afterHandle(MetricsContext context, boolean success); - - public abstract void reset(); - - public abstract long getHandleCountLong(); - - public abstract int getHandleCount(); - - public abstract int getErrorCount(); - - public abstract long getErrorCountLong(); - - public abstract double getMeanDuration(); - - public abstract double getMinDuration(); - - public abstract double getMaxDuration(); - - public abstract double getStandardDeviationDuration(); - - public abstract int getActiveCount(); - - public abstract long getActiveCountLong(); - - public abstract Statistics getDuration(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMessageChannelMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMessageChannelMetrics.java deleted file mode 100644 index 45ab69ef96..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMessageChannelMetrics.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2009-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - - -/** - * An implementation of {@link MessageChannelMetrics} that aggregates the total response - * time over a sample, to avoid fetching the system time twice for every message. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class AggregatingMessageChannelMetrics extends DefaultMessageChannelMetrics { - - private static final int DEFAULT_SAMPLE_SIZE = 1000; - - private final int sampleSize; - - private long start; - - public AggregatingMessageChannelMetrics() { - this(null, DEFAULT_SAMPLE_SIZE); - } - - /** - * Construct an instance with default metrics with {@code window=10, period=1 second, - * lapsePeriod=1 minute}. - * @param name the name. - * @param sampleSize the sample size over which to aggregate the duration. - */ - public AggregatingMessageChannelMetrics(String name, int sampleSize) { - super(name); - this.sampleSize = sampleSize; - } - - /** - * Construct an instance with the supplied metrics. For proper representation of metrics, the - * supplied sendDuration must have a {@code factor=1000000.} and the the other arguments - * must be created with the {@code millis} constructor argument set to true. - * @param name the name. - * @param sendDuration an {@link ExponentialMovingAverage} for calculating the send duration. - * @param sendErrorRate an {@link ExponentialMovingAverageRate} for calculating the send error rate. - * @param sendSuccessRatio an {@link ExponentialMovingAverageRatio} for calculating the success ratio. - * @param sendRate an {@link ExponentialMovingAverageRate} for calculating the send rate. - * @param sampleSize the sample size over which to aggregate the duration. - */ - public AggregatingMessageChannelMetrics(String name, ExponentialMovingAverage sendDuration, - ExponentialMovingAverageRate sendErrorRate, ExponentialMovingAverageRatio sendSuccessRatio, - ExponentialMovingAverageRate sendRate, int sampleSize) { - super(name, sendDuration, sendErrorRate, sendSuccessRatio, sendRate); - this.sampleSize = sampleSize; - } - - @Override - public synchronized MetricsContext beforeSend() { - long count = this.sendCount.getAndIncrement(); - if (isFullStatsEnabled() && count % this.sampleSize == 0) { - this.start = System.nanoTime(); - this.sendRate.increment(this.start); - } - return new AggregatingChannelMetricsContext(this.start, count + 1); - } - - @Override - public void afterSend(MetricsContext context, boolean result) { - AggregatingChannelMetricsContext aggregatingContext = (AggregatingChannelMetricsContext) context; - long newCount = aggregatingContext.newCount; - if (result) { - if (isFullStatsEnabled() && newCount % this.sampleSize == 0) { - long now = System.nanoTime(); - this.sendSuccessRatio.success(now); - this.sendDuration.append(now - aggregatingContext.start); - } - } - else { - if (isFullStatsEnabled() && newCount % this.sampleSize == 0) { - long now = System.nanoTime(); - this.sendSuccessRatio.failure(now); - this.sendErrorRate.increment(now); - } - this.sendErrorCount.incrementAndGet(); - } - } - - protected static class AggregatingChannelMetricsContext extends DefaultChannelMetricsContext { - - protected long newCount; // NOSONAR - - public AggregatingChannelMetricsContext(long start, long newCount) { - super(start); - this.newCount = newCount; - } - - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMessageHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMessageHandlerMetrics.java deleted file mode 100644 index 2b5f117a74..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMessageHandlerMetrics.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2002-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - - -/** - * An implementation of {@link org.springframework.integration.support.management.MessageHandlerMetrics} - * that aggregates the total response - * time over a sample, to avoid fetching the system time twice for every message. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class AggregatingMessageHandlerMetrics extends DefaultMessageHandlerMetrics { - - private static final int DEFAULT_SAMPLE_SIZE = 1000; - - private final int sampleSize; - - private long start; - - public AggregatingMessageHandlerMetrics() { - this(null, DEFAULT_SAMPLE_SIZE); - } - - /** - * Construct an instance with the default moving average window (10). - * @param name the name. - * @param sampleSize the sample size over which to aggregate the duration. - */ - public AggregatingMessageHandlerMetrics(String name, int sampleSize) { - super(name); - this.sampleSize = sampleSize; - } - - /** - * Construct an instance with the supplied {@link ExponentialMovingAverage} calculating - * the duration of processing by the message handler (and any downstream synchronous - * endpoints). - * @param name the name. - * @param duration an {@link ExponentialMovingAverage} for calculating the duration. - * @param sampleSize the sample size over which to aggregate the duration. - */ - public AggregatingMessageHandlerMetrics(String name, ExponentialMovingAverage duration, int sampleSize) { - super(name, duration); - this.sampleSize = sampleSize; - } - - @Override - public synchronized MetricsContext beforeHandle() { - long count = this.handleCount.getAndIncrement(); - if (isFullStatsEnabled() && count % this.sampleSize == 0) { - this.start = System.nanoTime(); - } - this.activeCount.incrementAndGet(); - return new AggregatingHandlerMetricsContext(this.start, count + 1); - } - - @Override - public void afterHandle(MetricsContext context, boolean success) { - this.activeCount.decrementAndGet(); - AggregatingHandlerMetricsContext aggregatingContext = (AggregatingHandlerMetricsContext) context; - if (success) { - if (isFullStatsEnabled() && aggregatingContext.newCount % this.sampleSize == 0) { - this.duration.append(System.nanoTime() - aggregatingContext.start); - } - } - else { - this.errorCount.incrementAndGet(); - } - } - - protected static class AggregatingHandlerMetricsContext extends DefaultHandlerMetricsContext { - - protected long newCount; - - public AggregatingHandlerMetricsContext(long start, long newCount) { - super(start); - this.newCount = newCount; - } - - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMetricsFactory.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMetricsFactory.java deleted file mode 100644 index 14ca6febb0..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/AggregatingMetricsFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -/** - * Implementation that returns aggregating metrics. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Gary Russell - * @since 4.2 - * - */ -@Deprecated -public class AggregatingMetricsFactory implements MetricsFactory { - - private final int sampleSize; - - /** - * @param sampleSize the number of messages over which to aggregate the elapsed time. - */ - public AggregatingMetricsFactory(int sampleSize) { - this.sampleSize = sampleSize; - } - - @Override - public AbstractMessageChannelMetrics createChannelMetrics(String name) { - return new AggregatingMessageChannelMetrics(name, this.sampleSize); - } - - @Override - public AbstractMessageHandlerMetrics createHandlerMetrics(String name) { - return new AggregatingMessageHandlerMetrics(name, this.sampleSize); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseChannelMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseChannelMetrics.java deleted file mode 100644 index 151fdbc1a3..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseChannelMetrics.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * Primary interface for channels that provide metrics. - * - * @author Gary Russell - * @since 5.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public interface BaseChannelMetrics extends IntegrationStatsManagement { - - /** - * @return the number of successful sends - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Channel Send Count") - long sendCount(); - - /** - * @return the number of failed sends (either throwing an exception or rejected by the channel) - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Channel Send Error Count") - long sendErrorCount(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseHandlerMetrics.java deleted file mode 100644 index 9f2ac88480..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseHandlerMetrics.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * @author Gary Russell - * @since 5.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public interface BaseHandlerMetrics extends IntegrationStatsManagement { - - /** - * @return the number of successful handler calls - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count") - long handleCount(); - - /** - * @return the number of failed handler calls - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count") - long errorCount(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java deleted file mode 100644 index 4298fb5cb9..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetricsAware.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -/** - * Classes implementing this interface can accept a {@link ConfigurableMetrics}. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@FunctionalInterface -public interface ConfigurableMetricsAware { - - void configureMetrics(M metrics); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMessageChannelMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMessageChannelMetrics.java deleted file mode 100644 index 0b21ba0128..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMessageChannelMetrics.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright 2009-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * Default implementation; use the full constructor to customize the moving averages. - * - * @author Dave Syer - * @author Helena Edelson - * @author Gary Russell - * @author Ivan Krizsan - * - * @since 2.0 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class DefaultMessageChannelMetrics extends AbstractMessageChannelMetrics { - - public static final long ONE_SECOND_SECONDS = 1; - - public static final long ONE_MINUTE_SECONDS = 60; - - public static final int DEFAULT_MOVING_AVERAGE_WINDOW = 10; - - protected final ExponentialMovingAverage sendDuration; // NOSONAR final - - protected final ExponentialMovingAverageRate sendErrorRate; // NOSONAR final - - protected final ExponentialMovingAverageRatio sendSuccessRatio; // NOSONAR final - - protected final ExponentialMovingAverageRate sendRate; // NOSONAR final - - protected final AtomicLong sendCount = new AtomicLong(); // NOSONAR final - - protected final AtomicLong sendErrorCount = new AtomicLong(); // NOSONAR final - - protected final AtomicLong receiveCount = new AtomicLong(); // NOSONAR final - - protected final AtomicLong receiveErrorCount = new AtomicLong(); // NOSONAR final - - public DefaultMessageChannelMetrics() { - this(null); - } - - /** - * Construct an instance with default metrics with {@code window=10, period=1 second, - * lapsePeriod=1 minute}. - * @param name the name. - */ - public DefaultMessageChannelMetrics(String name) { - this(name, new ExponentialMovingAverage(DEFAULT_MOVING_AVERAGE_WINDOW, 1000000.), - new ExponentialMovingAverageRate( - ONE_SECOND_SECONDS, ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW, true), - new ExponentialMovingAverageRatio( - ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW, true), - new ExponentialMovingAverageRate( - ONE_SECOND_SECONDS, ONE_MINUTE_SECONDS, DEFAULT_MOVING_AVERAGE_WINDOW, true)); - } - - /** - * Construct an instance with the supplied metrics. For proper representation of metrics, the - * supplied sendDuration must have a {@code factor=1000000.} and the the other arguments - * must be created with the {@code millis} constructor argument set to true. - * @param name the name. - * @param sendDuration an {@link ExponentialMovingAverage} for calculating the send duration. - * @param sendErrorRate an {@link ExponentialMovingAverageRate} for calculating the send error rate. - * @param sendSuccessRatio an {@link ExponentialMovingAverageRatio} for calculating the success ratio. - * @param sendRate an {@link ExponentialMovingAverageRate} for calculating the send rate. - * @since 4.2 - */ - public DefaultMessageChannelMetrics(String name, ExponentialMovingAverage sendDuration, - ExponentialMovingAverageRate sendErrorRate, ExponentialMovingAverageRatio sendSuccessRatio, - ExponentialMovingAverageRate sendRate) { - - super(name); - this.sendDuration = sendDuration; - this.sendErrorRate = sendErrorRate; - this.sendSuccessRatio = sendSuccessRatio; - this.sendRate = sendRate; - } - - public void destroy() { - if (logger.isDebugEnabled()) { - logger.debug(this.sendDuration); - } - } - - @Override - public MetricsContext beforeSend() { - long start = 0; - if (isFullStatsEnabled()) { - start = System.nanoTime(); - this.sendRate.increment(start); - } - this.sendCount.incrementAndGet(); - return new DefaultChannelMetricsContext(start); - } - - @Override - public void afterSend(MetricsContext context, boolean result) { - if (result) { - if (isFullStatsEnabled()) { - long now = System.nanoTime(); - this.sendSuccessRatio.success(now); - this.sendDuration.append(now - ((DefaultChannelMetricsContext) context).start); - } - } - else { - if (isFullStatsEnabled()) { - long now = System.nanoTime(); - this.sendSuccessRatio.failure(now); - this.sendErrorRate.increment(now); - } - this.sendErrorCount.incrementAndGet(); - } - } - - @Override - public synchronized void reset() { - this.sendDuration.reset(); - this.sendErrorRate.reset(); - this.sendSuccessRatio.reset(); - this.sendRate.reset(); - this.sendCount.set(0); - this.sendErrorCount.set(0); - this.receiveErrorCount.set(0); - this.receiveCount.set(0); - } - - @Override - public int getSendCount() { - return (int) this.sendCount.get(); - } - - @Override - public long getSendCountLong() { - return this.sendCount.get(); - } - - @Override - public int getSendErrorCount() { - return (int) this.sendErrorCount.get(); - } - - @Override - public long getSendErrorCountLong() { - return this.sendErrorCount.get(); - } - - @Override - public double getTimeSinceLastSend() { - return this.sendRate.getTimeSinceLastMeasurement(); - } - - @Override - public double getMeanSendRate() { - return this.sendRate.getMean(); - } - - @Override - public double getMeanErrorRate() { - return this.sendErrorRate.getMean(); - } - - @Override - public double getMeanErrorRatio() { - return 1 - this.sendSuccessRatio.getMean(); - } - - @Override - public double getMeanSendDuration() { - return this.sendDuration.getMean(); - } - - @Override - public double getMinSendDuration() { - return this.sendDuration.getMin(); - } - - @Override - public double getMaxSendDuration() { - return this.sendDuration.getMax(); - } - - @Override - public double getStandardDeviationSendDuration() { - return this.sendDuration.getStandardDeviation(); - } - - @Override - public Statistics getSendDuration() { - return this.sendDuration.getStatistics(); - } - - @Override - public Statistics getSendRate() { - return this.sendRate.getStatistics(); - } - - @Override - public Statistics getErrorRate() { - return this.sendErrorRate.getStatistics(); - } - - @Override - public void afterReceive() { - this.receiveCount.incrementAndGet(); - } - - @Override - public void afterError() { - this.receiveErrorCount.incrementAndGet(); - } - - @Override - public int getReceiveCount() { - return (int) this.receiveCount.get(); - } - - @Override - public long getReceiveCountLong() { - return this.receiveCount.get(); - } - - @Override - public int getReceiveErrorCount() { - return (int) this.receiveErrorCount.get(); - } - - @Override - public long getReceiveErrorCountLong() { - return this.receiveErrorCount.get(); - } - - @Override - public String toString() { - return String.format("MessageChannelMonitor: [name=%s, sends=%d" - + (this.receiveCount.get() == 0 ? "" : this.receiveCount.get()) - + "]", name, this.sendCount.get()); - } - - protected static class DefaultChannelMetricsContext implements MetricsContext { - - protected final long start; // NOSONAR - - protected DefaultChannelMetricsContext(long start) { - this.start = start; - } - - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMessageHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMessageHandlerMetrics.java deleted file mode 100644 index d27fd294cb..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMessageHandlerMetrics.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2002-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * Default implementation; use the full constructor to customize the moving averages. - * - * @author Dave Syer - * @author Gary Russell - * @since 2.0 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class DefaultMessageHandlerMetrics extends AbstractMessageHandlerMetrics { - - private static final int DEFAULT_MOVING_AVERAGE_WINDOW = 10; - - - protected final AtomicLong activeCount = new AtomicLong(); // NOSONAR final - - protected final AtomicLong handleCount = new AtomicLong(); // NOSONAR final - - protected final AtomicLong errorCount = new AtomicLong(); // NOSONAR final - - protected final ExponentialMovingAverage duration; // NOSONAR final - - public DefaultMessageHandlerMetrics() { - this(null); - } - - /** - * Construct an instance with the default moving average window (10). - * @param name the name. - */ - public DefaultMessageHandlerMetrics(String name) { - this(name, new ExponentialMovingAverage(DEFAULT_MOVING_AVERAGE_WINDOW, 1000000.)); - } - - /** - * Construct an instance with the supplied {@link ExponentialMovingAverage} calculating - * the duration of processing by the message handler (and any downstream synchronous - * endpoints). - * @param name the name. - * @param duration an {@link ExponentialMovingAverage} for calculating the duration. - * @since 4.2 - */ - public DefaultMessageHandlerMetrics(String name, ExponentialMovingAverage duration) { - super(name); - this.duration = duration; - } - - @Override - public MetricsContext beforeHandle() { - long start = 0; - if (isFullStatsEnabled()) { - start = System.nanoTime(); - } - this.handleCount.incrementAndGet(); - this.activeCount.incrementAndGet(); - return new DefaultHandlerMetricsContext(start); - } - - @Override - public void afterHandle(MetricsContext context, boolean success) { - this.activeCount.decrementAndGet(); - if (isFullStatsEnabled() && success) { - this.duration.append(System.nanoTime() - ((DefaultHandlerMetricsContext) context).start); - } - else if (!success) { - this.errorCount.incrementAndGet(); - } - } - - @Override - public synchronized void reset() { - this.duration.reset(); - this.errorCount.set(0); - this.handleCount.set(0); - } - - @Override - public long getHandleCountLong() { - if (logger.isTraceEnabled()) { - logger.trace("Getting Handle Count:" + this); - } - return this.handleCount.get(); - } - - @Override - public int getHandleCount() { - return (int) getHandleCountLong(); - } - - @Override - public int getErrorCount() { - return (int) this.errorCount.get(); - } - - @Override - public long getErrorCountLong() { - return this.errorCount.get(); - } - - @Override - public double getMeanDuration() { - return this.duration.getMean(); - } - - @Override - public double getMinDuration() { - return this.duration.getMin(); - } - - @Override - public double getMaxDuration() { - return this.duration.getMax(); - } - - @Override - public double getStandardDeviationDuration() { - return this.duration.getStandardDeviation(); - } - - @Override - public int getActiveCount() { - return (int) this.activeCount.get(); - } - - @Override - public long getActiveCountLong() { - return this.activeCount.get(); - } - - @Override - public Statistics getDuration() { - return this.duration.getStatistics(); - } - - protected static class DefaultHandlerMetricsContext implements MetricsContext { - - protected final long start; // NOSONAR final - - protected DefaultHandlerMetricsContext(long start) { - this.start = start; - } - - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMetricsFactory.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMetricsFactory.java deleted file mode 100644 index 3f92b80607..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/DefaultMetricsFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - - - - -/** - * Default implementation. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public class DefaultMetricsFactory implements MetricsFactory { - - @Override - public AbstractMessageChannelMetrics createChannelMetrics(String name) { - return new DefaultMessageChannelMetrics(name); - } - - @Override - public AbstractMessageHandlerMetrics createHandlerMetrics(String name) { - return new DefaultMessageHandlerMetrics(name); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverage.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverage.java deleted file mode 100644 index 75c89080b4..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverage.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2009-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; - - - -/** - * Cumulative statistics for a series of real numbers with higher weight given to recent data. - * Clients call {@link #append(double)} every time there is a new measurement, and then can collect summary - * statistics from the convenience getters (e.g. {@link #getStatistics()}). Older values are given exponentially smaller - * weight, with a decay factor determined by a "window" size chosen by the caller. The result is a good approximation to - * the statistics of the series but with more weight given to recent measurements, so if the statistics change over time - * those trends can be approximately reflected. For performance reasons, the calculation is performed on retrieval, - * {@code window * 5} samples are retained meaning that the earliest retained value contributes just 0.5% to the - * sum. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Dave Syer - * @author Gary Russell - * @since 2.0 - */ -@Deprecated -public class ExponentialMovingAverage { - - private volatile long count; - - private volatile double min = Double.MAX_VALUE; - - private volatile double max; - - private final Deque samples = new ArrayDeque<>(); - - private final int retention; - - private final int window; - - private final double factor; - - - /** - * Create a moving average accumulator with decay lapse window provided. Measurements older than this will have - * smaller weight than 1/e. - * @param window the exponential lapse window (number of measurements) - */ - public ExponentialMovingAverage(int window) { - this(window, 1); - } - - /** - * Create a moving average accumulator with decay lapse window provided. Measurements older than this will have - * smaller weight than 1/e. - * @param window the exponential lapse window (number of measurements) - * @param factor a factor by which raw values are reduced during analysis; e.g. to analyze in ms and - * raw values are ns, set the factor to 1000000.0. - * @since 4.2 - */ - public ExponentialMovingAverage(int window, double factor) { - this.window = window; - this.retention = window * 5; // last retained value contributes just 0.5% to the sum - this.factor = factor; - } - - public synchronized void reset() { - this.count = 0; - this.min = Double.MAX_VALUE; - this.max = 0; - this.samples.clear(); - } - - /** - * Add a new measurement to the series. - * @param value the measurement to append - */ - public synchronized void append(double value) { - if (this.samples.size() == this.retention) { - this.samples.poll(); - } - this.samples.add(value); - this.count++; //NOSONAR - false positive, we're synchronized - } - - private Statistics calc() { - List copy; - long currentCount; - synchronized (this) { - copy = new ArrayList(this.samples); - currentCount = this.count; - } - double sum = 0; - double decay = 1 - 1. / this.window; - double sumSquares = 0; - double weight = 0; - double currentMin = this.min; - double currentMax = this.max; - for (Double value : copy) { - value /= this.factor; - if (value > currentMax) { - currentMax = value; - } - if (value < currentMin) { - currentMin = value; - } - sum = decay * sum + value; - sumSquares = decay * sumSquares + value * value; - weight = decay * weight + 1; - } - synchronized (this) { - if (currentMax > this.max) { - this.max = currentMax; - } - if (currentMin < this.min) { - this.min = currentMin; - } - } - double mean = weight > 0 ? sum / weight : 0.; - double var = weight > 0 ? sumSquares / weight - mean * mean : 0.; - double standardDeviation = var > 0 ? Math.sqrt(var) : 0; - return new Statistics(currentCount, currentMin == Double.MAX_VALUE ? 0 : currentMin, currentMax, mean, standardDeviation); //NOSONAR - } - - /** - * @return the number of measurements recorded - */ - public int getCount() { - return (int) this.count; - } - - /** - * @return the number of measurements recorded - */ - public long getCountLong() { - return this.count; - } - - /** - * @return the mean value - */ - public double getMean() { - return calc().getMean(); - } - - /** - * @return the approximate standard deviation - */ - public double getStandardDeviation() { - return calc().getStandardDeviation(); - } - - /** - * @return the maximum value recorded (not weighted) - */ - public double getMax() { - return calc().getMax(); - } - - /** - * @return the minimum value recorded (not weighted) - */ - public double getMin() { - return calc().getMin(); - } - - /** - * @return summary statistics (count, mean, standard deviation etc.) - */ - public Statistics getStatistics() { - return calc(); - } - - @Override - public String toString() { - return getStatistics().toString(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverageRate.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverageRate.java deleted file mode 100644 index eef704e94e..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverageRate.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright 2009-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; - - -/** - * Cumulative statistics for an event rate with higher weight given to recent data. - * Clients call {@link #increment()} when a new event occurs, and then use convenience methods (e.g. {@link #getMean()}) - * to retrieve estimates of the rate of event arrivals and the statistics of the series. Older values are given - * exponentially smaller weight, with a decay factor determined by a duration chosen by the client. The rate measurement - * weights decay in two dimensions: - *
    - *
  • in time according to the lapse period supplied: weight = exp((t0-t)/T) where t0 is the - * last measurement time, t is the current time and T is the lapse period)
  • - *
  • per measurement according to the lapse window supplied: weight = exp(-i/L) where L is - * the lapse window and i is the sequence number of the measurement.
  • - *
- * For performance reasons, the calculation is performed on retrieval, - * {@code window * 5} samples are retained meaning that the earliest retained value contributes just 0.5% to the - * sum. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @author Dave Syer - * @author Gary Russell - * @author Steven Swor - * - */ -@Deprecated -public class ExponentialMovingAverageRate { - - private volatile double min = Double.MAX_VALUE; - - private volatile double max; - - private volatile double t0; - - private volatile long count; - - private final double lapse; - - private final double period; - - private final Deque times = new ArrayDeque<>(); - - private final int retention; - - private final int window; - - private final double factor; - - - /** - * @param period the period to base the rate measurement (in seconds) - * @param lapsePeriod the exponential lapse rate for the rate average (in seconds) - * @param window the exponential lapse window (number of measurements) - */ - public ExponentialMovingAverageRate(double period, double lapsePeriod, int window) { - this(period, lapsePeriod, window, false); - } - - /** - * @param period the period to base the rate measurement (in seconds) - * @param lapsePeriod the exponential lapse rate for the rate average (in seconds) - * @param window the exponential lapse window (number of measurements) - * @param millis when true, analyze the data as milliseconds instead of the native nanoseconds - * @since 4.2 - */ - public ExponentialMovingAverageRate(double period, double lapsePeriod, int window, boolean millis) { - this.lapse = lapsePeriod > 0 ? 0.001 / lapsePeriod : 0; // convert to milliseconds - this.period = period * 1000; // convert to milliseconds - this.window = window; - this.retention = window * 5; - this.factor = millis ? 1000000 : 1; - this.t0 = System.nanoTime() / this.factor; - } - - - public synchronized void reset() { - this.min = Double.MAX_VALUE; - this.max = 0; - this.count = 0; - this.times.clear(); - this.t0 = System.nanoTime() / this.factor; - } - - /** - * Add a new event to the series. - */ - public synchronized void increment() { - increment(System.nanoTime()); - } - - /** - * Add a new event to the series at time t. - * @param t a new event to the series (System.nanoTime()). - */ - public synchronized void increment(long t) { - if (this.times.size() == this.retention) { - this.times.poll(); - } - this.times.add(t); - this.count++; //NOSONAR - false positive, we're synchronized - } - - private Statistics calcStatic() { - List copy; - long currentCount; - synchronized (this) { - copy = new ArrayList(this.times); - currentCount = this.count; - } - ExponentialMovingAverage rates = new ExponentialMovingAverage(this.window); - double currentT0 = 0; - double sum = 0; - double weight = 0; - double currentMin = this.min; - double currentMax = this.max; - int size = copy.size(); - for (Long time : copy) { - double t = time / this.factor; - if (size == 1) { - currentT0 = this.t0; - } - else if (currentT0 == 0) { - currentT0 = t; - continue; - } - double delta = t - currentT0; - double value = delta > 0 ? delta / this.period : 0; - if (value > currentMax) { - currentMax = value; - } - if (value < currentMin) { - currentMin = value; - } - double alpha = Math.exp(-delta * this.lapse); - currentT0 = t; - sum = alpha * sum + value; - weight = alpha * weight + 1; - rates.append(sum > 0 ? weight / sum : 0); - } - synchronized (this) { - if (currentMax > this.max) { - this.max = currentMax; - } - if (currentMin < this.min) { - this.min = currentMin; - } - } - return new Statistics(currentCount, currentMin < Double.MAX_VALUE ? currentMin : 0, currentMax, rates.getMean(), - rates.getStandardDeviation()); - } - - /** - * @return the number of measurements recorded - */ - public int getCount() { - return (int) this.count; - } - - /** - * @return the number of measurements recorded - * @since 3.0 - */ - public long getCountLong() { - return this.count; - } - - /** - * @return the time in milliseconds since the last measurement - */ - public double getTimeSinceLastMeasurement() { - if (this.count == 0) { - return 0; - } - double currentT0 = lastTime(); - return (System.nanoTime() / this.factor - currentT0); - } - - /** - * @return the mean value - */ - public double getMean() { - return recalcMean(calcStatic()); - } - - /** - * Decay the mean using the current time. - * @param staticStats the static statistics. - * @return the new mean. - */ - private double recalcMean(Statistics staticStats) { - long currentCount = this.count; - currentCount = currentCount > this.retention ? this.retention : currentCount; - if (currentCount == 0) { - return 0; - } - double currentT0 = lastTime(); - double t = System.nanoTime() / this.factor; - double value = t > currentT0 ? (t - currentT0) / this.period : 0; - return currentCount / (currentCount / staticStats.getMean() + value); - } - - private synchronized double lastTime() { - if (this.times.size() > 0) { - return this.times.peekLast() / this.factor; - } - else { - return this.t0; - } - } - - /** - * @return the approximate standard deviation - */ - public double getStandardDeviation() { - return calcStatic().getStandardDeviation(); - } - - /** - * @return the maximum value recorded (not weighted) - */ - public double getMax() { - double currentMin = calcStatic().getMin(); - return currentMin > 0 ? 1 / currentMin : 0; - } - - /** - * @return the minimum value recorded (not weighted) - */ - public double getMin() { - double currentMax = calcStatic().getMax(); - return currentMax > 0 ? 1 / currentMax : 0; - } - - /** - * @return summary statistics (count, mean, standard deviation etc.) - */ - public Statistics getStatistics() { - Statistics staticStats = calcStatic(); - staticStats.setMean(recalcMean(staticStats)); - return staticStats; - } - - @Override - public String toString() { - return String.format("[%s, timeSinceLast=%f]", getStatistics(), getTimeSinceLastMeasurement()); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverageRatio.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverageRatio.java deleted file mode 100644 index cdf76d98e7..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ExponentialMovingAverageRatio.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright 2009-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.Iterator; -import java.util.List; - - - -/** - * Cumulative statistics for success ratio with higher weight given to recent data. - * Clients call {@link #success()} or {@link #failure()} when an event occurs, and the ratio of success to total events - * is accumulated. Older values are given exponentially smaller weight, with a decay factor determined by a duration - * chosen by the client. The rate measurement weights decay in two dimensions: - *
    - *
  • in time according to the lapse period supplied: weight = exp((t0-t)/T) where t0 is the - * last measurement time, t is the current time and T is the lapse period)
  • - *
  • per measurement according to the lapse window supplied: weight = exp(-i/L) where L is - * the lapse window and i is the sequence number of the measurement.
  • - *
- * For performance reasons, the calculation is performed on retrieval, - * {@code window * 5} samples are retained meaning that the earliest retained value contributes just 0.5% to the - * sum. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @author Dave Syer - * @author Gary Russell - * @author Steven Swor - * @since 2.0 - */ -@Deprecated -public class ExponentialMovingAverageRatio { - - private volatile double t0; - - private volatile long count; - - private volatile double min = Double.MAX_VALUE; - - private volatile double max; - - private final double lapse; - - private final Deque times = new ArrayDeque<>(); - - private final Deque values = new ArrayDeque<>(); - - private final int retention; - - private final int window; - - private final double factor; - - /** - * @param lapsePeriod the exponential lapse rate for the rate average (in seconds) - * @param window the exponential lapse window (number of measurements) - */ - public ExponentialMovingAverageRatio(double lapsePeriod, int window) { - this(lapsePeriod, window, false); - } - - /** - * @param lapsePeriod the exponential lapse rate for the rate average (in seconds) - * @param window the exponential lapse window (number of measurements) - * @param millis when true, analyze the data as milliseconds instead of the native nanoseconds - * @since 4.2 - */ - public ExponentialMovingAverageRatio(double lapsePeriod, int window, boolean millis) { - this.lapse = lapsePeriod > 0 ? 0.001 / lapsePeriod : 0; // convert to milliseconds - this.window = window; - this.retention = window * 5; - this.factor = millis ? 1000000 : 1; - this.t0 = System.nanoTime() / this.factor; - } - - - /** - * Add a new event with successful outcome. - */ - public void success() { - append(1, System.nanoTime()); - } - - /** - * Add a new event with successful outcome at time t. - * @param t the System.nanoTime(). - */ - public void success(long t) { - append(1, t); - } - - /** - * Add a new event with failed outcome. - */ - public void failure() { - append(0, System.nanoTime()); - } - - /** - * Add a new event with failed outcome at time t. - * @param t a new event with failed outcome in milliseconds. - */ - public void failure(long t) { - append(0, t); - } - - public synchronized void reset() { - this.t0 = System.nanoTime() / this.factor; - this.times.clear(); - this.values.clear(); - this.count = 0; - this.max = 0; - this.min = Double.MAX_VALUE; - } - - private synchronized void append(int value, long t) { - if (this.times.size() == this.retention) { - this.times.poll(); - this.values.poll(); - } - this.times.add(t); - this.values.add(value); - this.count++; //NOSONAR - false positive, we're synchronized - } - - private Statistics calcStatic() { - List copyTimes; - List copyValues; - long currentCount; - synchronized (this) { - copyTimes = new ArrayList(this.times); - copyValues = new ArrayList(this.values); - currentCount = this.count; - } - ExponentialMovingAverage cumulative = new ExponentialMovingAverage(this.window); - double currentT0 = 0; - double sum = 0; - double weight = 0; - double currentMin = this.min; - double currentMax = this.max; - int size = copyTimes.size(); - Iterator valuesIterator = copyValues.iterator(); - for (Long time : copyTimes) { - double t = time / this.factor; - if (size == 1) { - currentT0 = this.t0; - } - else if (currentT0 == 0) { - currentT0 = t; - valuesIterator.next(); - continue; - } - double alpha = Math.exp((currentT0 - t) * this.lapse); - currentT0 = t; - sum = alpha * sum + valuesIterator.next(); - weight = alpha * weight + 1; - double value = sum / weight; - if (value > currentMax) { - currentMax = value; - } - if (value < currentMin) { - currentMin = value; - } - cumulative.append(value); - } - synchronized (this) { - if (currentMax > this.max) { - this.max = currentMax; - } - if (currentMin < this.min) { - this.min = currentMin; - } - } - return new Statistics(currentCount, currentMin < Double.MAX_VALUE ? currentMin : 0, currentMax, cumulative.getMean(), - cumulative.getStandardDeviation()); - } - - /** - * @return the number of measurements recorded - */ - public int getCount() { - return (int) this.count; - } - - /** - * @return the number of measurements recorded - */ - public long getCountLong() { - return this.count; - } - - /** - * @return the time in seconds since the last measurement - */ - public double getTimeSinceLastMeasurement() { - double delta = System.nanoTime() - lastTime(); - return delta / 1000. / this.factor; - } - - /** - * @return the mean success rate - */ - public double getMean() { - if (this.count == 0) { - // Optimistic to start: success rate is 100% - return 1; - } - return decayMean(calcStatic()); - } - - /** - * Decay the mean using the current time. - * @param staticStats the static statistics. - * @return the new mean. - */ - private double decayMean(Statistics statistics) { - double t = System.nanoTime() / this.factor; - double mean = statistics.getMean(); - double alpha = Math.exp((lastTime() / this.factor - t) * this.lapse); - return alpha * mean + 1 - alpha; - } - - private synchronized double lastTime() { - if (this.times.size() > 0) { - return this.times.peekLast(); - } - else { - return this.t0 * this.factor; - } - } - - /** - * @return the approximate standard deviation of the success rate measurements - */ - public double getStandardDeviation() { - return calcStatic().getStandardDeviation(); - } - - /** - * @return the maximum value recorded of the exponential weighted average (per measurement) success rate - */ - public double getMax() { - return calcStatic().getMax(); - } - - /** - * @return the minimum value recorded of the exponential weighted average (per measurement) success rate - */ - public double getMin() { - return calcStatic().getMin(); - } - - /** - * @return summary statistics (count, mean, standard deviation etc.) - */ - public Statistics getStatistics() { - Statistics staticStats = calcStatic(); - staticStats.setMean(decayMean(staticStats)); - return staticStats; - } - - @Override - public String toString() { - return String.format("[%s, timeSinceLast=%f]", getStatistics(), getTimeSinceLastMeasurement()); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationInboundManagement.java similarity index 72% rename from spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetrics.java rename to spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationInboundManagement.java index 1e17edeb88..272c321532 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/ConfigurableMetrics.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationInboundManagement.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,13 @@ package org.springframework.integration.support.management; /** - * Marker interface for metrics. + * Marker interface indicating that this {@link IntegrationManagement} component initiates + * message flow. * * @author Gary Russell - * @since 4.2 + * @since 5.4 * - * @deprecated in favor of Micrometer metrics. */ -@Deprecated -public interface ConfigurableMetrics { +public interface IntegrationInboundManagement extends IntegrationManagement { } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagement.java index 79b49f8966..765e40690f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagement.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationManagement.java @@ -17,9 +17,10 @@ package org.springframework.integration.support.management; import org.springframework.beans.factory.DisposableBean; +import org.springframework.integration.support.context.NamedComponent; import org.springframework.integration.support.management.metrics.MetricsCaptor; import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedOperation; +import org.springframework.lang.Nullable; /** * Base interface for Integration managed components. @@ -28,7 +29,7 @@ import org.springframework.jmx.export.annotation.ManagedOperation; * @since 4.2 * */ -public interface IntegrationManagement extends DisposableBean { +public interface IntegrationManagement extends NamedComponent, DisposableBean { String METER_PREFIX = "spring.integration."; @@ -36,37 +37,35 @@ public interface IntegrationManagement extends DisposableBean { String RECEIVE_COUNTER_NAME = METER_PREFIX + "receive"; + /** + * Enable logging or not. + * @param enabled dalse to disable. + */ @ManagedAttribute(description = "Use to disable debug logging during normal message flow") void setLoggingEnabled(boolean enabled); + /** + * Return whether logging is enabled. + * @return true if enabled. + */ @ManagedAttribute boolean isLoggingEnabled(); - /** - * Deprecated. - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @ManagedOperation - void reset(); + default void setManagedName(String managedName) { + } - /** - * Deprecated. - * @param countsEnabled the countsEnabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @ManagedAttribute(description = "Enable message counting statistics") - void setCountsEnabled(boolean countsEnabled); + @Nullable + default String getManagedName() { + return null; + } - /** - * Deprecated. - * @return counts enabled - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @ManagedAttribute - boolean isCountsEnabled(); + default void setManagedType(String managedType) { + } + + @Nullable + default String getManagedType() { + return null; + } /** * Return the overrides. @@ -84,14 +83,21 @@ public interface IntegrationManagement extends DisposableBean { // no op } - - @Override default void destroy() { // no op } - + /** + * Return this {@link IntegrationManagement} as its concrete type. + * @param the type. + * @return this. + * @since 5.4 + */ + @SuppressWarnings("unchecked") + default T getThisAs() { + return (T) this; + } /** * Toggles to inform the management configurer to not set these properties since @@ -104,12 +110,6 @@ public interface IntegrationManagement extends DisposableBean { public boolean loggingConfigured; // NOSONAR - public boolean countsConfigured; // NOSONAR - - public boolean statsConfigured; // NOSONAR - - public boolean metricsConfigured; // NOSONAR - } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageHandlerMetrics.java deleted file mode 100644 index 6abc6b453b..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageHandlerMetrics.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; -import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedOperation; - -/** - * A {@link MessageHandlerMetrics} that exposes in addition the {@link Lifecycle} - * interface. The lifecycle methods can be used to stop and start polling endpoints, for - * instance, in a live system. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Dave Syer - * @author Gary Russell - * @since 2.0 - */ -@Deprecated -@IntegrationManagedResource -public class LifecycleMessageHandlerMetrics implements - org.springframework.integration.support.management.MessageHandlerMetrics, Lifecycle, - ConfigurableMetricsAware { - - private final Lifecycle lifecycle; - - protected final org.springframework.integration.support.management.MessageHandlerMetrics delegate; // NOSONAR - - - public LifecycleMessageHandlerMetrics(Lifecycle lifecycle, - org.springframework.integration.support.management.MessageHandlerMetrics delegate) { - - this.lifecycle = lifecycle; - this.delegate = delegate; - } - - public MessageHandlerMetrics getDelegate() { - return this.delegate; - } - - @SuppressWarnings("unchecked") - @Override - public void configureMetrics(AbstractMessageHandlerMetrics metrics) { - if (this.delegate instanceof ConfigurableMetricsAware) { - ((ConfigurableMetricsAware) this.delegate).configureMetrics(metrics); - } - } - - @Override - @ManagedAttribute - public boolean isRunning() { - return this.lifecycle.isRunning(); - } - - @Override - @ManagedOperation - public void start() { - this.lifecycle.start(); - } - - @Override - @ManagedOperation - public void stop() { - this.lifecycle.stop(); - } - - @Override - public void reset() { - this.delegate.reset(); - } - - @Override - public int getErrorCount() { - return this.delegate.getErrorCount(); - } - - @Override - public int getHandleCount() { - return this.delegate.getHandleCount(); - } - - @Override - public double getMaxDuration() { - return this.delegate.getMaxDuration(); - } - - @Override - public double getMeanDuration() { - return this.delegate.getMeanDuration(); - } - - @Override - public double getMinDuration() { - return this.delegate.getMinDuration(); - } - - @Override - public double getStandardDeviationDuration() { - return this.delegate.getStandardDeviationDuration(); - } - - @Override - public Statistics getDuration() { - return this.delegate.getDuration(); - } - - @Override - public String getManagedName() { - return this.delegate.getManagedName(); - } - - @Override - public String getManagedType() { - return this.delegate.getManagedType(); - } - - @Override - public int getActiveCount() { - return this.delegate.getActiveCount(); - } - - @Override - public long getHandleCountLong() { - return this.delegate.getHandleCountLong(); - } - - @Override - public long getErrorCountLong() { - return this.delegate.getErrorCountLong(); - } - - @Override - public long getActiveCountLong() { - return this.delegate.getActiveCountLong(); - } - - @Override - public void setStatsEnabled(boolean statsEnabled) { - this.delegate.setStatsEnabled(statsEnabled); - } - - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.delegate.setCountsEnabled(countsEnabled); - } - - @Override - public boolean isStatsEnabled() { - return this.delegate.isStatsEnabled(); - } - - @Override - public boolean isCountsEnabled() { - return this.delegate.isCountsEnabled(); - } - - @Override - public void setLoggingEnabled(boolean enabled) { - this.delegate.setLoggingEnabled(enabled); - } - - @Override - public boolean isLoggingEnabled() { - return this.delegate.isLoggingEnabled(); - } - - @Override - public void setManagedName(String name) { - this.delegate.setManagedName(name); - } - - @Override - public void setManagedType(String source) { - this.delegate.setManagedType(source); - } - - @Override - public ManagementOverrides getOverrides() { - return this.delegate.getOverrides(); - } - - @Override - public void destroy() { - this.delegate.destroy(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageSourceManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageSourceManagement.java deleted file mode 100644 index bf2eec86de..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageSourceManagement.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2016-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; - -/** - * An extension to {@link LifecycleMessageSourceMetrics} for sources that implement {@link MessageSourceManagement}. - * - * @author Gary Russell - * @since 5.0 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class LifecycleMessageSourceManagement extends LifecycleMessageSourceMetrics implements MessageSourceManagement { - - public LifecycleMessageSourceManagement(Lifecycle lifecycle, MessageSourceManagement delegate) { - super(lifecycle, delegate); - } - - @Override - public void setMaxFetchSize(int maxFetchSize) { - ((MessageSourceManagement) this.delegate).setMaxFetchSize(maxFetchSize); - } - - @Override - public int getMaxFetchSize() { - return ((MessageSourceManagement) this.delegate).getMaxFetchSize(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageSourceMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageSourceMetrics.java deleted file mode 100644 index 07a5146b6c..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleMessageSourceMetrics.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; -import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedOperation; - -/** - * A {@link MessageSourceMetrics} that exposes in addition the {@link Lifecycle} interface. - * The lifecycle methods can be used to start and stop polling endpoints, for instance, in a live system. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @author Dave Syer - * @author Gary Russell - * @author Artem Bilan - * - * @since 2.0 - */ -@Deprecated -@IntegrationManagedResource -public class LifecycleMessageSourceMetrics implements MessageSourceMetrics, Lifecycle { - - private final Lifecycle lifecycle; - - protected final MessageSourceMetrics delegate; // NOSONAR final - - - public LifecycleMessageSourceMetrics(Lifecycle lifecycle, MessageSourceMetrics delegate) { - this.lifecycle = lifecycle; - this.delegate = delegate; - } - - public MessageSourceMetrics getDelegate() { - return this.delegate; - } - - @Override - @ManagedOperation - public void reset() { - this.delegate.reset(); - } - - @Override - @ManagedAttribute - public boolean isRunning() { - return this.lifecycle.isRunning(); - } - - @Override - @ManagedOperation - public void start() { - this.lifecycle.start(); - } - - @Override - @ManagedOperation - public void stop() { - this.lifecycle.stop(); - } - - @Override - public String getManagedName() { - return this.delegate.getManagedName(); - } - - @Override - public String getManagedType() { - return this.delegate.getManagedType(); - } - - @Override - public int getMessageCount() { - return this.delegate.getMessageCount(); - } - - @Override - public long getMessageCountLong() { - return this.delegate.getMessageCountLong(); - } - - @Override - public void setCountsEnabled(boolean countsEnabled) { - this.delegate.setCountsEnabled(countsEnabled); - } - - @Override - public boolean isCountsEnabled() { - return this.delegate.isCountsEnabled(); - } - - @Override - public void setLoggingEnabled(boolean enabled) { - this.delegate.setLoggingEnabled(enabled); - } - - @Override - public boolean isLoggingEnabled() { - return this.delegate.isLoggingEnabled(); - } - - @Override - public void setManagedName(String name) { - this.delegate.setManagedName(name); - } - - @Override - public void setManagedType(String source) { - this.delegate.setManagedType(source); - } - - @Override - public ManagementOverrides getOverrides() { - return this.delegate.getOverrides(); - } - - @Override - public void destroy() { - this.delegate.destroy(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageHandlerMetrics.java deleted file mode 100644 index 412786564c..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageHandlerMetrics.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2015-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; -import org.springframework.util.Assert; - -/** - * Adds {@link TrackableComponent}. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Gary Russell - * @author Artem Bilan - * - * @since 4.2 - */ -@Deprecated -@IntegrationManagedResource -public class LifecycleTrackableMessageHandlerMetrics extends LifecycleMessageHandlerMetrics - implements TrackableComponent { - - private final TrackableComponent trackable; - - public LifecycleTrackableMessageHandlerMetrics(Lifecycle lifecycle, MessageHandlerMetrics delegate) { - super(lifecycle, delegate); - Assert.isInstanceOf(TrackableComponent.class, delegate); - this.trackable = (TrackableComponent) delegate; - } - - @Override - public String getBeanName() { - return this.trackable.getBeanName(); - } - - @Override - public String getComponentName() { - return this.trackable.getComponentName(); - } - - @Override - public String getComponentType() { - return this.trackable.getComponentType(); - } - - @Override - public void setShouldTrack(boolean shouldTrack) { - this.trackable.setShouldTrack(shouldTrack); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageSourceManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageSourceManagement.java deleted file mode 100644 index 07d08b5d88..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageSourceManagement.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; - -/** - * An extension to {@link LifecycleTrackableMessageSourceMetrics} for sources - * that implement {@link MessageSourceManagement}. - * - * @author Gary Russell - * @since 5.0 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class LifecycleTrackableMessageSourceManagement extends LifecycleTrackableMessageSourceMetrics - implements MessageSourceManagement { - - public LifecycleTrackableMessageSourceManagement(Lifecycle lifecycle, MessageSourceManagement delegate) { - super(lifecycle, delegate); - } - - @Override - public void setMaxFetchSize(int maxFetchSize) { - ((MessageSourceManagement) this.delegate).setMaxFetchSize(maxFetchSize); - } - - @Override - public int getMaxFetchSize() { - return ((MessageSourceManagement) this.delegate).getMaxFetchSize(); - } - - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageSourceMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageSourceMetrics.java deleted file mode 100644 index de26719517..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/LifecycleTrackableMessageSourceMetrics.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; -import org.springframework.util.Assert; - -/** - * Adds {@link TrackableComponent}. - * - * @author Gary Russell - * @author Artem Bilan - * - * @since 2.0 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -@IntegrationManagedResource -public class LifecycleTrackableMessageSourceMetrics extends LifecycleMessageSourceMetrics - implements TrackableComponent { - - private final TrackableComponent trackable; - - public LifecycleTrackableMessageSourceMetrics(Lifecycle lifecycle, MessageSourceMetrics delegate) { - super(lifecycle, delegate); - Assert.isInstanceOf(TrackableComponent.class, lifecycle); - this.trackable = (TrackableComponent) lifecycle; - } - - @Override - public String getBeanName() { - return this.trackable.getBeanName(); - } - - @Override - public String getComponentName() { - return this.trackable.getComponentName(); - } - - @Override - public String getComponentType() { - return this.trackable.getComponentType(); - } - - @Override - public void setShouldTrack(boolean shouldTrack) { - this.trackable.setShouldTrack(shouldTrack); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationStatsManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ManageableLifecycle.java similarity index 57% rename from spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationStatsManagement.java rename to spring-integration-core/src/main/java/org/springframework/integration/support/management/ManageableLifecycle.java index 66c35942c8..c8100e8677 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/IntegrationStatsManagement.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ManageableLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,24 +16,29 @@ package org.springframework.integration.support.management; +import org.springframework.context.Lifecycle; import org.springframework.jmx.export.annotation.ManagedAttribute; - +import org.springframework.jmx.export.annotation.ManagedOperation; /** - * Base interface containing methods to control complete statistics gathering. + * Makes {@link Lifecycle} methods manageable. * * @author Gary Russell - * @since 4.2 + * @since 5.4 * - * @deprecated in favor of Micrometer metrics. */ -@Deprecated -public interface IntegrationStatsManagement extends IntegrationManagement { +public interface ManageableLifecycle extends Lifecycle { - @ManagedAttribute(description = "Enable all statistics") - void setStatsEnabled(boolean statsEnabled); + @ManagedOperation(description = "Start the component") + @Override + void start(); - @ManagedAttribute - boolean isStatsEnabled(); + @ManagedOperation(description = "Stop the component") + @Override + void stop(); + + @ManagedAttribute(description = "Is the component running?") + @Override + boolean isRunning(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseSourceMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ManageableSmartLifecycle.java similarity index 70% rename from spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseSourceMetrics.java rename to spring-integration-core/src/main/java/org/springframework/integration/support/management/ManageableSmartLifecycle.java index d58badff82..03ded6e29f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/BaseSourceMetrics.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/ManageableSmartLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,15 @@ package org.springframework.integration.support.management; +import org.springframework.context.SmartLifecycle; + /** + * Extend {@link ManageableLifecycle} to make those methods manageable. + * * @author Gary Russell - * @since 5.2 + * @since 5.4 * */ -public interface BaseSourceMetrics extends IntegrationManagement { - - /** - * The number of successful message receptions. - * @return the count. - */ - long messageCount(); +public interface ManageableSmartLifecycle extends SmartLifecycle, ManageableLifecycle { } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageChannelMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageChannelMetrics.java deleted file mode 100644 index e9e4a05720..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageChannelMetrics.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * Interface for all message channel monitors containing accessors for various useful - * metrics that are generic for all channel types. - * - * @author Dave Syer - * @author Gary Russell - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @since 2.0 - */ -@Deprecated -public interface MessageChannelMetrics extends BaseChannelMetrics { - - /** - * @return the number of successful sends - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Count") - int getSendCount(); - - /** - * @return the number of successful sends - * @since 3.0 - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Count") - long getSendCountLong(); - - - @Override - default long sendCount() { - return getSendCountLong(); - } - - /** - * @return the number of failed sends (either throwing an exception or rejected by the channel) - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Error Count") - int getSendErrorCount(); - - /** - * @return the number of failed sends (either throwing an exception or rejected by the channel) - * @since 3.0 - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Send Error Count") - long getSendErrorCountLong(); - - @Override - default long sendErrorCount() { - return getSendErrorCountLong(); - } - - /** - * @return the time in milliseconds since the last send - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Time Since Last Send in Milliseconds") - double getTimeSinceLastSend(); - - /** - * @return the mean send rate (per second) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Rate per Second") - double getMeanSendRate(); - - /** - * @return the mean error rate (per second). Errors comprise all failed sends. - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Error Rate per Second") - double getMeanErrorRate(); - - /** - * @return the mean ratio of failed to successful sends in approximately the last minute - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Mean Channel Error Ratio per Minute") - double getMeanErrorRatio(); - - /** - * @return the mean send duration (milliseconds) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Mean Duration in Milliseconds") - double getMeanSendDuration(); - - /** - * @return the minimum send duration (milliseconds) since startup - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Min Duration in Milliseconds") - double getMinSendDuration(); - - /** - * @return the maximum send duration (milliseconds) since startup - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Max Duration in Milliseconds") - double getMaxSendDuration(); - - /** - * @return the standard deviation send duration (milliseconds) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Channel Send Standard Deviation Duration in Milliseconds") - double getStandardDeviationSendDuration(); - - /** - * @return summary statistics about the send duration (milliseconds) - */ - Statistics getSendDuration(); - - /** - * @return summary statistics about the send rates (per second) - */ - Statistics getSendRate(); - - /** - * @return summary statistics about the error rates (per second) - */ - Statistics getErrorRate(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageHandlerMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageHandlerMetrics.java deleted file mode 100644 index 47fd776d44..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageHandlerMetrics.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * @author Dave Syer - * @author Gary Russell - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @since 2.0 - */ -@Deprecated -public interface MessageHandlerMetrics extends BaseHandlerMetrics { - - /** - * @return the number of successful handler calls - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count") - int getHandleCount(); - - /** - * @return the number of successful handler calls - * @since 3.0 - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Execution Count") - long getHandleCountLong(); - - - @Override - default long handleCount() { - return getHandleCountLong(); - } - - /** - * @return the number of failed handler calls - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count") - int getErrorCount(); - - /** - * @return the number of failed handler calls - * @since 3.0 - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Handler Error Count") - long getErrorCountLong(); - - @Override - default long errorCount() { - return getErrorCountLong(); - } - - /** - * @return the mean handler duration (milliseconds) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Mean Duration in Milliseconds") - double getMeanDuration(); - - /** - * @return the minimum handler duration (milliseconds) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Min Duration in Milliseconds") - double getMinDuration(); - - /** - * @return the maximum handler duration (milliseconds) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Max Duration in Milliseconds") - double getMaxDuration(); - - /** - * @return the standard deviation handler duration (milliseconds) - */ - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Standard Deviation Duration in Milliseconds") - double getStandardDeviationDuration(); - - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Execution Count") - int getActiveCount(); - - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Handler Active Execution Count") - long getActiveCountLong(); - - /** - * @return summary statistics about the handler duration (milliseconds) - */ - Statistics getDuration(); - - void setManagedName(String name); - - String getManagedName(); - - void setManagedType(String source); - - String getManagedType(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceManagement.java index b30aff538a..87f7099218 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceManagement.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceManagement.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.jmx.export.annotation.ManagedAttribute; */ @SuppressWarnings("deprecation") @IntegrationManagedResource -public interface MessageSourceManagement extends MessageSourceMetrics { +public interface MessageSourceManagement { /** * Set the maximum number of objects the source should fetch if it is necessary to diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceMetrics.java deleted file mode 100644 index 986050373d..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceMetrics.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * @author Dave Syer - * @author Gary Russell - * @author Artem Bilan - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @since 2.0 - */ -@Deprecated -public interface MessageSourceMetrics extends BaseSourceMetrics { - - /** - * @return the number of successful message receptions. - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count") - int getMessageCount(); - - /** - * @return the number of successful handler calls - * @since 3.0 - */ - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Message Source Message Count") - long getMessageCountLong(); - - @Override - default long messageCount() { - return getMessageCountLong(); - } - - void setManagedName(String name); - - String getManagedName(); - - void setManagedType(String source); - - String getManagedType(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceMetricsConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceMetricsConfigurer.java deleted file mode 100644 index c716088006..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MessageSourceMetricsConfigurer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2018-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -/** - * Perform additional configuration on {@link MessageSourceMetrics}. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Gary Russell - * @since 5.0.2 - * - */ -@Deprecated -@FunctionalInterface -public interface MessageSourceMetricsConfigurer { - - void configure(MessageSourceMetrics metrics, String beanName); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MetricsContext.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MetricsContext.java deleted file mode 100644 index a60b5d8953..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MetricsContext.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2015-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -/** - * Interface representing an opaque object containing state between initiating an - * event and concluding it. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @author Gary Russell - * @since 4.2 - */ -@Deprecated -public interface MetricsContext { - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MetricsFactory.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/MetricsFactory.java deleted file mode 100644 index 3ca954a29e..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/MetricsFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -/** - * Factories implementing this interface provide metric objects for message channels and - * message handlers. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * @author Gary Russell - * @since 4.2 - * - */ -@Deprecated -public interface MetricsFactory { - - /** - * Factory method to create an {@link AbstractMessageChannelMetrics}. - * @param name the name. - * @return the metrics. - */ - AbstractMessageChannelMetrics createChannelMetrics(String name); - - /** - * Factory method to create an {@link AbstractMessageChannelMetrics} for - * a pollable channel. - * @param name the name. - * @return the metrics. - * @since 5.0.2 - */ - default AbstractMessageChannelMetrics createPollableChannelMetrics(String name) { - return createChannelMetrics(name); - } - - /** - * Factory method to create an {@link AbstractMessageHandlerMetrics}. - * @param name the name. - * @return the metrics. - */ - AbstractMessageHandlerMetrics createHandlerMetrics(String name); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/PollableChannelManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/PollableChannelManagement.java deleted file mode 100644 index e3105210f9..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/PollableChannelManagement.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * Metrics for pollable channels. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public interface PollableChannelManagement extends PollableChannelMetrics { - - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Count") - int getReceiveCount(); - - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Count") - long getReceiveCountLong(); - - @Override - default long receiveCount() { - return getReceiveCountLong(); - } - - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Error Count") - int getReceiveErrorCount(); - - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Receive Error Count") - long getReceiveErrorCountLong(); - - @Override - default long receiveErrorCount() { - return getReceiveErrorCountLong(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/PollableChannelMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/PollableChannelMetrics.java deleted file mode 100644 index c532db1d1f..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/PollableChannelMetrics.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * @author Gary Russell - * @since 5.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public interface PollableChannelMetrics extends IntegrationStatsManagement { - - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Channel Receive Count") - long receiveCount(); - - @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Channel Receive Error Count") - long receiveErrorCount(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/QueueChannelManagement.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/QueueChannelManagement.java deleted file mode 100644 index f489ebf5e9..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/QueueChannelManagement.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.jmx.export.annotation.ManagedMetric; -import org.springframework.jmx.support.MetricType; - -/** - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public interface QueueChannelManagement extends PollableChannelManagement { - - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "QueueChannel Queue Size") - int getQueueSize(); - - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "QueueChannel Remaining Capacity") - int getRemainingCapacity(); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/RouterMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/RouterMetrics.java deleted file mode 100644 index d38242719d..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/RouterMetrics.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; - -import org.springframework.context.Lifecycle; - -/** - * Allows Router operations to appear in the same MBean as statistics. - * - * @author Gary Russell - * @since 4.2 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -@SuppressWarnings("deprecation") -public class RouterMetrics extends LifecycleMessageHandlerMetrics implements MappingMessageRouterManagement { - - private final MappingMessageRouterManagement router; - - public RouterMetrics(Lifecycle lifecycle, MappingMessageRouterManagement delegate) { - super(lifecycle, (MessageHandlerMetrics) delegate); - this.router = delegate; - } - - @Override - public void setChannelMapping(String key, String channelName) { - this.router.setChannelMapping(key, channelName); - } - - @Override - public void removeChannelMapping(String key) { - this.router.removeChannelMapping(key); - } - - @Override - public void replaceChannelMappings(Properties channelMappings) { - this.router.replaceChannelMappings(channelMappings); - } - - @Override - public Map getChannelMappings() { - return this.router.getChannelMappings(); - } - - @Override - public void setChannelMappings(Map channelMappings) { - this.router.setChannelMappings(channelMappings); - } - - @Override - public Collection getDynamicChannelNames() { - return this.router.getDynamicChannelNames(); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/Statistics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/Statistics.java deleted file mode 100644 index f26986d678..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/Statistics.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -/** - * Statistics. - * @deprecated in favor of dimensional metrics via - * {@link org.springframework.integration.support.management.metrics.MeterFacade}. - * Built-in metrics will be removed in a future release. - * - * @author Dave Syer - * @author Gary Russell - * @since 2.0 - */ -@Deprecated -public class Statistics { - - private final long count; - - private final double min; - - private final double max; - - private double mean; - - private final double standardDeviation; - - - public Statistics(long count, double min, double max, double mean, double standardDeviation) { - this.count = count; - this.min = min; - this.max = max; - this.mean = mean; - this.standardDeviation = standardDeviation; - } - - - public int getCount() { - return (int) this.count; - } - - public long getCountLong() { - return this.count; - } - - public double getMin() { - return this.min; - } - - public double getMax() { - return this.max; - } - - public double getMean() { - return this.mean; - } - - public void setMean(double mean) { - this.mean = mean; - } - - public double getStandardDeviation() { - return this.standardDeviation; - } - - @Override - public String toString() { - return String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f]", - this.count, this.min, this.max, getMean(), getStandardDeviation()); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/TrackableRouterMetrics.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/TrackableRouterMetrics.java deleted file mode 100644 index 971d274f01..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/TrackableRouterMetrics.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2015-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import org.springframework.context.Lifecycle; -import org.springframework.util.Assert; - -/** - * Adds {@link TrackableComponent}. - * - * @author Gary Russell - * @author Artem Bilan - * - * @since 2.0 - * - * @deprecated in favor of Micrometer metrics. - */ -@Deprecated -public class TrackableRouterMetrics extends RouterMetrics implements TrackableComponent { - - private final TrackableComponent trackable; - - public TrackableRouterMetrics(Lifecycle lifecycle, MappingMessageRouterManagement delegate) { - super(lifecycle, delegate); - Assert.isInstanceOf(TrackableComponent.class, delegate); - this.trackable = (TrackableComponent) delegate; - } - - @Override - public String getBeanName() { - return this.trackable.getBeanName(); - } - - @Override - public String getComponentName() { - return this.trackable.getComponentName(); - } - - @Override - public String getComponentType() { - return this.trackable.getComponentType(); - } - - @Override - public void setShouldTrack(boolean shouldTrack) { - this.trackable.setShouldTrack(shouldTrack); - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java index bf6ad29833..c69e07f7cb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; import org.springframework.integration.support.DefaultMessageBuilderFactory; import org.springframework.integration.support.MessageBuilderFactory; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -38,7 +39,7 @@ import org.springframework.util.ObjectUtils; * @author Artem Bilan */ public abstract class AbstractMessageProcessingTransformer - implements Transformer, BeanFactoryAware, Lifecycle { + implements Transformer, BeanFactoryAware, ManageableLifecycle { private final MessageProcessor messageProcessor; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java index 03a6b6698d..2177d10423 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/ContentEnricher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ import java.util.Map; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.context.Lifecycle; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.expression.spel.SpelParserConfiguration; @@ -34,6 +33,7 @@ import org.springframework.integration.expression.ExpressionUtils; import org.springframework.integration.gateway.MessagingGatewaySupport; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.support.DefaultMessageBuilderFactory; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.transformer.support.HeaderValueMessageProcessor; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -57,7 +57,7 @@ import org.springframework.util.ReflectionUtils; * * @since 2.1 */ -public class ContentEnricher extends AbstractReplyProducingMessageHandler implements Lifecycle { +public class ContentEnricher extends AbstractReplyProducingMessageHandler implements ManageableLifecycle { /** * Customized SpelExpressionParser to allow to specify nested properties when paren is null diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java index deaa8d9c89..4948e8230b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/MessageTransformingHandler.java @@ -25,6 +25,7 @@ import org.springframework.integration.IntegrationPattern; import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.support.context.NamedComponent; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -38,7 +39,7 @@ import org.springframework.util.Assert; * @author Artem Bilan * @author Gary Russell */ -public class MessageTransformingHandler extends AbstractReplyProducingMessageHandler implements Lifecycle { +public class MessageTransformingHandler extends AbstractReplyProducingMessageHandler implements ManageableLifecycle { private final Transformer transformer; diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration.xsd index 0f465d9a9a..19645b99cf 100644 --- a/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration.xsd +++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/spring-integration.xsd @@ -4918,69 +4918,6 @@ The list of component name patterns you want to track (e.g., tracked-components - - - - The default value for components that don't match 'counts-enabled-patterns'. - Defaults to false, or true when an Integration MBean Exporter is provided. - - - - - - - The default value for components that don't match 'stats-enabled-patterns'. - Defaults to false, or true when an Integration MBean Exporter is provided. - - - - - - - Comma separated list of simple patterns for component names for which message counts - will be enabled (defaults to '*'). Only patterns that also match 'managed-components' - will be considered. Enables message counting (`sendCount`, `errorCount`, `receiveCount`) - for those components that support counters (channels, message handlers, etc). - This is the initial setting only, individual components can have counts enabled/disabled - at runtime. May be overridden by an entry in 'stats-enabled' which is additional - functionality over simple counts. If a pattern starts with `!`, counts are disabled - for matches. For components with names that match multiple patterns, the first pattern wins. - Disabling counts at runtime also disables stats. - - - - - - - Comma separated list of simple patterns for component names for which message statistics - will be enabled (response times, rates etc), as well as counts (a positive match here - overrides `counts-enabled`, you can't have statistics without counts). - (defaults to '*'). Only patterns that also match 'managed-components' - will be considered. Enables statistics for those components that support - statistics (channels - when sending, message handlers, etc). - This is the initial setting only, individual components can have stats enabled/disabled - at runtime. If a pattern starts with `!`, stats (and counts) are disabled - for matches. Note: this means that '!foo' here will disable stats - and counts for 'foo' even if counts are enabled for 'foo' in 'counts-enabled'. - For components with names that match multiple patterns, the first pattern wins. - Enabling stats at runtime also enables counts. - - - - - - - - - - - - A MetricsFactory responsible for creating objects that maintain metrics for message - channels and message handlers. - - - diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/MessageChannelReactiveUtilsTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/MessageChannelReactiveUtilsTests.java index 472130bbb4..697ecdc766 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/MessageChannelReactiveUtilsTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/MessageChannelReactiveUtilsTests.java @@ -74,7 +74,6 @@ class MessageChannelReactiveUtilsTests { @Disabled("Backpressure is not honored") void testOverproducingWithSubscribableChannel() { DirectChannel channel = new DirectChannel(); - channel.setCountsEnabled(true); Disposable.Composite compositeDisposable = Disposables.composite(); AtomicInteger sendCount = new AtomicInteger(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java index b728aa3f16..a1a568310f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/manualflow/ManualFlowTests.java @@ -148,15 +148,9 @@ public class ManualFlowTests { assertThat(replyProducers.contains(bridgeHandler)).isTrue(); - assertThat(this.integrationManagementConfigurer.getChannelMetrics("channel")).isNotNull(); - assertThat(this.integrationManagementConfigurer.getHandlerMetrics("bridge")).isNotNull(); - flowRegistration.destroy(); assertThat(replyProducers.contains(bridgeHandler)).isFalse(); - - assertThat(this.integrationManagementConfigurer.getChannelMetrics("channel")).isNull(); - assertThat(this.integrationManagementConfigurer.getHandlerMetrics("bridge")).isNull(); } @Test diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java index cee9ecaf06..43de45fbf8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,6 @@ public class MessagingGatewayTests { this.messagingGateway.setReplyChannel(this.replyChannel); this.messagingGateway.setBeanFactory(this.applicationContext); - this.messagingGateway.setCountsEnabled(true); this.messagingGateway.afterPropertiesSet(); this.messagingGateway.start(); this.applicationContext.refresh(); @@ -93,7 +92,8 @@ public class MessagingGatewayTests { Mockito.when(requestChannel.send(messageMock, 1000L)).thenReturn(true); this.messagingGateway.send(messageMock); Mockito.verify(requestChannel).send(messageMock, 1000L); - assertThat(this.messagingGateway.getMessageCount()).isEqualTo(1); + // TODO Micrometer counter +// assertThat(this.messagingGateway.getMessageCount()).isEqualTo(1); } @Test(expected = MessageDeliveryException.class) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/graph/IntegrationGraphServerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/graph/IntegrationGraphServerTests.java index 9cf63b1718..501f868aef 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/graph/IntegrationGraphServerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/graph/IntegrationGraphServerTests.java @@ -72,8 +72,6 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import net.minidev.json.JSONArray; @@ -154,16 +152,12 @@ public class IntegrationGraphServerTests { jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'router')]"); String routerJson = jsonArray.toJSONString(); - assertThat(routerJson).contains("\"deprecated\":\"stats are deprecated"); - this.server.rebuild(); graph = this.server.getGraph(); baos = new ByteArrayOutputStream(); objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); - objectMapper.registerModule(new SimpleModule().addSerializer(IntegrationNode.Stats.class, - NullSerializer.instance)); objectMapper.writeValue(baos, graph); // System . out . println(new String(baos.toByteArray())); @@ -179,7 +173,6 @@ public class IntegrationGraphServerTests { jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'router')]"); routerJson = jsonArray.toJSONString(); - assertThat(routerJson).contains("\"stats\":null"); assertThat(routerJson).contains("\"sendTimers\":{\"successes\":{\"count\":4"); jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'toRouter')]"); String toRouterJson = jsonArray.toJSONString(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java deleted file mode 100644 index 2ef07599b3..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRateTests.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Deque; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.assertj.core.data.Offset; -import org.junit.Ignore; -import org.junit.Test; - -import org.springframework.integration.test.util.TestUtils; -import org.springframework.util.StopWatch; - -/** - * @author Dave Syer - * @author Gary Russell - * @author Steven Swor - * @author Artem Bilan - */ -@Ignore("Very sensitive to the time. Don't forget to test after some changes.") -@SuppressWarnings("deprecation") -public class ExponentialMovingAverageRateTests { - - private static final Log logger = LogFactory.getLog(ExponentialMovingAverageRateTests.class); - - private final ExponentialMovingAverageRate history = new ExponentialMovingAverageRate(1., 10., 10, true); - - @Test - public void testGetCount() { - assertThat(history.getCount()).isEqualTo(0); - history.increment(); - assertThat(history.getCount()).isEqualTo(1); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetTimeSinceLastMeasurement() { - long sleepTime = 20L; - - // fill history with the same value. - long now = System.nanoTime() - 2 * sleepTime * 1000000; - for (int i = 0; i < TestUtils.getPropertyValue(history, "retention", Integer.class); i++) { - history.increment(now); - } - final Deque times = TestUtils.getPropertyValue(history, "times", Deque.class); - assertThat(times.peekFirst()).isEqualTo(Long.valueOf(now)); - assertThat(times.peekLast()).isEqualTo(Long.valueOf(now)); - - //increment just so we'll have a different value between first and last - history.increment(System.nanoTime() - sleepTime * 1000000); - assertThat(times.peekLast()).isNotEqualTo(times.peekFirst()); - - /* - * We've called Thread.sleep twice with the same value in quick - * succession. If timeSinceLastSend is pulling off the correct end of - * the queue, then we should be closer to the sleep time than we are to - * 2 x sleepTime, but we should definitely be greater than the sleep - * time. - */ - double timeSinceLastMeasurement = history.getTimeSinceLastMeasurement(); - assertThat(timeSinceLastMeasurement > sleepTime).isTrue(); - assertThat(timeSinceLastMeasurement <= (1.5 * sleepTime)).isTrue(); - } - - @Test - public void testGetEarlyMean() throws Exception { - long t0 = System.currentTimeMillis(); - assertThat(history.getMean()).isCloseTo(0, Offset.offset(0.01)); - Thread.sleep(20L); - history.increment(); - long elapsed = System.currentTimeMillis() - t0; - if (elapsed < 30L) { - assertThat(history.getMean() > 10).isTrue(); - } - else { - logger.warn("Test took too long to verify mean"); - } - } - - @Test - public void testGetMean() throws Exception { - long t0 = System.currentTimeMillis(); - assertThat(history.getMean()).isCloseTo(0, Offset.offset(0.01)); - Thread.sleep(20L); - history.increment(); - Thread.sleep(20L); - history.increment(); - double before = history.getMean(); - Statistics statisticsBefore = history.getStatistics(); - long elapsed = System.currentTimeMillis() - t0; - if (elapsed < 50L) { - assertThat(before > 10).isTrue(); - Thread.sleep(20L); - elapsed = System.currentTimeMillis() - t0; - if (elapsed < 80L) { - assertThat(history.getMean()).isLessThan(before); - assertThat(history.getStatistics().getMean()).isLessThan(statisticsBefore.getMean()); - } - else { - logger.warn("Test took too long to verify mean"); - } - } - else { - logger.warn("Test took too long to verify mean"); - } - } - - @Test - public void testGetStandardDeviation() throws Exception { - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - Thread.sleep(20L); - history.increment(); - Thread.sleep(22L); - history.increment(); - Thread.sleep(18L); - assertThat(history.getStandardDeviation() > 0).as("Standard deviation should be non-zero: " + history).isTrue(); - } - - @Test - public void testReset() throws Exception { - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - history.increment(); - Thread.sleep(30L); - history.increment(); - assertThat(0.0).isNotEqualTo(history.getStandardDeviation()); - history.reset(); - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getCount()).isEqualTo(0); - assertThat(history.getTimeSinceLastMeasurement()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getMean()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getMin()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getMax()).isCloseTo(0, Offset.offset(0.01)); - } - - @Test - public void testRate() { - ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10); - int count = 1000000; - StopWatch watch = new StopWatch(); - watch.start(); - for (int i = 0; i < count; i++) { - rate.increment(); - } - watch.stop(); - double calculatedRate = count / (double) watch.getTotalTimeMillis() * 1000; - assertThat(rate.getMean()).isEqualTo(calculatedRate, Offset.offset(4000000d)); - } - - @Test - public void testPerf() { - ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10); - for (int i = 0; i < 1000000; i++) { - rate.increment(); - } - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRatioTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRatioTests.java deleted file mode 100644 index c078e6e47c..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageRatioTests.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Deque; - -import org.assertj.core.data.Offset; -import org.junit.Ignore; -import org.junit.Test; - -import org.springframework.integration.test.util.TestUtils; - -/** - * @author Dave Syer - * @author Gary Russell - * @author Artem Bilan - * @author Steven Swor - */ -@Ignore("Very sensitive to the time. Don't forget to test after some changes.") -@SuppressWarnings("deprecation") -public class ExponentialMovingAverageRatioTests { - - private final ExponentialMovingAverageRatio history = new ExponentialMovingAverageRatio(0.5, 10, true); - - @Test - public void testGetCount() { - assertThat(history.getCount()).isEqualTo(0); - history.success(); - assertThat(history.getCount()).isEqualTo(1); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetTimeSinceLastMeasurement() { - long sleepTime = 20L; - // fill history with the same value. - long now = System.nanoTime() - 2 * sleepTime * 1000000; - for (int i = 0; i < TestUtils.getPropertyValue(history, "retention", Integer.class); i++) { - history.success(now); - } - final Deque times = TestUtils.getPropertyValue(history, "times", Deque.class); - assertThat(times.peekFirst()).isEqualTo(Long.valueOf(now)); - assertThat(times.peekLast()).isEqualTo(Long.valueOf(now)); - - //increment just so we'll have a different value between first and last - history.success(System.nanoTime() - sleepTime * 1000000); - assertThat(times.peekLast()).isNotEqualTo(times.peekFirst()); - - /* - * We've called Thread.sleep twice with the same value in quick - * succession. If timeSinceLastSend is pulling off the correct end of - * the queue, then we should be closer to the sleep time than we are to - * 2 x sleepTime, but we should definitely be greater than the sleep - * time. - */ - double timeSinceLastMeasurement = history.getTimeSinceLastMeasurement(); - assertThat(timeSinceLastMeasurement).isGreaterThan(sleepTime / 100); - assertThat(timeSinceLastMeasurement).isLessThanOrEqualTo(1.5 * sleepTime / 100); - } - - @Test - public void testGetEarlyMean() { - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.success(); - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - } - - @Test - public void testGetEarlyFailure() { - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.failure(); - assertThat(history.getMean()).isCloseTo(0, Offset.offset(0.01)); - } - - @Test - public void testDecayedMean() throws Exception { - history.failure(System.nanoTime() - 200000000); - assertThat(history.getMean()).isCloseTo(average(0, Math.exp(-0.4)), Offset.offset(0.01)); - history.success(); - history.failure(); - double mean = history.getMean(); - Statistics statistics = history.getStatistics(); - Thread.sleep(50); - assertThat(history.getMean()).isGreaterThan(mean); - assertThat(history.getStatistics().getMean()).isGreaterThan(statistics.getMean()); - } - - @Test - public void testGetMean() { - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.success(); - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.success(); - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.success(); - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - } - - @Test - public void testGetMeanFailuresHighRate() { - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.success(); // need an extra now that we can't determine the time between the first and previous - history.success(); - assertThat(history.getMean()).isCloseTo(average(1), Offset.offset(0.01)); - history.failure(); - assertThat(history.getMean()).isCloseTo(average(1, 0.5), Offset.offset(0.1)); - history.success(); - assertThat(history.getMean()).isCloseTo(average(1, 0.5, 0.67), Offset.offset(0.1)); - } - - @Test - public void testGetMeanFailuresLowRate() { - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - history.failure(); // need an extra now that we can't determine the time between the first and previous - history.failure(); - assertThat(history.getMean()).isCloseTo(average(0), Offset.offset(0.01)); - history.failure(); - assertThat(history.getMean()).isCloseTo(average(0, 0), Offset.offset(0.01)); - history.success(); - assertThat(history.getMean()).isCloseTo(average(0, 0, 0.33), Offset.offset(0.1)); - } - - @Test - public void testGetStandardDeviation() { - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - history.success(); - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(1d)); - } - - @Test - public void testReset() { - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - history.success(); - history.failure(); - assertThat(history.getStandardDeviation()).isNotEqualTo(0); - history.reset(); - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getCount()).isEqualTo(0); - assertThat(history.getTimeSinceLastMeasurement()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - assertThat(history.getMin()).isCloseTo(0, Offset.offset(0.01)); - assertThat(history.getMax()).isCloseTo(0, Offset.offset(0.01)); - history.success(); - assertThat(history.getMin()).isCloseTo(1, Offset.offset(0.01)); - } - - private double average(double... values) { - int count = 0; - double sum = 0; - for (double d : values) { - sum += d; - count++; - } - return sum / count; - } - - @Test - public void testRatio() { - ExponentialMovingAverageRatio ratio = new ExponentialMovingAverageRatio(60, 10, true); - for (int i = 0; i < 100; i++) { - if (i % 10 == 1) { - ratio.failure(); - } - else { - ratio.success(); - } - } - assertThat(ratio.getMax()).isCloseTo(0.9, Offset.offset(0.02)); - assertThat(ratio.getMean()).isCloseTo(0.9, Offset.offset(0.03)); - } - - @Test - @Ignore - public void testPerf() { - ExponentialMovingAverageRatio ratio = new ExponentialMovingAverageRatio(60, 10); - for (int i = 0; i < 100000; i++) { - if (i % 10 == 0) { - ratio.failure(); - } - else { - ratio.success(); - } - } - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageTests.java deleted file mode 100644 index 829cb9fd6b..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/ExponentialMovingAverageTests.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.support.management; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.assertj.core.data.Offset; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author Dave Syer - * @author Artem Bilan - * @author Gary Russell - */ -@Ignore("Very sensitive to the time. Don't forget to test after some changes.") -@SuppressWarnings("deprecation") -public class ExponentialMovingAverageTests { - - private final ExponentialMovingAverage history = new ExponentialMovingAverage(10); - - - @Test - @Ignore // used to compare LinkedList to ArrayDeque which was 35% faster - public void perf() { - for (int i = 0; i < 100000000; i++) { - history.append(0.0); - } - } - - @Test - public void testGetCount() { - assertThat(history.getCount()).isEqualTo(0); - history.append(1); - assertThat(history.getCount()).isEqualTo(1); - } - - @Test - public void testGetMean() { - assertThat(history.getMean()).isCloseTo(0, Offset.offset(0.01)); - history.append(1); - history.append(1); - assertThat(history.getMean()).isCloseTo(1, Offset.offset(0.01)); - } - - @Test - public void testGetStandardDeviation() { - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - history.append(1); - history.append(1); - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - } - - @Test - public void testReset() { - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - history.append(1); - history.append(2); - assertThat(0 == history.getStandardDeviation()).isFalse(); - history.reset(); - assertThat(history.getStandardDeviation()).isCloseTo(0, Offset.offset(0.01)); - // INT-2165 - assertThat(history.toString()) - .isEqualTo(String.format("[N=%d, min=%f, max=%f, mean=%f, sigma=%f]", 0, 0d, 0d, 0d, 0d)); - history.append(1); - assertThat(history.getMin()).isCloseTo(1, Offset.offset(0.01)); - } - - @Test - public void testAv() { - ExponentialMovingAverage av = new ExponentialMovingAverage(10); - for (int i = 0; i < 10000; i++) { - switch (i % 3) { - case 0: - av.append(20); - break; - case 1: - av.append(30); - break; - case 2: - av.append(40); - break; - } - } - assertThat(av.getMax()).isCloseTo(40, Offset.offset(0.1)); - assertThat(av.getMin()).isCloseTo(20, Offset.offset(0.1)); - assertThat(av.getMean()).isCloseTo(30, Offset.offset(1.0)); - } - - @Test - @Ignore - public void testPerf() { - ExponentialMovingAverage av = new ExponentialMovingAverage(10); - for (int i = 0; i < 10000000; i++) { - switch (i % 4) { - case 0: - av.append(20); - break; - case 1: - av.append(30); - break; - case 2: - av.append(40); - break; - - case 3: - av.append(50); - break; - } - } - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java index 3e20cee79e..404d3dc6ed 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/management/IntegrationManagementConfigurerTests.java @@ -66,8 +66,6 @@ public class IntegrationManagementConfigurerTests { assertThat(channel.isLoggingEnabled()).isTrue(); assertThat(handler.isLoggingEnabled()).isTrue(); assertThat(source.isLoggingEnabled()).isTrue(); - channel.setCountsEnabled(true); - channel.setStatsEnabled(true); ApplicationContext ctx = mock(ApplicationContext.class); Map beans = new HashMap(); beans.put("foo", channel); @@ -82,8 +80,6 @@ public class IntegrationManagementConfigurerTests { assertThat(channel.isLoggingEnabled()).isFalse(); assertThat(handler.isLoggingEnabled()).isFalse(); assertThat(source.isLoggingEnabled()).isFalse(); - assertThat(channel.isCountsEnabled()).isTrue(); - assertThat(channel.isStatsEnabled()).isTrue(); } @Test @@ -91,8 +87,6 @@ public class IntegrationManagementConfigurerTests { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigEmptyAnnotation.class); AbstractMessageChannel channel = ctx.getBean("channel", AbstractMessageChannel.class); - assertThat(channel.isCountsEnabled()).isTrue(); - assertThat(channel.isStatsEnabled()).isTrue(); channel = ctx.getBean("loggingOffChannel", AbstractMessageChannel.class); assertThat(channel.isLoggingEnabled()).isFalse(); ctx.close(); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java index 4d4c740d03..542b88a3cb 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileReadingMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,7 @@ import org.springframework.integration.file.filters.DiscardAwareFileListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.ResettableFileListFilter; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -91,7 +92,7 @@ import org.springframework.util.Assert; * @author Steven Pearce */ public class FileReadingMessageSource extends AbstractMessageSource - implements Lifecycle { + implements ManageableLifecycle { private static final int DEFAULT_INTERNAL_QUEUE_CAPACITY = 5; @@ -416,7 +417,7 @@ public class FileReadingMessageSource extends AbstractMessageSource } - private class WatchServiceDirectoryScanner extends DefaultDirectoryScanner implements Lifecycle { + private class WatchServiceDirectoryScanner extends DefaultDirectoryScanner implements ManageableLifecycle { private final ConcurrentMap pathKeys = new ConcurrentHashMap<>(); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index 8b87af7fa4..712f6e8c09 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.Lifecycle; import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; import org.springframework.expression.spel.support.StandardEvaluationContext; @@ -58,6 +57,7 @@ import org.springframework.integration.handler.MessageTriggerAction; import org.springframework.integration.support.locks.DefaultLockRegistry; import org.springframework.integration.support.locks.LockRegistry; import org.springframework.integration.support.locks.PassThruLockRegistry; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.integration.util.WhileLockedProcessor; import org.springframework.messaging.Message; @@ -109,7 +109,7 @@ import org.springframework.util.StringUtils; * @author Alen Turkovic */ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHandler - implements Lifecycle, MessageTriggerAction { + implements ManageableLifecycle, MessageTriggerAction { private static final int DEFAULT_BUFFER_SIZE = 8192; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java index 637118be47..09595e81c4 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/AbstractRemoteFileStreamingMessageSource.java @@ -29,7 +29,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.springframework.context.Lifecycle; import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; import org.springframework.integration.IntegrationMessageHeaderAccessor; @@ -40,6 +39,7 @@ import org.springframework.integration.file.filters.ResettableFileListFilter; import org.springframework.integration.file.filters.ReversibleFileListFilter; import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.support.FileUtils; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -56,7 +56,7 @@ import org.springframework.util.ObjectUtils; * */ public abstract class AbstractRemoteFileStreamingMessageSource - extends AbstractFetchLimitingMessageSource implements Lifecycle { + extends AbstractFetchLimitingMessageSource implements ManageableLifecycle { private final RemoteFileTemplate remoteFileTemplate; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java index dae464a101..2eb65d115f 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.Comparator; import java.util.regex.Pattern; import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.context.Lifecycle; import org.springframework.integration.endpoint.AbstractFetchLimitingMessageSource; import org.springframework.integration.file.DefaultDirectoryScanner; import org.springframework.integration.file.DirectoryScanner; @@ -37,6 +36,7 @@ import org.springframework.integration.file.filters.FileSystemPersistentAcceptOn import org.springframework.integration.file.filters.RegexPatternFileListFilter; import org.springframework.integration.metadata.SimpleMetadataStore; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.util.Assert; /** @@ -65,7 +65,7 @@ import org.springframework.util.Assert; */ public abstract class AbstractInboundFileSynchronizingMessageSource extends AbstractFetchLimitingMessageSource - implements Lifecycle { + implements ManageableLifecycle { /** * An implementation that will handle the chores of actually connecting to and synchronizing diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java index 07b66f08ce..d3f5b76621 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java @@ -144,11 +144,7 @@ public class FtpTests extends FtpTestSupport { MessageSource source = context.getBean(FtpInboundFileSynchronizingMessageSource.class); assertThat(TestUtils.getPropertyValue(source, "maxFetchSize")).isEqualTo(10); - assertThat(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source")).isNotNull(); - registration.destroy(); - - assertThat(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source")).isNull(); } @Test diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/AbstractInternetProtocolSendingMessageHandler.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/AbstractInternetProtocolSendingMessageHandler.java index 014d8d5329..dd788086f3 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/AbstractInternetProtocolSendingMessageHandler.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/AbstractInternetProtocolSendingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ package org.springframework.integration.ip; import java.net.InetSocketAddress; import java.net.SocketAddress; -import org.springframework.context.Lifecycle; import org.springframework.integration.handler.AbstractMessageHandler; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.util.Assert; /** @@ -29,8 +29,8 @@ import org.springframework.util.Assert; * @author Gary Russell * @since 2.0 */ -public abstract class AbstractInternetProtocolSendingMessageHandler extends AbstractMessageHandler implements CommonSocketOptions, - Lifecycle { +public abstract class AbstractInternetProtocolSendingMessageHandler extends AbstractMessageHandler + implements CommonSocketOptions, ManageableLifecycle { private final SocketAddress destinationAddress; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java index 8db3f8f2a1..c48db1c7e9 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java @@ -42,6 +42,7 @@ import org.springframework.integration.ip.tcp.connection.TcpConnectionFailedCorr import org.springframework.integration.ip.tcp.connection.TcpListener; import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport; import org.springframework.integration.ip.tcp.connection.TcpSender; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandlingException; @@ -65,7 +66,7 @@ import org.springframework.util.concurrent.SettableListenableFuture; * @since 2.0 */ public class TcpOutboundGateway extends AbstractReplyProducingMessageHandler - implements TcpSender, TcpListener, Lifecycle { + implements TcpSender, TcpListener, ManageableLifecycle { private static final long DEFAULT_REMOTE_TIMEOUT = 10_000L; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandler.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandler.java index de2c808623..5f0aadd489 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandler.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.Lifecycle; import org.springframework.integration.handler.AbstractMessageHandler; import org.springframework.integration.ip.IpHeaders; import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory; @@ -33,6 +32,7 @@ import org.springframework.integration.ip.tcp.connection.ConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpConnection; import org.springframework.integration.ip.tcp.connection.TcpConnectionFailedCorrelationEvent; import org.springframework.integration.ip.tcp.connection.TcpSender; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandlingException; @@ -52,7 +52,7 @@ import org.springframework.util.Assert; * */ public class TcpSendingMessageHandler extends AbstractMessageHandler implements - TcpSender, Lifecycle, ClientModeCapable { + TcpSender, ManageableLifecycle, ClientModeCapable { /** * A default retry interval for the {@link ClientModeConnectionManager} rescheduling. diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java index 05e0c5b2f0..eb9689d071 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/ConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2019 the original author or authors. + * Copyright 2001-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.integration.ip.tcp.connection; -import org.springframework.context.Lifecycle; +import org.springframework.integration.support.management.ManageableLifecycle; @@ -27,7 +27,7 @@ import org.springframework.context.Lifecycle; * @since 2.0 * */ -public interface ConnectionFactory extends Lifecycle { +public interface ConnectionFactory extends ManageableLifecycle { TcpConnection getConnection() throws InterruptedException; diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java index 80cf3a9e44..d6c1201ad4 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java @@ -45,7 +45,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.core.convert.ConversionService; import org.springframework.expression.Expression; import org.springframework.integration.MessageTimeoutException; @@ -54,6 +53,7 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHand import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor; import org.springframework.integration.jms.util.JmsAdapterUtils; import org.springframework.integration.support.AbstractIntegrationMessageBuilder; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.util.JavaUtils; import org.springframework.jms.connection.ConnectionFactoryUtils; import org.springframework.jms.listener.DefaultMessageListenerContainer; @@ -82,7 +82,8 @@ import org.springframework.util.concurrent.SettableListenableFuture; * @author Gary Russell * @author Artem Bilan */ -public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler implements Lifecycle, MessageListener { +public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler + implements ManageableLifecycle, MessageListener { /** * A default receive timeout in milliseconds. diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java index d8da654ce2..a3cca1fde5 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java @@ -38,10 +38,8 @@ import org.springframework.messaging.support.ExecutorChannelInterceptor; * * @since 2.0 */ -@SuppressWarnings("deprecation") public class PollableJmsChannel extends AbstractJmsChannel - implements PollableChannel, org.springframework.integration.support.management.PollableChannelManagement, - ExecutorChannelInterceptorAware { + implements PollableChannel, ExecutorChannelInterceptorAware { private String messageSelector; @@ -57,50 +55,6 @@ public class PollableJmsChannel extends AbstractJmsChannel this.messageSelector = messageSelector; } - /** - * Deprecated. - * @return receive count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getReceiveCount() { - return getMetrics().getReceiveCount(); - } - - /** - * Deprecated. - * @return receive count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getReceiveCountLong() { - return getMetrics().getReceiveCountLong(); - } - - /** - * Deprecated. - * @return receive error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public int getReceiveErrorCount() { - return getMetrics().getReceiveErrorCount(); - } - - /** - * Deprecated. - * @return receive error count - * @deprecated in favor of Micrometer metrics. - */ - @Deprecated - @Override - public long getReceiveErrorCountLong() { - return getMetrics().getReceiveErrorCountLong(); - } - @Override @Nullable public Message receive(long timeout) { @@ -119,7 +73,6 @@ public class PollableJmsChannel extends AbstractJmsChannel ChannelInterceptorList interceptorList = getIChannelInterceptorList(); Deque interceptorStack = null; boolean counted = false; - boolean countsEnabled = isCountsEnabled(); try { if (isLoggingEnabled() && logger.isTraceEnabled()) { logger.trace("preReceive on channel '" + this + "'"); @@ -146,11 +99,8 @@ public class PollableJmsChannel extends AbstractJmsChannel } } else { - if (countsEnabled) { - incrementReceiveCounter(); - getMetrics().afterReceive(); - counted = true; - } + incrementReceiveCounter(); + counted = true; if (object instanceof Message) { message = (Message) object; } @@ -170,7 +120,7 @@ public class PollableJmsChannel extends AbstractJmsChannel return message; } catch (RuntimeException ex) { - if (countsEnabled && !counted) { + if (!counted) { incrementReceiveErrorCounter(ex); } interceptorList.afterReceiveCompletion(null, this, ex, interceptorStack); @@ -193,7 +143,6 @@ public class PollableJmsChannel extends AbstractJmsChannel if (metricsCaptor != null) { buildReceiveCounter(metricsCaptor, ex).increment(); } - getMetrics().afterError(); } private CounterFacade buildReceiveCounter(MetricsCaptor metricsCaptor, @Nullable Exception ex) { diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/SubscribableJmsChannel.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/SubscribableJmsChannel.java index e977ad38ea..3ed5de1aaf 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/SubscribableJmsChannel.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/SubscribableJmsChannel.java @@ -21,7 +21,6 @@ import javax.jms.MessageListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.context.SmartLifecycle; import org.springframework.integration.MessageDispatchingException; import org.springframework.integration.channel.BroadcastCapableChannel; import org.springframework.integration.context.IntegrationProperties; @@ -31,6 +30,7 @@ import org.springframework.integration.dispatcher.MessageDispatcher; import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy; import org.springframework.integration.dispatcher.UnicastingDispatcher; import org.springframework.integration.support.MessageBuilderFactory; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.AbstractMessageListenerContainer; import org.springframework.jms.support.converter.MessageConverter; @@ -52,7 +52,7 @@ import org.springframework.util.Assert; * @since 2.0 */ public class SubscribableJmsChannel extends AbstractJmsChannel - implements BroadcastCapableChannel, SmartLifecycle { + implements BroadcastCapableChannel, ManageableSmartLifecycle { private final AbstractMessageListenerContainer container; diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java index 53bbb8d4cd..4e0ad334fa 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/IntegrationMBeanExportConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -111,14 +111,6 @@ public class IntegrationMBeanExportConfiguration implements ImportAware, Environ setupDomain(exporter); setupServer(exporter); setupComponentNamePatterns(exporter); - if (this.configurer != null) { - if (this.configurer.getDefaultCountsEnabled() == null) { - this.configurer.setDefaultCountsEnabled(true); - } - if (this.configurer.getDefaultStatsEnabled() == null) { - this.configurer.setDefaultStatsEnabled(true); - } - } return exporter; } diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java index c0e32b5e6f..25839d24aa 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMBeanExporter.java @@ -42,6 +42,7 @@ import org.springframework.beans.factory.config.DestructionAwareBeanPostProcesso import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.Lifecycle; +import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.config.IntegrationManagementConfigurer; @@ -50,15 +51,17 @@ import org.springframework.integration.context.OrderlyShutdownCapable; import org.springframework.integration.core.MessageProducer; import org.springframework.integration.core.MessageSource; import org.springframework.integration.endpoint.AbstractEndpoint; +import org.springframework.integration.endpoint.AbstractMessageSource; import org.springframework.integration.endpoint.IntegrationConsumer; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.gateway.MessagingGatewaySupport; +import org.springframework.integration.handler.AbstractMessageHandler; import org.springframework.integration.handler.AbstractMessageProducingHandler; import org.springframework.integration.history.MessageHistoryConfigurer; import org.springframework.integration.support.context.NamedComponent; -import org.springframework.integration.support.management.MappingMessageRouterManagement; -import org.springframework.integration.support.management.MessageSourceManagement; -import org.springframework.integration.support.management.TrackableComponent; +import org.springframework.integration.support.management.IntegrationInboundManagement; +import org.springframework.integration.support.management.IntegrationManagement; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.integration.support.utils.PatternMatchUtils; import org.springframework.jmx.export.MBeanExporter; import org.springframework.jmx.export.UnableToRegisterMBeanException; @@ -66,8 +69,10 @@ import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.jmx.export.annotation.ManagedMetric; import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; +import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler; import org.springframework.jmx.export.naming.MetadataNamingStrategy; import org.springframework.jmx.support.MetricType; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; @@ -116,22 +121,15 @@ public class IntegrationMBeanExporter extends MBeanExporter private final Map anonymousSourceCounters = new HashMap<>(); - private final Set - handlers = new HashSet<>(); + private final Map handlers = new HashMap<>(); - private final Set - sources = new HashSet<>(); + private final Map sources = new HashMap<>(); + + private final Map sourceLifecycles = new HashMap<>(); private final Set inboundLifecycleMessageProducers = new HashSet<>(); - private final Set - channels = new HashSet<>(); - - private final Map - allChannelsByName = new HashMap<>(); - - private final Map - allSourcesByName = new HashMap<>(); + private final Map channels = new HashMap<>(); private final Map endpointsByMonitor = new HashMap<>(); @@ -146,7 +144,7 @@ public class IntegrationMBeanExporter extends MBeanExporter private final Set runtimeBeans = new HashSet<>(); private final MetadataNamingStrategy defaultNamingStrategy = - new IntegrationMetadataNamingStrategy(this.attributeSource); + new MetadataNamingStrategy(this.attributeSource); private String domain = DEFAULT_DOMAIN; @@ -162,7 +160,7 @@ public class IntegrationMBeanExporter extends MBeanExporter // Shouldn't be necessary, but to be on the safe side... setAutodetect(false); setNamingStrategy(this.defaultNamingStrategy); - setAssembler(new IntegrationMetadataMBeanInfoAssembler(this.attributeSource)); + setAssembler(new MetadataMBeanInfoAssembler(this.attributeSource)); } /** @@ -248,14 +246,12 @@ public class IntegrationMBeanExporter extends MBeanExporter } private void populateMessageHandlers() { - Map messageHandlers = - this.applicationContext - .getBeansOfType(org.springframework.integration.support.management.MessageHandlerMetrics.class); - for (Entry entry - : messageHandlers.entrySet()) { + Map messageHandlers = this.applicationContext + .getBeansOfType(MessageHandler.class); + for (Entry entry : messageHandlers.entrySet()) { String beanName = entry.getKey(); - org.springframework.integration.support.management.MessageHandlerMetrics bean = entry.getValue(); + MessageHandler bean = entry.getValue(); if (this.handlerInAnonymousWrapper(bean) != null) { if (logger.isDebugEnabled()) { logger.debug("Skipping " + beanName + " because it wraps another handler"); @@ -264,34 +260,35 @@ public class IntegrationMBeanExporter extends MBeanExporter } // If the handler is proxied, we have to extract the target to expose as an MBean. // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies. - org.springframework.integration.support.management.MessageHandlerMetrics monitor = - (org.springframework.integration.support.management.MessageHandlerMetrics) extractTarget(bean); - this.handlers.add(monitor); + MessageHandler monitor = (MessageHandler) extractTarget(bean); + if (monitor instanceof IntegrationManagement) { + this.handlers.put(beanName, (IntegrationManagement) monitor); + } } } private void populateMessageSources() { this.applicationContext.getBeansOfType( - org.springframework.integration.support.management.MessageSourceMetrics.class) + IntegrationInboundManagement.class) .values() .stream() - // If the channel is proxied, we have to extract the target to expose as an MBean. + // If the source is proxied, we have to extract the target to expose as an MBean. // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies. .map(this::extractTarget) - .map(org.springframework.integration.support.management.MessageSourceMetrics.class::cast) - .forEach(this.sources::add); + .map(IntegrationInboundManagement.class::cast) + .forEach(src -> this.sources.put(src.getComponentName(), src)); } private void populateMessageChannels() { - this.applicationContext.getBeansOfType( - org.springframework.integration.support.management.MessageChannelMetrics.class) + this.applicationContext.getBeansOfType(MessageChannel.class) .values() .stream() // If the channel is proxied, we have to extract the target to expose as an MBean. // The MetadataMBeanInfoAssembler does not support JDK dynamic proxies. .map(this::extractTarget) - .map(org.springframework.integration.support.management.MessageChannelMetrics.class::cast) - .forEach(this.channels::add); + .filter(ch -> ch instanceof IntegrationManagement) + .map(IntegrationManagement.class::cast) + .forEach(ch -> this.channels.put(ch.getComponentName(), ch)); } private void populateMessageProducers() { @@ -305,8 +302,6 @@ public class IntegrationMBeanExporter extends MBeanExporter private void configureManagementConfigurer() { if (!this.applicationContext.containsBean(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)) { this.managementConfigurer = new IntegrationManagementConfigurer(); - this.managementConfigurer.setDefaultCountsEnabled(true); - this.managementConfigurer.setDefaultStatsEnabled(true); this.managementConfigurer.setApplicationContext(this.applicationContext); this.managementConfigurer.setBeanName(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME); this.managementConfigurer.afterSingletonsInstantiated(); @@ -322,12 +317,13 @@ public class IntegrationMBeanExporter extends MBeanExporter public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (this.singletonsInstantiated) { try { - if (bean instanceof org.springframework.integration.support.management.MessageChannelMetrics) { - org.springframework.integration.support.management.MessageChannelMetrics monitor = - (org.springframework.integration.support.management.MessageChannelMetrics) extractTarget(bean); - this.channels.add(monitor); - registerChannel(monitor); - this.runtimeBeans.add(bean); + if (bean instanceof MessageChannel) { + MessageChannel monitor = (MessageChannel) extractTarget(bean); + if (monitor instanceof IntegrationManagement) { + this.channels.put(beanName, (IntegrationManagement) monitor); + registerChannel((IntegrationManagement) monitor); + this.runtimeBeans.add(bean); + } } else if (bean instanceof MessageProducer && bean instanceof Lifecycle) { registerProducer((MessageProducer) bean); @@ -348,25 +344,23 @@ public class IntegrationMBeanExporter extends MBeanExporter if (bean instanceof IntegrationConsumer) { IntegrationConsumer integrationConsumer = (IntegrationConsumer) bean; MessageHandler handler = integrationConsumer.getHandler(); - if (handler instanceof org.springframework.integration.support.management.MessageHandlerMetrics) { - org.springframework.integration.support.management.MessageHandlerMetrics messageHandlerMetrics = - (org.springframework.integration.support.management.MessageHandlerMetrics) extractTarget(handler); - registerHandler(messageHandlerMetrics); - this.handlers.add(messageHandlerMetrics); - this.runtimeBeans.add(messageHandlerMetrics); - return; + MessageHandler monitor = (MessageHandler) extractTarget(handler); + if (monitor instanceof IntegrationManagement) { + registerHandler((IntegrationManagement) monitor); + this.handlers.put(((IntegrationManagement) monitor).getComponentName(), + (IntegrationManagement) monitor); + this.runtimeBeans.add(monitor); } + return; } else if (bean instanceof SourcePollingChannelAdapter) { SourcePollingChannelAdapter pollingChannelAdapter = (SourcePollingChannelAdapter) bean; MessageSource messageSource = pollingChannelAdapter.getMessageSource(); - if (messageSource instanceof org.springframework.integration.support.management.MessageSourceMetrics) { - org.springframework.integration.support.management.MessageSourceMetrics messageSourceMetrics = - (org.springframework.integration.support.management.MessageSourceMetrics) - extractTarget(messageSource); - registerSource(messageSourceMetrics); - this.sources.add(messageSourceMetrics); - this.runtimeBeans.add(messageSourceMetrics); + if (messageSource instanceof IntegrationInboundManagement) { + IntegrationInboundManagement monitor = (IntegrationInboundManagement) extractTarget(messageSource); + registerSource(monitor); + this.sourceLifecycles.put(monitor, pollingChannelAdapter); + this.runtimeBeans.add(monitor); return; } } @@ -384,9 +378,9 @@ public class IntegrationMBeanExporter extends MBeanExporter @Override public boolean requiresDestruction(Object bean) { - return bean instanceof org.springframework.integration.support.management.MessageChannelMetrics || // NOSONAR - bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics || - bean instanceof org.springframework.integration.support.management.MessageSourceMetrics || + return bean instanceof AbstractMessageChannel || // NOSONAR + bean instanceof AbstractMessageHandler || + bean instanceof AbstractMessageSource || (bean instanceof MessageProducer && bean instanceof Lifecycle) || bean instanceof AbstractEndpoint; } @@ -403,21 +397,16 @@ public class IntegrationMBeanExporter extends MBeanExporter else { this.endpointsByMonitor.remove(bean); - if (bean instanceof org.springframework.integration.support.management.MessageChannelMetrics) { - this.channels.remove(bean); - this.allChannelsByName.remove(((NamedComponent) bean).getComponentName()); + if (bean instanceof IntegrationManagement) { + this.channels.remove(((NamedComponent) bean).getComponentName()); } - else if (bean instanceof org.springframework.integration.support.management.MessageHandlerMetrics) { - this.handlers.remove(bean); + else if (bean instanceof IntegrationManagement) { + this.handlers.remove(((NamedComponent) bean).getComponentName()); this.endpointNames.remove(((NamedComponent) bean).getComponentName()); } - else if (bean instanceof org.springframework.integration.support.management.MessageSourceMetrics) { - this.sources.remove(bean); + else if (bean instanceof IntegrationInboundManagement) { + this.sources.remove(((NamedComponent) bean).getComponentName()); this.endpointNames.remove(((NamedComponent) bean).getComponentName()); - String managedName = - ((org.springframework.integration.support.management.MessageSourceMetrics) bean) - .getManagedName(); - this.allSourcesByName.remove(managedName); } } } @@ -488,20 +477,6 @@ public class IntegrationMBeanExporter extends MBeanExporter } } - @Override - public void destroy() { - super.destroy(); - for (org.springframework.integration.support.management.MessageChannelMetrics monitor : this.channels) { - logger.info("Summary on shutdown: " + monitor); - } - for (org.springframework.integration.support.management.MessageHandlerMetrics monitor : this.handlers) { - logger.info("Summary on shutdown: " + monitor); - } - for (org.springframework.integration.support.management.MessageSourceMetrics monitor : this.sources) { - logger.info("Summary on shutdown: " + monitor); - } - } - /** * Shutdown active components. * @param howLong The time to wait in total for all activities to complete @@ -556,20 +531,11 @@ public class IntegrationMBeanExporter extends MBeanExporter */ @ManagedOperation public void stopMessageSources() { - for (org.springframework.integration.support.management.MessageSourceMetrics sourceMetrics - : this.allSourcesByName.values()) { - - if (sourceMetrics instanceof Lifecycle) { - if (logger.isInfoEnabled()) { - logger.info("Stopping message source " + sourceMetrics); - } - ((Lifecycle) sourceMetrics).stop(); - } - else { - if (logger.isInfoEnabled()) { - logger.info("Message source " + sourceMetrics + " cannot be stopped"); - } + for (Lifecycle source : this.sourceLifecycles.values()) { + if (logger.isInfoEnabled()) { + logger.info("Stopping message source " + source); } + source.stop(); } } @@ -592,8 +558,8 @@ public class IntegrationMBeanExporter extends MBeanExporter @ManagedOperation public void stopActiveChannels() { // Stop any "active" channels (JMS etc). - for (org.springframework.integration.support.management.MessageChannelMetrics metrics : this.allChannelsByName.values()) { - MessageChannel channel = (MessageChannel) metrics; + for (IntegrationManagement metrics : this.channels.values()) { + IntegrationManagement channel = metrics; if (channel instanceof Lifecycle) { if (logger.isInfoEnabled()) { logger.info("Stopping channel " + channel); @@ -631,41 +597,41 @@ public class IntegrationMBeanExporter extends MBeanExporter @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageChannel Count") public int getChannelCount() { - return this.managementConfigurer.getChannelNames().length; + return this.channels.size(); } @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageHandler Count") public int getHandlerCount() { - return this.managementConfigurer.getHandlerNames().length; + return this.handlers.size(); } @ManagedMetric(metricType = MetricType.COUNTER, displayName = "MessageSource Count") public int getSourceCount() { - return this.managementConfigurer.getSourceNames().length; + return this.sources.size(); } @ManagedAttribute public String[] getHandlerNames() { - return this.managementConfigurer.getHandlerNames(); + return this.handlers.values().stream() + .map(hand -> hand.getManagedName()) + .toArray(n -> new String[n]); } - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count") + @Deprecated + @ManagedMetric(metricType = MetricType.GAUGE, displayName = "No longer supported") public int getActiveHandlerCount() { - return (int) getActiveHandlerCountLong(); + return 0; } - @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Active Handler Count") + @Deprecated + @ManagedMetric(metricType = MetricType.GAUGE, displayName = "No longer supported") public long getActiveHandlerCountLong() { - int count = 0; - for (org.springframework.integration.support.management.MessageHandlerMetrics monitor : this.handlers) { - count += monitor.getActiveCountLong(); - } - return count; + return 0; } @ManagedMetric(metricType = MetricType.GAUGE, displayName = "Queued Message Count") public int getQueuedMessageCount() { - return this.channels.stream() + return this.channels.values().stream() .filter(QueueChannel.class::isInstance) .map(QueueChannel.class::cast) .mapToInt(QueueChannel::getQueueSize) @@ -674,93 +640,51 @@ public class IntegrationMBeanExporter extends MBeanExporter @ManagedAttribute public String[] getChannelNames() { - return this.managementConfigurer.getChannelNames(); + return this.channels.keySet().stream() + .toArray(n -> new String[n]); } - public org.springframework.integration.support.management.MessageHandlerMetrics getHandlerMetrics(String name) { - return this.managementConfigurer.getHandlerMetrics(name); + @Nullable + @Deprecated + public AbstractMessageHandler getHandlerMetrics(String name) { + return null; } - public org.springframework.integration.support.management.Statistics getHandlerDuration(String name) { - org.springframework.integration.support.management.MessageHandlerMetrics handlerMetrics = getHandlerMetrics(name); - return handlerMetrics != null ? handlerMetrics.getDuration() : null; + @Nullable + public IntegrationManagement getHandler(String name) { + return this.handlers.get(name); } @ManagedAttribute public String[] getSourceNames() { - return this.managementConfigurer.getSourceNames(); + return this.sources.keySet().stream() + .toArray(n -> new String[n]); } - public org.springframework.integration.support.management.MessageSourceMetrics getSourceMetrics(String name) { - return this.managementConfigurer.getSourceMetrics(name); + @Deprecated + public IntegrationInboundManagement getSourceMetrics(String name) { + return this.sources.get(name); } - public int getSourceMessageCount(String name) { - return (int) getSourceMessageCountLong(name); + @Deprecated + public IntegrationManagement getChannelMetrics(String name) { + return this.channels.get(name); } - public long getSourceMessageCountLong(String name) { - org.springframework.integration.support.management.MessageSourceMetrics sourceMetrics = getSourceMetrics(name); - return sourceMetrics != null ? sourceMetrics.getMessageCountLong() : -1; + public IntegrationInboundManagement getSource(String name) { + return this.sources.get(name); } - public org.springframework.integration.support.management.MessageChannelMetrics getChannelMetrics(String name) { - return this.managementConfigurer.getChannelMetrics(name); - } - - public int getChannelSendCount(String name) { - return (int) getChannelSendCountLong(name); - } - - public long getChannelSendCountLong(String name) { - org.springframework.integration.support.management.MessageChannelMetrics channelMetrics = - getChannelMetrics(name); - return channelMetrics != null ? channelMetrics.getSendCountLong() : -1; - } - - public int getChannelSendErrorCount(String name) { - return (int) getChannelSendErrorCountLong(name); - } - - public long getChannelSendErrorCountLong(String name) { - org.springframework.integration.support.management.MessageChannelMetrics channelMetrics = getChannelMetrics(name); - return channelMetrics != null ? channelMetrics.getSendErrorCountLong() : -1; - } - - public int getChannelReceiveCount(String name) { - return (int) getChannelReceiveCountLong(name); - } - - public long getChannelReceiveCountLong(String name) { - org.springframework.integration.support.management.MessageChannelMetrics channelMetrics = - getChannelMetrics(name); - if (channelMetrics instanceof org.springframework.integration.support.management.PollableChannelManagement) { - return ((org.springframework.integration.support.management.PollableChannelManagement) channelMetrics) - .getReceiveCountLong(); - } - return -1; - } - - @ManagedOperation - public org.springframework.integration.support.management.Statistics getChannelSendRate(String name) { - org.springframework.integration.support.management.MessageChannelMetrics channelMetrics = - getChannelMetrics(name); - return channelMetrics != null ? channelMetrics.getSendRate() : null; - } - - public org.springframework.integration.support.management.Statistics getChannelErrorRate(String name) { - org.springframework.integration.support.management.MessageChannelMetrics channelMetrics = - getChannelMetrics(name); - return channelMetrics != null ? channelMetrics.getErrorRate() : null; + public IntegrationManagement getChannel(String name) { + return this.channels.get(name); } private void registerChannels() { - this.channels.forEach(this::registerChannel); + this.channels.values().forEach(this::registerChannel); } - private void registerChannel(org.springframework.integration.support.management.MessageChannelMetrics monitor) { - String name = ((NamedComponent) monitor).getComponentName(); - this.allChannelsByName.put(name, monitor); + private void registerChannel(IntegrationManagement monitor) { + String name = monitor.getComponentName(); if (matches(this.componentNamePatterns, name)) { String beanKey = getChannelBeanKey(name); if (logger.isInfoEnabled()) { @@ -772,31 +696,30 @@ public class IntegrationMBeanExporter extends MBeanExporter } private void registerHandlers() { - this.handlers.forEach(this::registerHandler); + this.handlers.values().forEach(this::registerHandler); } - private void registerHandler(org.springframework.integration.support.management.MessageHandlerMetrics handler) { - org.springframework.integration.support.management.MessageHandlerMetrics monitor = enhanceHandlerMonitor(handler); - String name = monitor.getManagedName(); - if (!this.objectNames.containsKey(handler) && matches(this.componentNamePatterns, name)) { + private void registerHandler(IntegrationManagement monitor2) { + IntegrationManagement monitor = enhanceHandlerMonitor(monitor2); + String name = monitor.getComponentName(); + if (!this.objectNames.containsKey(monitor2) && matches(this.componentNamePatterns, name)) { String beanKey = getHandlerBeanKey(monitor); if (logger.isInfoEnabled()) { logger.info("Registering MessageHandler " + name); } ObjectName objectName = registerBeanNameOrInstance(monitor, beanKey); - this.objectNames.put(handler, objectName); + this.objectNames.put(monitor2, objectName); } } private void registerSources() { - this.sources.forEach(this::registerSource); + this.sources.values().forEach(this::registerSource); } - private void registerSource(org.springframework.integration.support.management.MessageSourceMetrics source) { - org.springframework.integration.support.management.MessageSourceMetrics monitor = enhanceSourceMonitor(source); + private void registerSource(IntegrationInboundManagement source) { + IntegrationInboundManagement monitor = enhanceSourceMonitor(source); String name = monitor.getManagedName(); - this.allSourcesByName.put(name, monitor); if (!this.objectNames.containsKey(source) && matches(this.componentNamePatterns, name)) { String beanKey = getSourceBeanKey(monitor); if (logger.isInfoEnabled()) { @@ -804,6 +727,14 @@ public class IntegrationMBeanExporter extends MBeanExporter } ObjectName objectName = registerBeanNameOrInstance(monitor, beanKey); this.objectNames.put(source, objectName); + Lifecycle lifecycle = this.sourceLifecycles.get(source); + if (lifecycle != null) { + beanKey = getEndpointBeanKey(source.getManagedName() + ".adapter", source.getManagedType()); + if (logger.isInfoEnabled()) { + logger.info("Registering Endpoint " + beanKey); + } + this.objectNames.put(lifecycle, registerBeanNameOrInstance(lifecycle, beanKey)); + } } } @@ -839,7 +770,7 @@ public class IntegrationMBeanExporter extends MBeanExporter } this.endpointNames.add(name); beanKey = getEndpointBeanKey(name, source); - ObjectName objectName = registerBeanInstance(new ManagedEndpoint(endpoint), beanKey); + ObjectName objectName = registerBeanInstance(endpoint, beanKey); this.objectNames.put(endpoint, objectName); if (logger.isInfoEnabled()) { logger.info("Registered endpoint without MessageSource: " + objectName); @@ -882,16 +813,16 @@ public class IntegrationMBeanExporter extends MBeanExporter quoteIfNecessary(channel), extra); } - private String getHandlerBeanKey(org.springframework.integration.support.management.MessageHandlerMetrics handler) { + private String getHandlerBeanKey(IntegrationManagement monitor) { // This ordering of keys seems to work with default settings of JConsole return String.format(this.domain + ":type=MessageHandler,name=%s,bean=%s" + getStaticNames(), - quoteIfNecessary(handler.getManagedName()), quoteIfNecessary(handler.getManagedType())); + quoteIfNecessary(monitor.getManagedName()), quoteIfNecessary(monitor.getManagedType())); } - private String getSourceBeanKey(org.springframework.integration.support.management.MessageSourceMetrics source) { + private String getSourceBeanKey(IntegrationInboundManagement monitor) { // This ordering of keys seems to work with default settings of JConsole return String.format(this.domain + ":type=MessageSource,name=%s,bean=%s" + getStaticNames(), - quoteIfNecessary(source.getManagedName()), quoteIfNecessary(source.getManagedType())); + quoteIfNecessary(monitor.getManagedName()), quoteIfNecessary(monitor.getManagedType())); } private String getEndpointBeanKey(String name, String source) { @@ -925,11 +856,10 @@ public class IntegrationMBeanExporter extends MBeanExporter } @SuppressWarnings("unlikely-arg-type") - private org.springframework.integration.support.management.MessageHandlerMetrics enhanceHandlerMonitor( - org.springframework.integration.support.management.MessageHandlerMetrics monitor) { + private IntegrationManagement enhanceHandlerMonitor(IntegrationManagement monitor2) { - if (monitor.getManagedName() != null && monitor.getManagedType() != null) { - return monitor; + if (monitor2.getManagedName() != null && monitor2.getManagedType() != null) { + return monitor2; } // Assignment algorithm and bean id, with bean id pulled reflectively out of enclosing endpoint if possible @@ -944,32 +874,32 @@ public class IntegrationMBeanExporter extends MBeanExporter endpoint = this.applicationContext.getBean(beanName, IntegrationConsumer.class); try { MessageHandler handler = endpoint.getHandler(); - if (handler.equals(monitor) || - extractTarget(handlerInAnonymousWrapper(handler)).equals(monitor)) { + if (handler.equals(monitor2) || + extractTarget(handlerInAnonymousWrapper(handler)).equals(monitor2)) { name = beanName; endpointName = beanName; break; } } catch (Exception e) { - logger.trace("Could not get handler from bean = " + beanName); + logger.trace("Could not get handler from bean = " + beanName, e); endpoint = null; } } - org.springframework.integration.support.management.MessageHandlerMetrics messageHandlerMetrics = - buildMessageHandlerMetrics(monitor, name, source, endpoint); + IntegrationManagement messageHandlerMetrics = + buildMessageHandlerMetrics(monitor2, name, source, endpoint); if (endpointName != null) { this.endpointsByMonitor.put(messageHandlerMetrics, endpointName); } return messageHandlerMetrics; } - private org.springframework.integration.support.management.MessageHandlerMetrics buildMessageHandlerMetrics( - org.springframework.integration.support.management.MessageHandlerMetrics monitor, + private IntegrationManagement buildMessageHandlerMetrics( + IntegrationManagement monitor2, String name, String source, IntegrationConsumer endpoint) { - org.springframework.integration.support.management.MessageHandlerMetrics result = monitor; + IntegrationManagement result = monitor2; String managedType = source; String managedName = name; @@ -985,16 +915,10 @@ public class IntegrationMBeanExporter extends MBeanExporter } } - if (endpoint instanceof Lifecycle) { - result = wrapMessageHandlerInLifecycleMetrics(monitor, (Lifecycle) endpoint); - } - if (managedName == null) { - if (monitor instanceof NamedComponent) { - managedName = ((NamedComponent) monitor).getComponentName(); - } + managedName = ((NamedComponent) monitor2).getComponentName(); if (managedName == null) { - managedName = monitor.toString(); + managedName = monitor2.toString(); } managedType = "handler"; } @@ -1020,52 +944,20 @@ public class IntegrationMBeanExporter extends MBeanExporter return channelName + (total > 1 ? "#" + total : ""); } - /** - * Wrap the monitor in a lifecycle so it exposes the start/stop operations - */ - private org.springframework.integration.support.management.MessageHandlerMetrics - wrapMessageHandlerInLifecycleMetrics( - org.springframework.integration.support.management.MessageHandlerMetrics monitor, - Lifecycle endpoint) { - - org.springframework.integration.support.management.MessageHandlerMetrics result; - if (monitor instanceof MappingMessageRouterManagement) { - if (monitor instanceof TrackableComponent) { - result = new org.springframework.integration.support.management.TrackableRouterMetrics(endpoint, - (MappingMessageRouterManagement) monitor); - } - else { - result = new org.springframework.integration.support.management.RouterMetrics(endpoint, - (MappingMessageRouterManagement) monitor); - } - } - else { - if (monitor instanceof TrackableComponent) { - result = new org.springframework.integration.support.management. - LifecycleTrackableMessageHandlerMetrics(endpoint, monitor); - } - else { - result = new org.springframework.integration.support.management. - LifecycleMessageHandlerMetrics(endpoint, monitor); - } - } - return result; - } - private String getInternalComponentName(String name) { return name.substring(('_' + IntegrationConfigUtils.BASE_PACKAGE).length() + 1); } - private org.springframework.integration.support.management.MessageSourceMetrics enhanceSourceMonitor( - org.springframework.integration.support.management.MessageSourceMetrics monitor) { + private IntegrationInboundManagement enhanceSourceMonitor(IntegrationInboundManagement source2) { - if (monitor.getManagedName() != null) { - return monitor; + if (source2.getManagedName() != null) { + return source2; } String endpointName = null; String source = "endpoint"; - AbstractEndpoint endpoint = getEndpointForMonitor(monitor); + AbstractEndpoint endpoint = getEndpointForMonitor(source2); + this.sourceLifecycles.put(source2, endpoint); if (endpoint != null) { endpointName = endpoint.getBeanName(); @@ -1075,8 +967,8 @@ public class IntegrationMBeanExporter extends MBeanExporter source = "internal"; } - org.springframework.integration.support.management.MessageSourceMetrics messageSourceMetrics = - buildMessageSourceMetricsIfAny(monitor, endpointName, source, endpoint); + IntegrationInboundManagement messageSourceMetrics = + buildMessageSourceMetricsIfAny(source2, endpointName, source, endpoint); if (endpointName != null) { this.endpointsByMonitor.put(messageSourceMetrics, endpointName); } @@ -1084,29 +976,28 @@ public class IntegrationMBeanExporter extends MBeanExporter } @SuppressWarnings("unlikely-arg-type") - private AbstractEndpoint getEndpointForMonitor( - org.springframework.integration.support.management.MessageSourceMetrics monitor) { + private AbstractEndpoint getEndpointForMonitor(IntegrationInboundManagement source2) { for (AbstractEndpoint endpoint : this.applicationContext.getBeansOfType(AbstractEndpoint.class).values()) { Object target = null; - if (monitor instanceof MessagingGatewaySupport && endpoint.equals(monitor)) { - target = monitor; + if (source2 instanceof MessagingGatewaySupport && endpoint.equals(source2)) { + target = source2; } else if (endpoint instanceof SourcePollingChannelAdapter) { target = ((SourcePollingChannelAdapter) endpoint).getMessageSource(); } - if (monitor.equals(target)) { + if (source2.equals(target)) { return endpoint; } } return null; } - private org.springframework.integration.support.management.MessageSourceMetrics buildMessageSourceMetricsIfAny( - org.springframework.integration.support.management.MessageSourceMetrics monitor, String name, + private IntegrationInboundManagement buildMessageSourceMetricsIfAny( + IntegrationInboundManagement source2, String name, String source, Object endpoint) { - org.springframework.integration.support.management.MessageSourceMetrics result = monitor; + IntegrationInboundManagement result = source2; String managedType = source; String managedName = name; @@ -1136,10 +1027,6 @@ public class IntegrationMBeanExporter extends MBeanExporter } } - if (endpoint instanceof Lifecycle) { - result = wrapMessageSourceInLifecycleMetrics(result, endpoint); - } - if (managedName == null) { managedName = result.toString(); managedType = "source"; @@ -1150,36 +1037,4 @@ public class IntegrationMBeanExporter extends MBeanExporter return result; } - /** - * Wrap the monitor in a lifecycle so it exposes the start/stop operations - */ - private org.springframework.integration.support.management.MessageSourceMetrics wrapMessageSourceInLifecycleMetrics( - org.springframework.integration.support.management.MessageSourceMetrics monitor, Object endpoint) { - - org.springframework.integration.support.management.MessageSourceMetrics result; - if (endpoint instanceof TrackableComponent) { - if (monitor instanceof MessageSourceManagement) { - result = new org.springframework.integration.support.management. - LifecycleTrackableMessageSourceManagement((Lifecycle) endpoint, - (MessageSourceManagement) monitor); - } - else { - result = new org.springframework.integration.support.management. - LifecycleTrackableMessageSourceMetrics((Lifecycle) endpoint, monitor); - } - } - else { - if (monitor instanceof MessageSourceManagement) { - result = new org.springframework.integration.support.management. - LifecycleMessageSourceManagement((Lifecycle) endpoint, - (MessageSourceManagement) monitor); - } - else { - result = new org.springframework.integration.support.management.LifecycleMessageSourceMetrics( - (Lifecycle) endpoint, monitor); - } - } - return result; - } - } diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMetadataMBeanInfoAssembler.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMetadataMBeanInfoAssembler.java deleted file mode 100644 index 41580730e0..0000000000 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMetadataMBeanInfoAssembler.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.monitor; - -import javax.management.Descriptor; - -import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler; -import org.springframework.jmx.export.metadata.JmxAttributeSource; - -/** - * The {@link MetadataMBeanInfoAssembler} extension to assemble metadata MBean info from - * the - * {@link org.springframework.integration.support.management.LifecycleMessageSourceMetrics} - * or - * {@link org.springframework.integration.support.management.LifecycleMessageHandlerMetrics} - * managed bean's delegate. - *

- * All other managed beans are left as is. - * - * @author Gary Russell - * @author Artem Bilan - * - * @since 4.3 - */ -public class IntegrationMetadataMBeanInfoAssembler extends MetadataMBeanInfoAssembler { - - public IntegrationMetadataMBeanInfoAssembler(JmxAttributeSource attributeSource) { - super(attributeSource); - } - - @Override - protected String getDescription(Object managedBean, String beanKey) { - return super.getDescription(extractManagedBean(managedBean), beanKey); - } - - @Override - protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) { - super.populateMBeanDescriptor(desc, extractManagedBean(managedBean), beanKey); - } - - @SuppressWarnings("deprecation") - private Object extractManagedBean(Object managedBean) { - if (managedBean instanceof org.springframework.integration.support.management.LifecycleMessageSourceMetrics) { - return ((org.springframework.integration.support.management.LifecycleMessageSourceMetrics) managedBean) - .getDelegate(); - } - else if (managedBean instanceof org.springframework.integration.support.management.LifecycleMessageHandlerMetrics) { - return ((org.springframework.integration.support.management.LifecycleMessageHandlerMetrics) managedBean) - .getDelegate(); - } - return managedBean; - } - -} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMetadataNamingStrategy.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMetadataNamingStrategy.java deleted file mode 100644 index 8820d08a56..0000000000 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/IntegrationMetadataNamingStrategy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.monitor; - -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; - -import org.springframework.jmx.export.metadata.JmxAttributeSource; -import org.springframework.jmx.export.naming.MetadataNamingStrategy; - -/** - * The {@link MetadataNamingStrategy} naming extension to extract an {@link ObjectName} - * from the - * {@link org.springframework.integration.support.management.LifecycleMessageSourceMetrics} - * or - * {@link org.springframework.integration.support.management.LifecycleMessageHandlerMetrics} - * managed bean's delegate. - *

- * Otherwise delegate to the {@link MetadataNamingStrategy#getObjectName} as is. - * - * @author Gary Russell - * @author Artem Bilan - * - * @since 4.3 - */ -public class IntegrationMetadataNamingStrategy extends MetadataNamingStrategy { - - public IntegrationMetadataNamingStrategy(JmxAttributeSource attributeSource) { - super(attributeSource); - } - - @Override - public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { - return super.getObjectName(extractManagedBean(managedBean), beanKey); - } - - @SuppressWarnings("deprecation") - private Object extractManagedBean(Object managedBean) { - if (managedBean instanceof org.springframework.integration.support.management.LifecycleMessageSourceMetrics) { - return ((org.springframework.integration.support.management.LifecycleMessageSourceMetrics) managedBean) - .getDelegate(); - } - else if (managedBean instanceof org.springframework.integration.support.management.LifecycleMessageHandlerMetrics) { - return ((org.springframework.integration.support.management.LifecycleMessageHandlerMetrics) managedBean) - .getDelegate(); - } - return managedBean; - } - -} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ManagedEndpoint.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ManagedEndpoint.java index 849d05a885..2fa008068b 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ManagedEndpoint.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ManagedEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.integration.monitor; import org.springframework.context.Lifecycle; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.support.management.IntegrationManagedResource; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.jmx.export.annotation.ManagedOperation; @@ -28,7 +29,11 @@ import org.springframework.jmx.export.annotation.ManagedOperation; * @author Dave Syer * @author Gary Russell * + * @deprecated this is no longer used by the framework. Replaced by + * {@link ManageableLifecycle}. + * */ +@Deprecated @IntegrationManagedResource public class ManagedEndpoint implements Lifecycle { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests-context.xml index db1a71345f..d3ddf26909 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests-context.xml @@ -29,8 +29,8 @@ - SendCount - SendErrorCount + QueueSize + RemainingCapacity @@ -47,7 +47,7 @@ - + bean = (Map) payload - .get(domain + ":name=in,type=MessageChannel"); + .get(this.domain + ":name=out,type=MessageChannel"); assertThat(bean.size()).isEqualTo(2); - assertThat(bean.containsKey("SendCount")).isTrue(); - assertThat(bean.containsKey("SendErrorCount")).isTrue(); + assertThat(bean.containsKey("QueueSize")).isTrue(); + assertThat(bean.containsKey("RemainingCapacity")).isTrue(); adapter.stop(); } @@ -106,10 +106,7 @@ public class MBeanAttributeFilterTests { List keys = new ArrayList<>(bean.keySet()); Collections.sort(keys); - assertThat(keys) - .containsExactly("LoggingEnabled", "MaxSendDuration", "MeanErrorRate", "MeanErrorRatio", - "MeanSendDuration", "MeanSendRate", "MinSendDuration", "StandardDeviationSendDuration", - "SubscriberCount", "TimeSinceLastSend"); + assertThat(keys).containsExactly("LoggingEnabled", "SubscriberCount"); adapterNot.stop(); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml index bd90ff73d8..caa3e50579 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests-context.xml @@ -16,7 +16,7 @@ - + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java index 913e0c5d94..07382023f5 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,9 +46,8 @@ public class ControlBusParserTests { public void testControlMessageToChannelMetrics() { MessageChannel control = this.context.getBean("controlChannel", MessageChannel.class); MessagingTemplate messagingTemplate = new MessagingTemplate(); - Object value = messagingTemplate.convertSendAndReceive(control, - "@integrationMbeanExporter.getChannelSendRate('testChannel').count", Object.class); - assertThat(value).isEqualTo(0); + Object value = messagingTemplate.convertSendAndReceive(control, "@cb.isRunning()", Object.class); + assertThat(value).isEqualTo(Boolean.TRUE); } } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterParserTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterParserTests-context.xml index 5a40262d81..4bb9cd1bdc 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterParserTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterParserTests-context.xml @@ -20,12 +20,7 @@ object-naming-strategy="keyNamer" managed-components="\!excluded, f*, b*, q*, t*" /> - + foo diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/configuration/EnableMBeanExportTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/configuration/EnableMBeanExportTests.java index f492e03685..b6d955188f 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/configuration/EnableMBeanExportTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/configuration/EnableMBeanExportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,10 +69,6 @@ public class EnableMBeanExportTests { @Autowired private IntegrationManagementConfigurer configurer; - @SuppressWarnings("deprecation") - @Autowired - private org.springframework.integration.support.management.MetricsFactory myMetricsFactory; - @SuppressWarnings("unchecked") @Test public void testEnableMBeanExport() throws MalformedObjectNameException, ClassNotFoundException { @@ -80,14 +76,7 @@ public class EnableMBeanExportTests { assertThat(this.exporter.getServer()).isSameAs(this.mBeanServer); String[] componentNamePatterns = TestUtils.getPropertyValue(this.exporter, "componentNamePatterns", String[].class); assertThat(componentNamePatterns).containsExactly("input", "inputX", "in*"); - String[] enabledCounts = TestUtils.getPropertyValue(this.configurer, "enabledCountsPatterns", String[].class); - assertThat(enabledCounts).containsExactly("foo", "bar", "baz"); - String[] enabledStats = TestUtils.getPropertyValue(this.configurer, "enabledStatsPatterns", String[].class); - assertThat(enabledStats).containsExactly("qux", "!*"); assertThat(TestUtils.getPropertyValue(this.configurer, "defaultLoggingEnabled", Boolean.class)).isFalse(); - assertThat(TestUtils.getPropertyValue(this.configurer, "defaultCountsEnabled", Boolean.class)).isTrue(); - assertThat(TestUtils.getPropertyValue(this.configurer, "defaultStatsEnabled", Boolean.class)).isTrue(); - assertThat(TestUtils.getPropertyValue(this.configurer, "metricsFactory")).isSameAs(this.myMetricsFactory); Set names = this.mBeanServer.queryNames(ObjectName.getInstance("FOO:type=MessageChannel,*"), null); // Only one registered (out of >2 available) @@ -118,12 +107,7 @@ public class EnableMBeanExportTests { defaultDomain = "${managed.domain}", managedComponents = {"input", "${managed.component}"}) @EnableIntegrationManagement( - defaultLoggingEnabled = "false", - defaultCountsEnabled = "true", - defaultStatsEnabled = "true", - countsEnabled = { "foo", "${count.patterns}" }, - statsEnabled = { "qux", "!*" }, - metricsFactory = "myMetricsFactory") + defaultLoggingEnabled = "false") public static class ContextConfiguration { @Bean @@ -141,12 +125,6 @@ public class EnableMBeanExportTests { return new QueueChannel(); } - @SuppressWarnings("deprecation") - @Bean - public org.springframework.integration.support.management.MetricsFactory myMetricsFactory() { - return new org.springframework.integration.support.management.DefaultMetricsFactory(); - } - } public static class EnvironmentApplicationContextInitializer diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java deleted file mode 100644 index 58ba1fe256..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChannelIntegrationTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2009-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.monitor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.integration.support.context.NamedComponent; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageDeliveryException; -import org.springframework.messaging.PollableChannel; -import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author Dave Syer - * @author Gary Russell - * @author Artem Bilan - * - * @since 2.0 - */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -@DirtiesContext -public class ChannelIntegrationTests { - - @Autowired - private MessageChannel requests; - - @Autowired - private PollableChannel intermediate; - - @Autowired - private PollableChannel sourceChannel; - - @Autowired - private IntegrationMBeanExporter messageChannelsMonitor; - - @Test - public void testMessageChannelStatistics() { - this.requests.send(new GenericMessage<>("foo")); - - String intermediateChannelName = ((NamedComponent) this.intermediate).getBeanName(); - - assertThat(messageChannelsMonitor.getChannelSendCount(intermediateChannelName)).isEqualTo(1); - - double rate = - messageChannelsMonitor.getChannelSendRate(((NamedComponent) this.requests).getBeanName()).getMean(); - assertThat(rate).as("No statistics for requests channel").isGreaterThanOrEqualTo(0); - - rate = messageChannelsMonitor.getChannelSendRate(intermediateChannelName).getMean(); - assertThat(rate).as("No statistics for intermediate channel").isGreaterThanOrEqualTo(0); - - assertThat(intermediate.receive(100L)).isNotNull(); - assertThat(messageChannelsMonitor.getChannelReceiveCount(intermediateChannelName)).isEqualTo(1); - - requests.send(new GenericMessage<>("foo")); - try { - requests.send(new GenericMessage<>("foo")); - } - catch (@SuppressWarnings("unused") MessageDeliveryException e) { - } - - assertThat(messageChannelsMonitor.getChannelSendCount(intermediateChannelName)).isEqualTo(3); - - assertThat(messageChannelsMonitor.getChannelSendErrorCount(intermediateChannelName)).isEqualTo(1); - - assertThat(messageChannelsMonitor.getChannelMetrics(intermediateChannelName)).isSameAs(intermediate); - - @SuppressWarnings("deprecation") - org.springframework.integration.support.management.BaseHandlerMetrics handlerMetrics = messageChannelsMonitor - .getHandlerMetrics("bridge"); - - assertThat(handlerMetrics.handleCount()).isEqualTo(3); - assertThat(handlerMetrics.errorCount()).isEqualTo(1); - - assertThat(this.sourceChannel.receive(10000)).isNotNull(); - - assertThat(messageChannelsMonitor.getSourceMessageCount("source")).isGreaterThan(0); - assertThat(messageChannelsMonitor.getSourceMetrics("source").getMessageCount()).isGreaterThan(0); - } - -} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java index 1b697aca92..c8e152e894 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2019 the original author or authors. + * Copyright 2009-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,10 +88,6 @@ public class HandlerMonitoringIntegrationTests { int before = service.getCounter(); channel.send(new GenericMessage<>("bar")); assertThat(service.getCounter()).isEqualTo(before + 1); - - int count = messageHandlersMonitor.getHandlerDuration(monitor).getCount(); - assertThat(count > 0).as("No statistics for input channel").isTrue(); - } finally { context.close(); @@ -118,11 +114,13 @@ public class HandlerMonitoringIntegrationTests { private int counter; + @Override public void execute(String input) throws Exception { Thread.sleep(10L); // make the duration non-zero this.counter++; } + @Override public int getCounter() { return counter; } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java index 56524b41f6..ae2ccb073a 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2019 the original author or authors. + * Copyright 2009-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,8 +122,8 @@ public class MBeanExporterIntegrationTests { Set names = server.queryNames( ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null); - assertThat(names.size()).isEqualTo(2); - names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=explicit,*"), null); + assertThat(names.size()).isEqualTo(3); + names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=explicit.adapter,*"), null); assertThat(names.size()).isEqualTo(1); MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations(); String startName = null; diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java deleted file mode 100644 index eeec1db0f8..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageChannelsMonitorIntegrationTests.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright 2009-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.monitor; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.junit.Test; - -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.channel.AbstractMessageChannel; -import org.springframework.integration.channel.interceptor.WireTap; -import org.springframework.integration.support.context.NamedComponent; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageHandlingException; -import org.springframework.messaging.support.ChannelInterceptor; -import org.springframework.messaging.support.GenericMessage; -import org.springframework.messaging.support.InterceptableChannel; - -/** - * @author Dave Syer - * @author Gary Russell - * @author Artem Bilan - * - */ -public class MessageChannelsMonitorIntegrationTests { - - private static Log logger = LogFactory.getLog(MessageChannelsMonitorIntegrationTests.class); - - private AbstractMessageChannel channel; - - private Service service; - - private IntegrationMBeanExporter messageChannelsMonitor; - - public void setMessageHandlersMonitor(IntegrationMBeanExporter messageChannelsMonitor) { - this.messageChannelsMonitor = messageChannelsMonitor; - } - - public void setService(Service service) { - this.service = service; - } - - @Test - public void testSendWithAnonymousHandler() throws Exception { - doTest("anonymous-channel.xml", "anonymous"); - } - - @Test - public void testSendWithProxiedChannel() throws Exception { - doTest("proxy-channel.xml", "anonymous"); - } - - @Test - public void testRates() throws Exception { - try (ClassPathXmlApplicationContext context = createContext("anonymous-channel.xml")) { - this.channel = context.getBean("anonymous", AbstractMessageChannel.class); - int before = service.getCounter(); - CountDownLatch latch = new CountDownLatch(50); - service.setLatch(latch); - for (int i = 0; i < 50; i++) { - channel.send(new GenericMessage<>("bar")); - Thread.sleep(20L); - } - assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); - assertThat(service.getCounter()).isEqualTo(before + 50); - - // The handler monitor is registered under the endpoint id (since it is explicit) - int sends = messageChannelsMonitor.getChannelSendRate(this.channel.getBeanName()).getCount(); - assertThat(sends).as("No send statistics for input channel").isEqualTo(50); - long sendsLong = messageChannelsMonitor.getChannelSendRate(this.channel.getBeanName()).getCountLong(); - assertThat(sends).as("No send statistics for input channel").isEqualTo(sendsLong); - - } - } - - @Test - public void testErrors() throws Exception { - try (ClassPathXmlApplicationContext context = createContext("anonymous-channel.xml")) { - this.channel = context.getBean("anonymous", AbstractMessageChannel.class); - int before = service.getCounter(); - CountDownLatch latch = new CountDownLatch(10); - service.setLatch(latch); - for (int i = 0; i < 5; i++) { - channel.send(new GenericMessage<>("bar")); - Thread.sleep(20L); - } - try { - channel.send(new GenericMessage<>("fail")); - } - catch (MessageHandlingException e) { - // ignore - } - for (int i = 0; i < 5; i++) { - channel.send(new GenericMessage<>("bar")); - Thread.sleep(20L); - } - assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); - assertThat(service.getCounter()).isEqualTo(before + 10); - - // The handler monitor is registered under the endpoint id (since it is explicit) - int sends = messageChannelsMonitor.getChannelSendRate(this.channel.getBeanName()).getCount(); - assertThat(sends).as("No send statistics for input channel").isEqualTo(11); - int errors = messageChannelsMonitor.getChannelErrorRate(this.channel.getBeanName()).getCount(); - assertThat(errors).as("No error statistics for input channel").isEqualTo(1); - } - } - - @Test - public void testQueues() throws Exception { - try (ClassPathXmlApplicationContext context = createContext("queue-channel.xml")) { - this.channel = context.getBean("queue", AbstractMessageChannel.class); - int before = service.getCounter(); - CountDownLatch latch = new CountDownLatch(10); - service.setLatch(latch); - for (int i = 0; i < 5; i++) { - channel.send(new GenericMessage<>("bar")); - Thread.sleep(20L); - } - try { - channel.send(new GenericMessage<>("fail")); - } - catch (MessageHandlingException e) { - // ignore - } - for (int i = 0; i < 5; i++) { - channel.send(new GenericMessage<>("bar")); - Thread.sleep(20L); - } - assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); - assertThat(service.getCounter()).isEqualTo(before + 10); - - // The handler monitor is registered under the endpoint id (since it is explicit) - int sends = messageChannelsMonitor.getChannelSendRate(this.channel.getBeanName()).getCount(); - assertThat(sends).as("No send statistics for input channel").isEqualTo(11); - int receives = messageChannelsMonitor.getChannelReceiveCount(this.channel.getBeanName()); - assertThat(receives).as("No send statistics for input channel").isEqualTo(11); - int errors = messageChannelsMonitor.getChannelErrorRate(this.channel.getBeanName()).getCount(); - assertThat(errors).as("Expect no errors for input channel (handler fails)").isEqualTo(0); - } - } - - private void doTest(String config, String channelName) throws Exception { - try (ClassPathXmlApplicationContext context = createContext(config)) { - MessageChannel channel = context.getBean(channelName, MessageChannel.class); - int before = service.getCounter(); - CountDownLatch latch = new CountDownLatch(1); - service.setLatch(latch); - channel.send(new GenericMessage<>("bar")); - assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); - assertThat(service.getCounter()).isEqualTo(before + 1); - - // The handler monitor is registered under the endpoint id (since it is explicit) - int sends = messageChannelsMonitor.getChannelSendRate(((NamedComponent) channel).getBeanName()).getCount(); - assertThat(sends).as("No statistics for input channel").isEqualTo(1); - - assertThat(channel).isInstanceOf(InterceptableChannel.class); - List channelInterceptors = ((InterceptableChannel) channel).getInterceptors(); - assertThat(channelInterceptors.size()).isEqualTo(1); - assertThat(channelInterceptors.get(0)).isInstanceOf(WireTap.class); - } - } - - private ClassPathXmlApplicationContext createContext(String config) { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config, getClass()); - context.getAutowireCapableBeanFactory() - .autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); - return context; - } - - public static class Service { - - private int counter; - - private volatile CountDownLatch latch; - - public void setLatch(CountDownLatch latch) { - this.latch = latch; - } - - public void execute(String input) { - if ("fail".equals(input)) { - throw new RuntimeException("Planned"); - } - counter++; - latch.countDown(); - } - - public int getCounter() { - return counter; - } - - } - - @Aspect - public static class TestChannelInterceptor { - - @Before("execution(* *..MessageChannel+.send(*)) && args(input)") - public void around(Message input) { - logger.debug("Handling: " + input); - } - - } - -} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceMonitoringIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceMonitoringIntegrationTests.java deleted file mode 100644 index 71b418b715..0000000000 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessageSourceMonitoringIntegrationTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2009-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.monitor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.messaging.PollableChannel; - -/** - * @author Dave Syer - * @author Gary Russell - * @author Artem Bilan - */ -public class MessageSourceMonitoringIntegrationTests { - - private PollableChannel channel; - - private Service service; - - private IntegrationMBeanExporter exporter; - - public void setMessageHandlersMonitor(IntegrationMBeanExporter exporter) { - this.exporter = exporter; - } - - public void setService(Service service) { - this.service = service; - } - - @Test - public void testSendAndHandleWithEndpointName() throws Exception { - // The message source monitor is registered under the endpoint id (since it is explicit) - doTest("explicit-source.xml", "input", "explicit"); - } - - @Test - public void testSendAndHandleWithAnonymous() throws Exception { - // The message source monitor is registered under the channel name - doTest("anonymous-source.xml", "anonymous", "anonymous"); - } - - private void doTest(String config, String channelName, String monitor) throws Exception { - - ClassPathXmlApplicationContext context = createContext(config, channelName); - - try { - - int before = service.getCounter(); - channel.receive(1000L); - channel.receive(1000L); - assertThat(before < service.getCounter()).isTrue(); - - int count = exporter.getSourceMessageCount(monitor); - assertThat(count > 0).as("No statistics for input channel").isTrue(); - - } - finally { - context.close(); - } - - } - - private ClassPathXmlApplicationContext createContext(String config, String channelName) { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config, getClass()); - context.getAutowireCapableBeanFactory() - .autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); - channel = context.getBean(channelName, PollableChannel.class); - return context; - } - - public interface Service { - - String execute() throws Exception; - - int getCounter(); - } - - public static class SimpleService implements Service { - - private int counter; - - public String execute() throws Exception { - Thread.sleep(10L); // make the duration non-zero - counter++; - return "count=" + counter; - } - - public int getCounter() { - return counter; - } - - } - -} diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java index e55efe91d3..0ccd453cca 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,12 +47,12 @@ public class Int2307Tests { int count = 0; for (ObjectInstance mbean : mbeans) { if (mbean.toString() - .startsWith("org.springframework.integration.support.management.LifecycleTrackableMessageHandlerMetrics[test.domain:type=MessageHandler,name=rlr,bean=endpoint,random=")) { + .startsWith("org.springframework.integration.router.RecipientListRouter[test.domain:type=MessageHandler,name=rlr,bean=endpoint,random=")) { bits |= 2; count++; } else if (mbean.toString() - .startsWith("org.springframework.integration.support.management.TrackableRouterMetrics[test.domain:type=MessageHandler,name=hvr,bean=endpoint,random=")) { + .startsWith("org.springframework.integration.router.HeaderValueRouter[test.domain:type=MessageHandler,name=hvr,bean=endpoint,random=")) { bits |= 8; count++; } diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java index 0604960193..aaaa557874 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/core/DefaultJpaOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -221,13 +221,11 @@ public class DefaultJpaOperations extends AbstractJpaOperations { } @Override - @Nullable public void persist(Object entity) { persist(entity, 0, false); } @Override - @Nullable public void persist(Object entity, int flushSize, boolean clearOnFlush) { Assert.notNull(entity, "The object to persist must not be null."); persistOrMerge(entity, false, flushSize, clearOnFlush); diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java index 342391f702..2eedecf966 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java @@ -19,7 +19,6 @@ package org.springframework.integration.kafka.channel; import java.util.ArrayDeque; import java.util.Deque; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import org.springframework.integration.channel.ExecutorChannelInterceptorAware; import org.springframework.integration.kafka.inbound.KafkaMessageSource; @@ -42,10 +41,8 @@ import org.springframework.util.Assert; * @since 5.4 * */ -@SuppressWarnings("deprecation") public class PollableKafkaChannel extends AbstractKafkaChannel - implements PollableChannel, org.springframework.integration.support.management.PollableChannelManagement, - ExecutorChannelInterceptorAware { + implements PollableChannel, ExecutorChannelInterceptorAware { private final KafkaMessageSource source; @@ -74,26 +71,6 @@ public class PollableKafkaChannel extends AbstractKafkaChannel return topics[0]; } - @Override - public int getReceiveCount() { - return getMetrics().getReceiveCount(); - } - - @Override - public long getReceiveCountLong() { - return getMetrics().getReceiveCountLong(); - } - - @Override - public int getReceiveErrorCount() { - return getMetrics().getReceiveErrorCount(); - } - - @Override - public long getReceiveErrorCountLong() { - return getMetrics().getReceiveErrorCountLong(); - } - @Override @Nullable public Message receive() { @@ -110,8 +87,7 @@ public class PollableKafkaChannel extends AbstractKafkaChannel protected Message doReceive() { ChannelInterceptorList interceptorList = getIChannelInterceptorList(); Deque interceptorStack = null; - AtomicBoolean counted = new AtomicBoolean(); - boolean countsEnabled = isCountsEnabled(); + boolean counted = false; boolean traceEnabled = isLoggingEnabled() && logger.isTraceEnabled(); try { if (traceEnabled) { @@ -126,13 +102,14 @@ public class PollableKafkaChannel extends AbstractKafkaChannel Message message = this.source.receive(); if (message != null) { incrementReceiveCounter(); + counted = true; message = interceptorList.postReceive(message, this); } interceptorList.afterReceiveCompletion(message, this, null, interceptorStack); return message; } catch (RuntimeException ex) { - if (countsEnabled && !counted.get()) { + if (!counted) { incrementReceiveErrorCounter(ex); } interceptorList.afterReceiveCompletion(null, this, ex, interceptorStack); @@ -155,7 +132,6 @@ public class PollableKafkaChannel extends AbstractKafkaChannel if (metricsCaptor != null) { buildReceiveCounter(metricsCaptor, ex).increment(); } - getMetrics().afterError(); } private CounterFacade buildReceiveCounter(MetricsCaptor metricsCaptor, @Nullable Exception ex) { diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/SubscribableKafkaChannel.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/SubscribableKafkaChannel.java index 92935aab3b..0f5ae2865f 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/SubscribableKafkaChannel.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/SubscribableKafkaChannel.java @@ -23,6 +23,7 @@ import org.springframework.context.SmartLifecycle; import org.springframework.integration.dispatcher.MessageDispatcher; import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy; import org.springframework.integration.dispatcher.UnicastingDispatcher; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.kafka.config.KafkaListenerContainerFactory; import org.springframework.kafka.core.KafkaOperations; import org.springframework.kafka.listener.MessageListenerContainer; @@ -41,7 +42,8 @@ import org.springframework.util.Assert; * @since 5.4 * */ -public class SubscribableKafkaChannel extends AbstractKafkaChannel implements SubscribableChannel, SmartLifecycle { +public class SubscribableKafkaChannel extends AbstractKafkaChannel implements SubscribableChannel, + ManageableSmartLifecycle { private static final int DEFAULT_PHASE = Integer.MAX_VALUE / 2; // same as MessageProducerSupport diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/outbound/KafkaProducerMessageHandler.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/outbound/KafkaProducerMessageHandler.java index f74d4f16d0..9320356542 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/outbound/KafkaProducerMessageHandler.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/outbound/KafkaProducerMessageHandler.java @@ -37,7 +37,6 @@ import org.apache.kafka.common.header.Headers; import org.apache.kafka.common.header.internals.RecordHeader; import org.apache.kafka.common.header.internals.RecordHeaders; -import org.springframework.context.Lifecycle; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.integration.MessageTimeoutException; @@ -49,6 +48,7 @@ import org.springframework.integration.kafka.support.KafkaIntegrationHeaders; import org.springframework.integration.kafka.support.KafkaSendFailureException; import org.springframework.integration.support.DefaultErrorMessageStrategy; import org.springframework.integration.support.ErrorMessageStrategy; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.requestreply.ReplyingKafkaTemplate; import org.springframework.kafka.requestreply.RequestReplyFuture; @@ -100,7 +100,7 @@ import org.springframework.util.concurrent.SettableListenableFuture; * @since 5.4 */ public class KafkaProducerMessageHandler extends AbstractReplyProducingMessageHandler - implements Lifecycle { + implements ManageableLifecycle { /** * Buffer added to ensure our timeout is longer than Kafka's. diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java index 4bdc6ee70e..01c287e9f4 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/outbound/AbstractMqttMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.integration.mqtt.outbound; import java.util.concurrent.atomic.AtomicBoolean; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.Lifecycle; import org.springframework.expression.Expression; import org.springframework.integration.handler.AbstractMessageHandler; import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor; @@ -27,6 +26,7 @@ import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter; import org.springframework.integration.mqtt.support.MqttHeaders; import org.springframework.integration.mqtt.support.MqttMessageConverter; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConverter; @@ -41,7 +41,7 @@ import org.springframework.util.Assert; * @since 4.0 * */ -public abstract class AbstractMqttMessageHandler extends AbstractMessageHandler implements Lifecycle { +public abstract class AbstractMqttMessageHandler extends AbstractMessageHandler implements ManageableLifecycle { private static final MessageProcessor DEFAULT_TOPIC_PROCESSOR = (message) -> message.getHeaders().get(MqttHeaders.TOPIC, String.class); diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/channel/SubscribableRedisChannel.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/channel/SubscribableRedisChannel.java index ba08ef7a0f..fdbdafd47f 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/channel/SubscribableRedisChannel.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/channel/SubscribableRedisChannel.java @@ -20,7 +20,6 @@ import java.util.concurrent.Executor; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.context.SmartLifecycle; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; @@ -37,6 +36,7 @@ import org.springframework.integration.channel.ChannelUtils; import org.springframework.integration.context.IntegrationProperties; import org.springframework.integration.dispatcher.BroadcastingDispatcher; import org.springframework.integration.support.converter.SimpleMessageConverter; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.integration.util.ErrorHandlingTaskExecutor; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; @@ -58,7 +58,7 @@ import org.springframework.util.StringUtils; */ @SuppressWarnings("rawtypes") public class SubscribableRedisChannel extends AbstractMessageChannel - implements BroadcastCapableChannel, SmartLifecycle { + implements BroadcastCapableChannel, ManageableSmartLifecycle { private final RedisMessageListenerContainer container = new RedisMessageListenerContainer(); diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java index 4a88de8cd3..62a3b65849 100644 --- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java +++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.context.SmartLifecycle; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.rsocket.RSocketStrategies; import org.springframework.util.Assert; @@ -43,7 +43,7 @@ import org.springframework.util.MimeType; */ public abstract class AbstractRSocketConnector implements ApplicationContextAware, InitializingBean, DisposableBean, SmartInitializingSingleton, - SmartLifecycle { + ManageableSmartLifecycle { protected final IntegrationRSocketMessageHandler rSocketMessageHandler; // NOSONAR - final diff --git a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/AbstractStompSessionManager.java b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/AbstractStompSessionManager.java index a732614024..7382bcb616 100644 --- a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/AbstractStompSessionManager.java +++ b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/AbstractStompSessionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,9 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; -import org.springframework.context.SmartLifecycle; import org.springframework.integration.stomp.event.StompConnectionFailedEvent; import org.springframework.integration.stomp.event.StompSessionConnectedEvent; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.simp.stomp.StompClientSupport; import org.springframework.messaging.simp.stomp.StompCommand; @@ -69,7 +69,7 @@ import org.springframework.util.concurrent.ListenableFutureCallback; * @since 4.2 */ public abstract class AbstractStompSessionManager implements StompSessionManager, ApplicationEventPublisherAware, - SmartLifecycle, DisposableBean, BeanNameAware { + ManageableSmartLifecycle, DisposableBean, BeanNameAware { private static final long DEFAULT_RECOVERY_INTERVAL = 10000; diff --git a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/outbound/StompMessageHandler.java b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/outbound/StompMessageHandler.java index f2c4538f89..1535da4288 100644 --- a/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/outbound/StompMessageHandler.java +++ b/spring-integration-stomp/src/main/java/org/springframework/integration/stomp/outbound/StompMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; -import org.springframework.context.Lifecycle; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.integration.expression.ExpressionUtils; @@ -32,6 +31,7 @@ import org.springframework.integration.stomp.StompSessionManager; import org.springframework.integration.stomp.event.StompExceptionEvent; import org.springframework.integration.stomp.event.StompReceiptEvent; import org.springframework.integration.stomp.support.StompHeaderMapper; +import org.springframework.integration.support.management.ManageableLifecycle; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; @@ -54,7 +54,8 @@ import org.springframework.util.Assert; * * @since 4.2 */ -public class StompMessageHandler extends AbstractMessageHandler implements ApplicationEventPublisherAware, Lifecycle { +public class StompMessageHandler extends AbstractMessageHandler + implements ApplicationEventPublisherAware, ManageableLifecycle { private static final int DEFAULT_CONNECT_TIMEOUT = 3000; diff --git a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ClientWebSocketContainer.java b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ClientWebSocketContainer.java index 08f151959b..3cdde31deb 100644 --- a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ClientWebSocketContainer.java +++ b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ClientWebSocketContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.springframework.context.Lifecycle; -import org.springframework.context.SmartLifecycle; import org.springframework.http.HttpHeaders; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.util.concurrent.ListenableFuture; @@ -49,7 +49,7 @@ import org.springframework.web.socket.client.WebSocketClient; * * @since 4.1 */ -public final class ClientWebSocketContainer extends IntegrationWebSocketContainer implements SmartLifecycle { +public final class ClientWebSocketContainer extends IntegrationWebSocketContainer implements ManageableSmartLifecycle { private static final int DEFAULT_CONNECTION_TIMEOUT = 10; diff --git a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ServerWebSocketContainer.java b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ServerWebSocketContainer.java index ca2c67c1b5..a922f73b7f 100644 --- a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ServerWebSocketContainer.java +++ b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/ServerWebSocketContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.integration.websocket; import java.util.Arrays; import org.springframework.context.Lifecycle; -import org.springframework.context.SmartLifecycle; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.integration.util.JavaUtils; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; @@ -51,7 +51,7 @@ import org.springframework.web.socket.sockjs.transport.TransportHandler; * @since 4.1 */ public class ServerWebSocketContainer extends IntegrationWebSocketContainer - implements WebSocketConfigurer, SmartLifecycle { + implements WebSocketConfigurer, ManageableSmartLifecycle { private final String[] paths; diff --git a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java index b2f9bb0058..c0c916decd 100644 --- a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java +++ b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.jxmpp.util.XmppStringUtils; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.context.SmartLifecycle; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.util.StringUtils; /** @@ -45,7 +45,7 @@ import org.springframework.util.StringUtils; * * @see XMPPTCPConnection */ -public class XmppConnectionFactoryBean extends AbstractFactoryBean implements SmartLifecycle { +public class XmppConnectionFactoryBean extends AbstractFactoryBean implements ManageableSmartLifecycle { private final Object lifecycleMonitor = new Object(); diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java index 46299637f2..6a56cd3694 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,9 @@ import org.apache.curator.utils.CloseableUtils; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.data.Stat; -import org.springframework.context.SmartLifecycle; import org.springframework.integration.metadata.ListenableMetadataStore; import org.springframework.integration.metadata.MetadataStoreListener; +import org.springframework.integration.support.management.ManageableSmartLifecycle; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.util.Assert; @@ -47,7 +47,7 @@ import org.springframework.util.Assert; * * @since 4.2 */ -public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle { +public class ZookeeperMetadataStore implements ListenableMetadataStore, ManageableSmartLifecycle { private static final String KEY_MUST_NOT_BE_NULL = "'key' must not be null."; diff --git a/src/reference/asciidoc/graph.adoc b/src/reference/asciidoc/graph.adoc index 506c684e98..dbeb66a7a7 100644 --- a/src/reference/asciidoc/graph.adoc +++ b/src/reference/asciidoc/graph.adoc @@ -91,20 +91,8 @@ A Spring Integration application with only the default components would expose a ---- ==== -NOTE: Version 5.2 has deprecated the legacy metrics in favor of Micrometer meters as discussed <<./metrics.adoc#metrics-management,Metrics Management>>. -While not shown above, the legacy metrics (under the `stats` child node) will continue to appear in the graph, but with an extra child node `"deprecated" : "stats are deprecated in favor of sendTimers and receiveCounters"`. - -With some JSON serializers, you can suppress the inclusion of legacy statistics using several techniques; for example, with Jackson, you can register a `SimpleModule` configured with a `NullSerializer` with the `ObjectMapper`: - -==== -[source, java] ----- -objectMapper.registerModule(new SimpleModule() - .addSerializer(IntegrationNode.Stats.class, NullSerializer.instance)); ----- -==== - -The resulting json contains `"stats" : null`. +NOTE: Version 5.2 deprecated the legacy metrics in favor of Micrometer meters as discussed <<./metrics.adoc#metrics-management,Metrics Management>>. +The legacy metrics were removed in Version 5.4 and will no longer appear in the graph. In the preceding example, the graph consists of three top-level elements. diff --git a/src/reference/asciidoc/jmx.adoc b/src/reference/asciidoc/jmx.adoc index b41ad7b6a9..ffcdde9cd4 100644 --- a/src/reference/asciidoc/jmx.adoc +++ b/src/reference/asciidoc/jmx.adoc @@ -251,7 +251,7 @@ The following example shows how to declare an instance of an `IntegrationMBeanEx The MBean exporter is orthogonal to the one provided in Spring core. It registers message channels and message handlers but does not register itself. You can expose the exporter itself (and certain other components in Spring Integration) by using the standard `` tag. -The exporter has some metrics attached to it -- for instance, a count of the number of active handlers and the number of queued messages. +The exporter has some metrics attached to it -- for instance, a count of the number of handlers and the number of queued messages. It also has a useful operation, as discussed in <>. ===== @@ -365,69 +365,14 @@ These resulted in a significant performance improvement of the JMX statistics co However, it has some implications for user code in a few specific (uncommon) situations. These changes are detailed below, with a caution where necessary. -Metrics Capture:: -Previously, `MessageSource`, `MessageChannel`, and `MessageHandler` metrics were captured by wrapping the object in a JDK dynamic proxy to intercept appropriate method calls and capture the statistics. -The proxy was added when an integration MBean exporter was declared in the context. -+ -Now, the statistics are captured by the beans themselves. -See <<./metrics.adoc#metrics-management,Metrics and Management>> for more information. -+ -WARNING: This change means that you no longer automatically get an MBean or statistics for custom `MessageHandler` implementations, unless those custom handlers extend `AbstractMessageHandler`. -The simplest way to resolve this is to extend `AbstractMessageHandler`. -If you cannot do so, another work around is to implement the `MessageHandlerMetrics` interface. -For convenience, a `DefaultMessageHandlerMetrics` is provided to capture and report statistics. -You should invoke the `beforeHandle` and `afterHandle` at the appropriate times. -Your `MessageHandlerMetrics` methods can then delegate to this object to obtain each statistic. -Similarly, `MessageSource` implementations must extend `AbstractMessageSource` or implement `MessageSourceMetrics`. -Message sources capture only a count, so there is no provided convenience class. -You should maintain the count in an `AtomicLong` field. -+ -The removal of the proxy has two additional benefits: -+ -* Stack traces in exceptions are reduced (when JMX is enabled) because the proxy is not on the stack -* Cases where two MBeans were exported for the same bean now only export a single MBean with consolidated attributes and operations (see the MBean consolidation bullet, later). - -Resolution:: -`System.nanoTime()` (rather than `System.currentTimeMillis()`) is now used to capture times . -This may provide more accuracy on some JVMs, espcially when you expect durations of less than one millisecond. - -Setting Initial Statistics Collection State:: -Previously, when JMX was enabled, all sources, channels, and handlers captured statistics. -You can now control whether the statistics are enabled on an individual component. -Further, you can capture simple counts on `MessageChannel` instances and `MessageHandler` instances instead of capturing the complete time-based statistics. -This can have significant performance implications, because you can selectively configure where you need detailed statistics and enable and disable collection at runtime. -+ -See <<./metrics.adoc#metrics-management,Metrics and Management>>. - @IntegrationManagedResource:: Similar to the `@ManagedResource` annotation, the `@IntegrationManagedResource` marks a class as being eligible to be exported as an MBean. However, it is exported only if the application context has an `IntegrationMBeanExporter`. + -Certain Spring Integration classes (in the `org.springframework.integration`) package) that were previously annotated with`@ManagedResource` are now annotated with both `@ManagedResource` and `@IntegrationManagedResource`. +Certain Spring Integration classes (in the `org.springframework.integration`) package) that were previously annotated with `@ManagedResource` are now annotated with both `@ManagedResource` and `@IntegrationManagedResource`. This is for backwards compatibility (see the next item). Such MBeans are exported by any context `MBeanServer` or by an `IntegrationMBeanExporter` (but not both -- if both exporters are present, the bean is exported by the integration exporter if the bean matches a `managed-components` pattern). -Consolidated MBeans:: -Certain classes within the framework (mapping routers, for example) have additional attributes and operations over and above those provided by metrics and `Lifecycle`. -We use a `Router` as an example here. -+ -Previously, beans of these types were exported as two distinct MBeans: -+ -* The metrics MBean (with an object name such as `intDomain:type=MessageHandler,name=myRouter,bean=endpoint`). -This MBean had metrics attributes and metrics/Lifecycle operations. -* A second MBean (with an object name such as `ctxDomain:name=org.springframework.integration.config.` `RouterFactoryBean#0`,type=MethodInvokingRouter`) was exported with the channel mappings attribute and operations. -+ -Now the attributes and operations are consolidated into a single MBean. -The object name depends on the exporter. -If exported by the integration MBean exporter, the object name is, for example: `intDomain:type=MessageHandler,name=myRouter,bean=endpoint`. -If exported by another exporter, the object name is, for example: `ctxDomain:name=org.springframework.integration.config.` `RouterFactoryBean#0,type=MethodInvokingRouter`. -There is no difference between these MBeans (aside from the object name), except that the statistics are not enabled (the attributes are `0`) by exporters other than the integration exporter. -You can enable statistics at runtime by using the JMX operations. -When exported by the integration MBean exporter, the initial state can be managed as described earlier. -+ -WARNING: If you currently use the second MBean to change, for example, channel mappings and you use the integration MBean exporter, note that the object name has changed because of the MBean consolidation. -There is no change if you are not using the integration MBean exporter. - MBean Exporter Bean Name Patterns:: Previously, the `managed-components` patterns were inclusive only. If a bean name matched one of the patterns, it would be included. diff --git a/src/reference/asciidoc/metrics.adoc b/src/reference/asciidoc/metrics.adoc index 1cdfdaf7e7..8802d24b96 100644 --- a/src/reference/asciidoc/metrics.adoc +++ b/src/reference/asciidoc/metrics.adoc @@ -5,21 +5,14 @@ This section describes how to capture metrics for Spring Integration. In recent versions, we have relied more on Micrometer (see https://micrometer.io), and we plan to use Micrometer even more in future releases. [[configuring-metrics-capture]] -==== Configuring Metrics Capture +==== Legacy Metrics -NOTE: Prior to version 4.2, metrics were only available when JMX was enabled. -See <<./jmx.adoc#jmx,JMX Support>>. +Legacy metrics were removed in Version 5.4; see Micrometer Integration below. -To enable `MessageSource`, `MessageChannel`, and `MessageHandler` metrics, add an `` bean to the application context (in XML) or annotate one of your `@Configuration` classes with `@EnableIntegrationManagement` (in Java). -`MessageSource` instances maintain only counts, `MessageChannel` instances and `MessageHandler` instances maintain duration statistics in addition to counts. -See <> and <>, later in this chapter. +==== Disabling Logging in High Volume Environments -Doing so causes the automatic registration of the `IntegrationManagementConfigurer` bean in the application context. -Only one such bean can exist in the context, and, if registered manually via a `` definition, it must have the bean name set to `integrationManagementConfigurer`. -This bean applies its configuration to beans after all beans in the context have been instantiated. - -In addition to metrics, you can control debug logging in the main message flow. -In very high volume applications, even calls to `isDebugEnabled()` can be quite expensive with some logging subsystems. +You can control debug logging in the main message flow. +In very high volume applications, calls to `isDebugEnabled()` can be quite expensive with some logging subsystems. You can disable all such logging to avoid this overhead. Exception logging (debug or otherwise) is not affected by this setting. @@ -28,13 +21,8 @@ The following listing shows the available options for controlling logging: ==== [source, xml] ---- - - default-counts-enabled="false" <2> - default-stats-enabled="false" <3> - counts-enabled-patterns="foo, !baz, ba*" <4> - stats-enabled-patterns="fiz, buz" <5> - metrics-factory="myMetricsFactory" /> <6> + <1> + ---- [source, java] @@ -42,12 +30,8 @@ The following listing shows the available options for controlling logging: @Configuration @EnableIntegration @EnableIntegrationManagement( - defaultLoggingEnabled = "true", <1> - defaultCountsEnabled = "false", <2> - defaultStatsEnabled = "false", <3> - countsEnabled = { "foo", "${count.patterns}" }, <4> - statsEnabled = { "qux", "!*" }, <5> - MetricsFactory = "myMetricsFactory") <6> + defaultLoggingEnabled = "true" <1>) + public static class ContextConfiguration { ... } @@ -59,64 +43,20 @@ Set to 'true' to enable debug logging (if also enabled by the logging subsystem) Only applied if you have not explicitly configured the setting in a bean definition. The default is `true`. -<2> Enable or disable count metrics for components that do not match one of the patterns in <4>. -Only applied if you have not explicitly configured the setting in a bean definition. -The default is `false`. - -<3> Enable or disable statistical metrics for components that do not match one of the patterns in <5>. -Only applied if you have not explicitly configured the setting in a bean definition. -The default is 'false'. - -<4> A comma-delimited list of patterns for beans for which counts should be enabled. -You can negate the pattern with `!`. -First match (positive or negative) wins. -In the unlikely event that you have a bean name starting with `!`, escape the `!` in the pattern. -For example, `\!something` positively matches a bean named `!something`. - -<5> A comma-delimited list of patterns for beans for which statistical metrics should be enabled. -You can negate the pattern\ with `!`. -First match (positive or negative) wins. -In the unlikely event that you have a bean name starting with `!`, escape the `!` in the pattern. -`\!something` positively matches a bean named `!something`. -The collection of statistics implies the collection of counts. - -<6> A reference to a `MetricsFactory`. -See <>. - -At runtime, counts and statistics can be obtained by calling `getChannelMetrics`, `getHandlerMetrics` and `getSourceMetrics` (all from the `IntegrationManagementConfigurer` class), which return `MessageChannelMetrics`, `MessageHandlerMetrics`, and `MessageSourceMetrics`, respectively. - -See the https://docs.spring.io/spring-integration/api/index.html[Javadoc] for complete information about these classes. - -When JMX is enabled (see <<./jmx.adoc#jmx,JMX Support>>), `IntegrationMBeanExporter` also exposes these metrics. - -IMPORTANT: -`defaultLoggingEnabled`, `defaultCountsEnabled`, and `defaultStatsEnabled` are applied only if you have not explicitly configured the corresponding setting in a bean definition. - -Starting with version 5.0.2, the framework automatically detects whether the application context has a single `MetricsFactory` bean and, if so, uses it instead of the default metrics factory. - -IMPORTANT: These legacy metrics have been deprecated in favor of Micrometer metrics discussed below. -Legacy metrics support will be removed in a future release. +IMPORTANT: `defaultLoggingEnabled` is applied only if you have not explicitly configured the corresponding setting in a bean definition. [[micrometer-integration]] ==== Micrometer Integration -Starting with version 5.0.3, the presence of a https://micrometer.io/[Micrometer] `MeterRegistry` in the application context triggers support for Micrometer metrics in addition to the built-in metrics (note that the legacy built-in metrics will be removed in a future release). - -IMPORTANT: Micrometer was first supported in version 5.0.2, but changes were made to the Micrometer `Meters` in version 5.0.3 to make them more suitable for use in dimensional systems. -Further changes were made in 5.0.4. -If you use Micrometer, a minimum of version 5.0.4 is recommended, since some of the changes in 5.0.4 were breaking API changes. +Starting with version 5.0.3, the presence of a https://micrometer.io/[Micrometer] `MeterRegistry` in the application context triggers support for Micrometer metrics. To use Micrometer, add one of the `MeterRegistry` beans to the application context. -If the `IntegrationManagementConfigurer` detects exactly one `MeterRegistry` bean, it configures a `MicrometerMetricsCaptor` bean with a name of `integrationMicrometerMetricsCaptor`. For each `MessageHandler` and `MessageChannel`, timers are registered. For each `MessageSource`, a counter is registered. This only applies to objects that extend `AbstractMessageHandler`, `AbstractMessageChannel`, and `AbstractMessageSource` (which is the case for most framework components). -With Micrometer metrics, the `statsEnabled` flag has no effect, since statistics capture is delegated to Micrometer. -The `countsEnabled` flag controls whether the Micrometer `Meter` instances are updated when processing each message. - The `Timer` Meters for send operations on message channels have the following names or tags: * `name`: `spring.integration.send` @@ -178,191 +118,3 @@ and * `tag`: `type:channel` * `tag`: `name:` * `description`: `The remaining capacity of the queue channel` - -[[mgmt-channel-features]] -==== `MessageChannel` Metric Features - -These legacy metrics will be removed in a future release. -See <>. - -Message channels report metrics according to their concrete type. -If you are looking at a `DirectChannel`, you see statistics for the send operation. -If it is a `QueueChannel`, you also see statistics for the receive operation as well as the count of messages that are currently buffered by this `QueueChannel`. -In both cases, some metrics are simple counters (message count and error count), and some are estimates of averages of interesting quantities. -The algorithms used to calculate these estimates are described briefly in the following table. - -.MessageChannel Metrics -[cols="1,2,3", options="header"] -|=== -| Metric Type -| Example -| Algorithm - -| Count -| Send Count -| Simple incrementer. -Increases by one when an event occurs. - -| Error Count -| Send Error Count -| Simple incrementer. -Increases by one when an send results in an error. - -| Duration -| Send Duration (method execution time in milliseconds) -| Exponential moving average with decay factor (ten by default). -Average of the method execution time over roughly the last ten (by default) measurements. - -| Rate -| Send Rate (number of operations per second) -| Inverse of Exponential moving average of the interval between events with decay in time (lapsing over 60 seconds by default) and per measurement (last ten events by default). - -| Error Rate -| Send Error Rate (number of errors per second) -| Inverse of exponential moving average of the interval between error events with decay in time (lapsing over 60 seconds by default) and per measurement (last ten events by default). - -| Ratio -| Send Success Ratio (ratio of successful to total sends) -| Estimate the success ratio as the exponential moving average of the series composed of values (1 for success and 0 for failure, decaying as per the rate measurement over time and events by default). -The error ratio is: 1 - success ratio. - -|=== - -[[mgmt-handler-features]] -==== MessageHandler Metric Features - -These legacy metrics will be removed in a future release. -See <>. - -The following table shows the statistics maintained for message handlers. -Some metrics are simple counters (message count and error count), and one is an estimate of averages of send duration. -The algorithms used to calculate these estimates are described briefly in the following table: - -.MessageHandlerMetrics -[cols="1,2,3", options="header"] -|=== -| Metric Type -| Example -| Algorithm - -| Count -| Handle Count -| Simple incrementer. -Increases by one when an event occurs. - -| Error Count -| Handler Error Count -| Simple incrementer. -Increases by one when an invocation results in an error. - -| Active Count -| Handler Active Count -| Indicates the number of currently active threads currently invoking the handler (or any downstream synchronous flow). - -| Duration -| Handle Duration (method execution time in milliseconds) -| Exponential moving average with decay factor (ten by default). -Average of the method execution time over roughly the last ten (default) measurements. - -|=== - -[[mgmt-statistics]] -==== Time-Based Average Estimates - -A feature of the time-based average estimates is that they decay with time if no new measurements arrive. -To help interpret the behavior over time, the time (in seconds) since the last measurement is also exposed as a metric. - -There are two basic exponential models: decay per measurement (appropriate for duration and anything where the number of measurements is part of the metric) and decay per time unit (more suitable for rate measurements where the time in between measurements is part of the metric). -Both models depend on the fact that `S(n) = sum(i=0,i=n) w(i) x(i)` has a special form when `w(i) = r^i`, with `r=constant`: `S(n) = x(n) + r S(n-1)` (so you only have to store `S(n-1)` (not the whole series `x(i)`) to generate a new metric estimate from the last measurement). -The algorithms used in the duration metrics use `r=exp(-1/M)` with `M=10`. -The net effect is that the estimate, `S(n)`, is more heavily weighted to recent measurements and is composed roughly of the last `M` measurements. -So `M` is the "`window`" or lapse rate of the estimate. -For the vanilla moving average, `i` is a counter over the number of measurements. -For the rate, we interpret `i` as the elapsed time or a combination of elapsed time and a counter (so the metric estimate contains contributions roughly from the last `M` measurements and the last `T` seconds). - -[[mgmt-metrics-factory]] -==== Metrics Factory - -A strategy interface `MetricsFactory` has been introduced to let you provide custom channel metrics for your `MessageChannel` instances and `MessageHandler` instances. -By default, a `DefaultMetricsFactory` provides a default implementation of `MessageChannelMetrics` and `MessageHandlerMetrics`, <>. -To override the default `MetricsFactory`, configure it as <>, by providing a reference to your `MetricsFactory` bean instance. -You can either customize the default implementations, as described in the next section, or provide completely different -implementations by extending `AbstractMessageChannelMetrics` or `AbstractMessageHandlerMetrics`. - -See also <>. - -In addition to the default metrics factory <>, the framework provides the `AggregatingMetricsFactory`. -This factory creates `AggregatingMessageChannelMetrics` and `AggregatingMessageHandlerMetrics` instances. -In very high volume scenarios, the cost of capturing statistics can be prohibitive (the time to make two calls to the system and -store the data for each message). -The aggregating metrics aggregate the response time over a sample of messages. -This can save significant CPU time. - -CAUTION: The statistics are likely to be skewed if messages arrive in bursts. -These metrics are intended for use with high, constant-volume, message rates. - -The following example shows how to define an aggregrating metrics factory: - -==== -[source, xml] ----- - - - ----- -==== - -The preceding configuration aggregates the duration over 1000 messages. -Counts (send and error) are maintained per-message, but the statistics are per 1000 messages. - -===== Customizing the Default Channel and Handler Statistics - -See <> and the https://docs.spring.io/spring-integration/api/index.html[Javadoc] for the `ExponentialMovingAverage*` classes for more information about these values. - -By default, the `DefaultMessageChannelMetrics` and `DefaultMessageHandlerMetrics` use a "`window`" of ten measurements, -a rate period of one second (meaning rate per second) and a decay lapse period of one minute. - -If you wish to override these defaults, you can provide a custom `MetricsFactory` that returns appropriately configured -metrics and provide a reference to it in the MBean exporter, as <>. - -The following example shows how to do so: - -==== -[source,java] ----- -public static class CustomMetrics implements MetricsFactory { - - @Override - public AbstractMessageChannelMetrics createChannelMetrics(String name) { - return new DefaultMessageChannelMetrics(name, - new ExponentialMovingAverage(20, 1000000.), - new ExponentialMovingAverageRate(2000, 120000, 30, true), - new ExponentialMovingAverageRatio(130000, 40, true), - new ExponentialMovingAverageRate(3000, 140000, 50, true)); - } - - @Override - public AbstractMessageHandlerMetrics createHandlerMetrics(String name) { - return new DefaultMessageHandlerMetrics(name, new ExponentialMovingAverage(20, 1000000.)); - } - -} ----- -==== - -===== Advanced Customization - -The customizations described earlier are wholesale and apply to all appropriate beans exported by the MBean exporter. -This is the extent of customization available when you use XML configuration. - -Individual beans can be provided with different implementations using by Java `@Configuration` or programmatically at -runtime (after the application context has been refreshed) by invoking the `configureMetrics` methods on -`AbstractMessageChannel` and `AbstractMessageHandler`. - -===== Performance Improvement - -Previously, the time-based metrics (see <>) were calculated in real time. -The statistics are now calculated when retrieved instead. -This resulted in a significant performance improvement, at the expense of a small amount of additional memory for each statistic. -As <>, you can disable the statistics altogether while retaining the MBean that allows the invocation of `Lifecycle` methods. diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 5edbf18713..b653d84c0f 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -47,6 +47,8 @@ See <<./gateway.adoc#gateway-default-reply-channel,Setting the Default Reply Cha The aggregator (and resequencer) can now expire orphaned groups (groups in a persistent store where no new messages arrive after an application restart). See <<./aggregator.adoc#aggregator-expiring-groups, Aggregator Expiring Groups>> for more information. +The legacy metrics that were replaced by Micrometer meters have been removed. + [[x5.4-tcp]] === TCP Changes