GH-1570 Made DynamicDestinationsBindable synchronized

Made DynamicDestinationsBindable synchronized to preserve consistency to the internal map

Resolves #1570
This commit is contained in:
Oleg Zhurakousky
2019-01-01 11:19:42 +01:00
parent b0af0205ba
commit 112dad8d4e

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2019 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.
@@ -27,9 +27,9 @@ import org.springframework.cloud.stream.binder.Binding;
* A {@link Bindable} that stores the dynamic destination names and handles their
* unbinding.
*
* This class is not thread-safe.
*
* @author Ilayaperumal Gopinathan
* @author Oleg Zhurakousky
*/
public final class DynamicDestinationsBindable implements Bindable {
@@ -38,17 +38,17 @@ public final class DynamicDestinationsBindable implements Bindable {
*/
private final Map<String, Binding<?>> outputBindings = new HashMap<>();
public void addOutputBinding(String name, Binding<?> binding) {
public synchronized void addOutputBinding(String name, Binding<?> binding) {
this.outputBindings.put(name, binding);
}
@Override
public Set<String> getOutputs() {
public synchronized Set<String> getOutputs() {
return Collections.unmodifiableSet(outputBindings.keySet());
}
@Override
public void unbindOutputs(BindingService adapter) {
public synchronized void unbindOutputs(BindingService adapter) {
for (Map.Entry<String, Binding<?>> entry : outputBindings.entrySet()) {
entry.getValue().unbind();
}