Search in sources :

Example 1 with BindingImpl

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;
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) BindingImpl(org.apache.qpid.server.binding.BindingImpl) MessageDestination(org.apache.qpid.server.message.MessageDestination) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Aggregations

BindingImpl (org.apache.qpid.server.binding.BindingImpl)1 MessageDestination (org.apache.qpid.server.message.MessageDestination)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)1 Binding (org.apache.qpid.server.model.Binding)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1