Do not check if the Lifecycle argument is null
Fixes #607 Signed-off-by: Marius Bogoevici <mbogoevici@pivotal.io> Address PR comments - Expand Javadoc - Rename Lifecycle field Signed-off-by: Marius Bogoevici <mbogoevici@pivotal.io>
This commit is contained in:
committed by
Ilayaperumal Gopinathan
parent
b3a0f2c2e1
commit
8e5689c298
@@ -99,19 +99,19 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
Binding<MessageChannel> foo2ProducerBinding = binder.bindProducer("foo.2", new DirectChannel(),
|
||||
createProducerProperties());
|
||||
foo0ProducerBinding.unbind();
|
||||
assertThat(TestUtils.getPropertyValue(foo0ProducerBinding, "endpoint", Lifecycle.class).isRunning())
|
||||
assertThat(TestUtils.getPropertyValue(foo0ProducerBinding, "lifecycle", Lifecycle.class).isRunning())
|
||||
.isFalse();
|
||||
foo0ConsumerBinding.unbind();
|
||||
foo1ProducerBinding.unbind();
|
||||
assertThat(TestUtils.getPropertyValue(foo0ConsumerBinding, "endpoint", Lifecycle.class).isRunning())
|
||||
assertThat(TestUtils.getPropertyValue(foo0ConsumerBinding, "lifecycle", Lifecycle.class).isRunning())
|
||||
.isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(foo1ProducerBinding, "endpoint", Lifecycle.class).isRunning())
|
||||
assertThat(TestUtils.getPropertyValue(foo1ProducerBinding, "lifecycle", Lifecycle.class).isRunning())
|
||||
.isFalse();
|
||||
foo1ConsumerBinding.unbind();
|
||||
foo2ProducerBinding.unbind();
|
||||
assertThat(TestUtils.getPropertyValue(foo1ConsumerBinding, "endpoint", Lifecycle.class).isRunning())
|
||||
assertThat(TestUtils.getPropertyValue(foo1ConsumerBinding, "lifecycle", Lifecycle.class).isRunning())
|
||||
.isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(foo2ProducerBinding, "endpoint", Lifecycle.class).isRunning())
|
||||
assertThat(TestUtils.getPropertyValue(foo2ProducerBinding, "lifecycle", Lifecycle.class).isRunning())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -339,6 +339,6 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
|
||||
protected Lifecycle extractEndpoint(Binding<MessageChannel> binding) {
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(binding);
|
||||
return (Lifecycle) accessor.getPropertyValue("endpoint");
|
||||
return (Lifecycle) accessor.getPropertyValue("lifecycle");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.stream.binder;
|
||||
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.support.context.NamedComponent;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -38,18 +37,26 @@ public class DefaultBinding<T> implements Binding<T> {
|
||||
|
||||
protected final T target;
|
||||
|
||||
protected final Lifecycle endpoint;
|
||||
protected final Lifecycle lifecycle;
|
||||
|
||||
public DefaultBinding(String name, String group, T target, Lifecycle endpoint) {
|
||||
/**
|
||||
* Creates an instance that associates a given name, group and binding target with an
|
||||
* optional {@link Lifecycle} component, which will be stopped during unbinding.
|
||||
*
|
||||
* @param name the name of the binding target
|
||||
* @param group the group (only for input targets)
|
||||
* @param target the binding target
|
||||
* @param lifecycle {@link Lifecycle} that runs while the
|
||||
* binding is active and will be stopped during unbinding
|
||||
*/
|
||||
public DefaultBinding(String name, String group, T target, Lifecycle lifecycle) {
|
||||
Assert.notNull(target, "target must not be null");
|
||||
Assert.notNull(endpoint, "endpoint must not be null");
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.target = target;
|
||||
this.endpoint = endpoint;
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -58,23 +65,27 @@ public class DefaultBinding<T> implements Binding<T> {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void unbind() {
|
||||
if (this.endpoint != null) {
|
||||
this.endpoint.stop();
|
||||
if (this.lifecycle != null) {
|
||||
this.lifecycle.stop();
|
||||
}
|
||||
afterUnbind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener method that executes after unbinding. Subclasses can implement their own
|
||||
* behaviour on unbinding by overriding this method.
|
||||
*/
|
||||
protected void afterUnbind() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return " Binding [name=" + this.name + ", target=" + this.target + ", endpoint=" +
|
||||
((this.endpoint instanceof NamedComponent) ? ((NamedComponent) this.endpoint).getComponentName() :
|
||||
ObjectUtils.nullSafeToString(this.endpoint))
|
||||
return " Binding [name=" + this.name + ", target=" + this.target + ", lifecycle="
|
||||
+ ((this.lifecycle instanceof NamedComponent)
|
||||
? ((NamedComponent) this.lifecycle).getComponentName()
|
||||
: ObjectUtils.nullSafeToString(this.lifecycle))
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user