Skip to content

Commit

Permalink
Fix SmartLifecycle.stop(Runnable) usage
Browse files Browse the repository at this point in the history
* Also remove redundant `stop(Runnable)` implementations which repeat
 a `default` one in the `SmartLifecycle`

**Cherry-pick to 2.1.x & 2.0.x**

# Conflicts:
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/BrokerEventListener.java
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/RabbitListenerEndpointRegistry.java
  • Loading branch information
artembilan committed Jun 21, 2019
1 parent 4167e93 commit ff8a5da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ public void stop(Runnable callback) {
if (this.container != null) {
this.container.stop(callback);
}
else {
callback.run();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,23 @@ public void stop() {

@Override
public void stop(Runnable callback) {
Collection<MessageListenerContainer> listenerContainers = getListenerContainers();
AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback);
for (MessageListenerContainer listenerContainer : listenerContainers) {
try {
listenerContainer.stop(aggregatingCallback);
}
catch (Exception e) {
if (this.logger.isWarnEnabled()) {
this.logger.warn("Failed to stop listener container [" + listenerContainer + "]", e);
Collection<MessageListenerContainer> containers = getListenerContainers();
if (containers.size() > 0) {
AggregatingCallback aggregatingCallback = new AggregatingCallback(containers.size(), callback);
for (MessageListenerContainer listenerContainer : containers) {
try {
listenerContainer.stop(aggregatingCallback);
}
catch (Exception e) {
if (this.logger.isWarnEnabled()) {
this.logger.warn("Failed to stop listener container [" + listenerContainer + "]", e);
}
}
}
}
else {
callback.run();
}
}

@Override
Expand Down

0 comments on commit ff8a5da

Please sign in to comment.