Skip to content

Commit d886733

Browse files
artembilangaryrussell
authored andcommitted
Fix meter leaks in the Pollable channels
1 parent dd6cd51 commit d886733

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -232,14 +232,17 @@ protected Message<?> doReceive(Long timeout) {
232232
catch (RuntimeException e) {
233233
if (countsEnabled && !counted) {
234234
if (getMetricsCaptor() != null) {
235-
getMetricsCaptor().counterBuilder(RECEIVE_COUNTER_NAME)
236-
.tag("name", getComponentName() == null ? "unknown" : getComponentName())
237-
.tag("type", "channel")
238-
.tag("result", "failure")
239-
.tag("exception", e.getClass().getSimpleName())
240-
.description("Messages received")
241-
.build()
242-
.increment();
235+
CounterFacade counterFacade =
236+
getMetricsCaptor()
237+
.counterBuilder(RECEIVE_COUNTER_NAME)
238+
.tag("name", getComponentName() == null ? "unknown" : getComponentName())
239+
.tag("type", "channel")
240+
.tag("result", "failure")
241+
.tag("exception", e.getClass().getSimpleName())
242+
.description("Messages received")
243+
.build();
244+
this.meters.add(counterFacade);
245+
counterFacade.increment();
243246
}
244247
getMetrics().afterError();
245248
}
@@ -298,6 +301,7 @@ private void incrementReceiveCounter() {
298301
.tag("exception", "none")
299302
.description("Messages received")
300303
.build();
304+
this.meters.add(this.receiveCounter);
301305
}
302306
this.receiveCounter.increment();
303307
}
@@ -352,12 +356,4 @@ public boolean hasExecutorInterceptors() {
352356
return this.executorInterceptorsSize > 0;
353357
}
354358

355-
@Override
356-
public void destroy() throws Exception {
357-
super.destroy();
358-
if (this.receiveCounter != null) {
359-
this.receiveCounter.remove();
360-
}
361-
}
362-
363359
}

spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -150,14 +150,17 @@ public Message<?> receive() {
150150
catch (RuntimeException e) {
151151
if (countsEnabled && !counted) {
152152
if (getMetricsCaptor() != null) {
153-
getMetricsCaptor().counterBuilder(RECEIVE_COUNTER_NAME)
154-
.tag("name", getComponentName() == null ? "unknown" : getComponentName())
155-
.tag("type", "channel")
156-
.tag("result", "failure")
157-
.tag("exception", e.getClass().getSimpleName())
158-
.description("Messages received")
159-
.build()
160-
.increment();
153+
CounterFacade counterFacade =
154+
getMetricsCaptor()
155+
.counterBuilder(RECEIVE_COUNTER_NAME)
156+
.tag("name", getComponentName() == null ? "unknown" : getComponentName())
157+
.tag("type", "channel")
158+
.tag("result", "failure")
159+
.tag("exception", e.getClass().getSimpleName())
160+
.description("Messages received")
161+
.build();
162+
this.meters.add(counterFacade);
163+
counterFacade.increment();
161164
}
162165
getMetrics().afterError();
163166
}
@@ -177,6 +180,7 @@ private void incrementReceiveCounter() {
177180
.tag("exception", "none")
178181
.description("Messages received")
179182
.build();
183+
this.meters.add(this.receiveCounter);
180184
}
181185
this.receiveCounter.increment();
182186
}

0 commit comments

Comments
 (0)