INT-4486: Properly implement stop(Runnable)

JIRA: https://jira.spring.io/browse/INT-4486

The `SmartLifecycle.stop(Runnable callback)` must always call the
`callback` in the end independently of the internal state

* Revise all the `SmartLifecycle` implementations for the proper
`callback` handling

**Cherry-pick to 5.0.x and 4.3.x**
This commit is contained in:
Artem Bilan
2018-06-11 14:29:06 -04:00
committed by Gary Russell
parent eb1efdb0ff
commit 85bc183849
11 changed files with 67 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -234,6 +234,9 @@ abstract class AbstractSubscribableAmqpChannel extends AbstractAmqpChannel
this.container.stop(callback);
this.declared = false;
}
else {
callback.run();
}
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -66,10 +66,11 @@ import org.springframework.util.StringUtils;
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.1
*/
public class AmqpChannelFactoryBean extends AbstractFactoryBean<AbstractAmqpChannel> implements SmartLifecycle,
DisposableBean, BeanNameAware {
public class AmqpChannelFactoryBean extends AbstractFactoryBean<AbstractAmqpChannel>
implements SmartLifecycle, DisposableBean, BeanNameAware {
private volatile AbstractAmqpChannel channel;
@@ -516,13 +517,14 @@ public class AmqpChannelFactoryBean extends AbstractFactoryBean<AbstractAmqpChan
if (this.channel instanceof SmartLifecycle) {
((SmartLifecycle) this.channel).stop(callback);
}
else {
callback.run();
}
}
@Override
protected void destroyInstance(AbstractAmqpChannel instance) throws Exception {
if (instance instanceof DisposableBean) {
((DisposableBean) this.channel).destroy();
}
this.channel.destroy();
}
}