use of org.apache.qpid.server.binding.BindingImpl in project qpid-broker-j by apache.
the class AbstractExchange method bind.
@Override
public boolean bind(final String destination, String bindingKey, Map<String, Object> arguments, boolean replaceExistingArguments) {
MessageDestination messageDestination = getAttainedMessageDestination(destination);
if (messageDestination == null) {
throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
}
if (bindingKey == null) {
bindingKey = "";
}
if (arguments == null) {
arguments = Collections.emptyMap();
}
Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
boolean modified = false;
for (Binding b : _bindings) {
if (b.getBindingKey().equals(bindingKey) && b.getDestination().equals(messageDestination.getName())) {
if (replaceExistingArguments) {
_bindings.remove(b);
modified = true;
break;
} else {
return false;
}
}
}
_bindings.add(newBinding);
if (isDurable() && messageDestination.isDurable()) {
final Collection<Binding> durableBindings = getDurableBindings();
attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
}
final BindingIdentifier bindingIdentifier = new BindingIdentifier(bindingKey, messageDestination);
if (modified) {
onBindingUpdated(bindingIdentifier, arguments);
} else {
final Map<String, Object> bindArguments = BIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination, arguments);
getEventLogger().message(_logSubject, BindingMessages.CREATED(String.valueOf(bindArguments)));
onBind(bindingIdentifier, arguments);
messageDestination.linkAdded(this, newBinding);
}
return true;
}
Aggregations