Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2675: DefaultBinding isRunning enhancements #2838

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected <S> MessageSourceCustomizer<S> getMessageSourceCustomizer() {
}

private String resolveBinderName(String bindingName, BindingServiceProperties bindingServiceProperties) {
String binder = bindingServiceProperties == null ? null : bindingServiceProperties.getBindings().get(bindingName).getBinder();
String binder = getBinderName(bindingName, bindingServiceProperties);
if (!StringUtils.hasText(binder)) {
return resolveFromDefaultBinder();
}
Expand All @@ -247,7 +247,7 @@ private String resolveFromDefaultBinder() {
}

private String resolveBinderType(String bindingName, BindingServiceProperties bindingServiceProperties) {
String binder = bindingServiceProperties == null ? null : bindingServiceProperties.getBindings().get(bindingName).getBinder();
String binder = getBinderName(bindingName, bindingServiceProperties);
if (!StringUtils.hasText(binder)) {
return resolveFromDefaultBinder();
}
Expand All @@ -259,6 +259,18 @@ private String resolveBinderType(String bindingName, BindingServiceProperties bi
}
}

private static String getBinderName(String bindingName, BindingServiceProperties bindingServiceProperties) {
String binder;
if (bindingServiceProperties == null) {
binder = null;
}
else {
BindingProperties bindingProperties = bindingServiceProperties.getBindings().get(bindingName);
binder = bindingProperties == null ? null : bindingProperties.getBinder();
}
return binder;
}

/**
* Binds an outbound channel to a given destination. The implementation delegates to
* {@link ProvisioningProvider#provisionProducerDestination(String, ProducerProperties)}
Expand Down Expand Up @@ -655,7 +667,9 @@ public void afterUnbind() {
}

};

if (properties.isAutoStartup()) {
binding.start();
}
doPublishEvent(new BindingCreatedEvent(binding));
return binding;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
* @author Myeonghyeon Lee
* @author Soby Chacko
* @author Byungjun You
* @see org.springframework.cloud.stream.annotation.EnableBinding
*/

@JsonPropertyOrder({ "bindingName", "name", "group", "pausable", "state" })
Expand All @@ -60,6 +59,8 @@ public class DefaultBinding<T> implements Binding<T> {

private boolean paused;

private boolean running;

private boolean restartable;

private Lifecycle companion;
Expand Down Expand Up @@ -118,7 +119,16 @@ public String getState() {

@Override
public boolean isRunning() {
return this.lifecycle != null && this.lifecycle.isRunning();
if (this.running) {
return true;
}
else {
if (this.lifecycle != null && this.lifecycle.isRunning()) {
this.running = true;
return true;
}
return false;
}
}

public boolean isPausable() {
Expand All @@ -138,6 +148,7 @@ public synchronized void start() {
if (!this.isRunning()) {
if (this.lifecycle != null && this.restartable) {
this.lifecycle.start();
this.running = true;
}
else {
this.logger.warn("Can not re-bind an anonymous binding");
Expand All @@ -152,6 +163,7 @@ public synchronized void stop() {
}
if (this.isRunning()) {
this.lifecycle.stop();
this.running = false;
}
}

Expand Down