Search in sources :

Example 6 with Binding

use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.

the class ExchangeControllerTest method convertNextVersionLegacyConfiguredObject.

@Test
public void convertNextVersionLegacyConfiguredObject() {
    final ExchangeController exchangeController = new ExchangeController(_legacyManagementController, Collections.emptySet());
    final String exchangeName = "testExchange";
    final String alternateExchangeName = "altExchange";
    final String queueName = "testQueue";
    final String bindingKey = "testBindingKey";
    final LegacyConfiguredObject nextVersionExchange = mock(LegacyConfiguredObject.class);
    final AlternateBinding alternateBinding = mock(AlternateBinding.class);
    final Binding nextVersionBinding = mock(Binding.class);
    final LegacyConfiguredObject nextVersionAlternateExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionVirtualHost = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    when(alternateBinding.getDestination()).thenReturn(alternateExchangeName);
    when(nextVersionExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionExchange.getAttribute("alternateBinding")).thenReturn(alternateBinding);
    when(nextVersionExchange.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(exchangeName);
    when(nextVersionExchange.getAttribute("bindings")).thenReturn(Collections.singletonList(nextVersionBinding));
    when(nextVersionExchange.getParent(VirtualHostController.TYPE)).thenReturn(nextVersionVirtualHost);
    when(nextVersionBinding.getDestination()).thenReturn(queueName);
    when(nextVersionBinding.getBindingKey()).thenReturn(bindingKey);
    when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionAlternateExchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn(alternateExchangeName);
    when(nextVersionVirtualHost.getChildren(ExchangeController.TYPE)).thenReturn(Arrays.asList(nextVersionExchange, nextVersionAlternateExchange));
    when(nextVersionVirtualHost.getChildren(QueueController.TYPE)).thenReturn(Collections.singletonList(queue));
    final LegacyConfiguredObject convertedExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedAltExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
    when(_legacyManagementController.convertFromNextVersion(nextVersionExchange)).thenReturn(convertedExchange);
    when(_legacyManagementController.convertFromNextVersion(nextVersionAlternateExchange)).thenReturn(convertedAltExchange);
    when(_legacyManagementController.convertFromNextVersion(queue)).thenReturn(convertedQueue);
    final LegacyConfiguredObject destination = exchangeController.convertFromNextVersion(nextVersionExchange);
    assertThat(destination.getAttribute("alternateExchange"), is(equalTo(convertedAltExchange)));
    final Collection<LegacyConfiguredObject> children = destination.getChildren(BindingController.TYPE);
    assertThat(children.size(), is(equalTo(1)));
    final LegacyConfiguredObject o = children.iterator().next();
    assertThat(o.getCategory(), is(equalTo(BindingController.TYPE)));
    assertThat(o.getAttribute(AbstractConfiguredObject.NAME), is(equalTo(bindingKey)));
    assertThat(o.getAttribute("queue"), is(equalTo(convertedQueue)));
    assertThat(o.getAttribute("exchange"), is(equalTo(convertedExchange)));
}
Also used : AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Test(org.junit.Test)

Example 7 with Binding

use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.

the class AbstractExchange method bindInternal.

private boolean bindInternal(final String destination, final String bindingKey, Map<String, Object> arguments, final boolean replaceExistingArguments) throws AMQInvalidArgumentException {
    MessageDestination messageDestination = getAttainedMessageDestination(destination);
    if (messageDestination == null) {
        throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
    }
    if (arguments == null) {
        arguments = Collections.emptyMap();
    }
    Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
    Binding previousBinding = null;
    for (Binding b : _bindings) {
        if (b.getBindingKey().equals(bindingKey) && b.getDestination().equals(messageDestination.getName())) {
            previousBinding = b;
            break;
        }
    }
    if (previousBinding != null && !replaceExistingArguments) {
        return false;
    }
    final BindingIdentifier bindingIdentifier = new BindingIdentifier(bindingKey, messageDestination);
    if (previousBinding != null) {
        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);
    }
    if (previousBinding != null) {
        _bindings.remove(previousBinding);
    }
    _bindings.add(newBinding);
    if (isDurable() && messageDestination.isDurable()) {
        final Collection<Binding> durableBindings = getDurableBindings();
        attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
    }
    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)

Example 8 with Binding

use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.

the class AbstractExchange method onOpen.

@Override
protected void onOpen() {
    super.onOpen();
    final ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>> durableBindingsAttribute = (ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>>) getModel().getTypeRegistry().getAttributeTypes(getTypeClass()).get(DURABLE_BINDINGS);
    final Collection<Binding> bindings = durableBindingsAttribute.convertValue(getActualAttributes().get(DURABLE_BINDINGS), this);
    if (bindings != null) {
        _bindings.addAll(bindings);
        for (Binding b : _bindings) {
            final MessageDestination messageDestination = getOpenedMessageDestination(b.getDestination());
            if (messageDestination != null) {
                Map<String, Object> arguments = b.getArguments() == null ? Collections.emptyMap() : b.getArguments();
                try {
                    onBind(new BindingIdentifier(b.getBindingKey(), messageDestination), arguments);
                } catch (AMQInvalidArgumentException e) {
                    throw new IllegalConfigurationException("Unexpected bind argument : " + e.getMessage(), e);
                }
                messageDestination.linkAdded(this, b);
            }
        }
    }
    if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_CREATING_LINK_CLOSE) {
        if (_creatingLinkInfo != null) {
            final LinkModel link;
            if (_creatingLinkInfo.isSendingLink()) {
                link = _virtualHost.getSendingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
            } else {
                link = _virtualHost.getReceivingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
            }
            addLifetimeConstraint(link);
        } else {
            throw new IllegalArgumentException("Exchanges created with a lifetime policy of " + getLifetimePolicy() + " must be created from a AMQP 1.0 link.");
        }
    }
    if (getAlternateBinding() != null) {
        String alternateDestination = getAlternateBinding().getDestination();
        _alternateBindingDestination = getOpenedMessageDestination(alternateDestination);
        if (_alternateBindingDestination != null) {
            _alternateBindingDestination.addReference(this);
        } else {
            LOGGER.warn("Cannot find alternate binding destination '{}' for exchange '{}'", alternateDestination, toString());
        }
    }
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) LinkModel(org.apache.qpid.server.protocol.LinkModel) Exchange(org.apache.qpid.server.model.Exchange) ConfiguredDerivedMethodAttribute(org.apache.qpid.server.model.ConfiguredDerivedMethodAttribute) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 9 with Binding

use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.

the class AbstractExchange method unbind.

@Override
public boolean unbind(@Param(name = "destination", mandatory = true) final String destination, @Param(name = "bindingKey") String bindingKey) {
    MessageDestination messageDestination = getAttainedMessageDestination(destination);
    if (messageDestination != null) {
        Iterator<Binding> bindingIterator = _bindings.iterator();
        while (bindingIterator.hasNext()) {
            Binding binding = bindingIterator.next();
            if (binding.getBindingKey().equals(bindingKey) && binding.getDestination().equals(destination)) {
                _bindings.remove(binding);
                messageDestination.linkRemoved(this, binding);
                onUnbind(new BindingIdentifier(bindingKey, messageDestination));
                if (!autoDeleteIfNecessary()) {
                    if (isDurable() && messageDestination.isDurable()) {
                        final Collection<Binding> durableBindings = getDurableBindings();
                        attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
                    }
                }
                final Map<String, Object> bindArguments = UNBIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination);
                getEventLogger().message(_logSubject, BindingMessages.DELETED(String.valueOf(bindArguments)));
                return true;
            }
        }
    }
    return false;
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) MessageDestination(org.apache.qpid.server.message.MessageDestination) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 10 with Binding

use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.

the class AbstractVirtualHost method hasDifferentBindings.

private boolean hasDifferentBindings(final Exchange<?> exchange, final Queue queue, final Map<String, Map<String, Object>> bindings) {
    for (String binding : bindings.keySet()) {
        boolean theSameBindingFound = false;
        for (Binding publishingLink : exchange.getPublishingLinks(queue)) {
            if (publishingLink.getBindingKey().equals(binding)) {
                Map<String, Object> expectedArguments = bindings.get(binding);
                Map<String, Object> actualArguments = publishingLink.getArguments();
                if (new HashMap<>(expectedArguments == null ? Collections.emptyMap() : expectedArguments).equals(new HashMap<>(actualArguments == null ? Collections.emptyMap() : actualArguments))) {
                    theSameBindingFound = true;
                }
            }
        }
        if (!theSameBindingFound) {
            return true;
        }
    }
    return false;
}
Also used : Binding(org.apache.qpid.server.model.Binding) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Aggregations

Binding (org.apache.qpid.server.model.Binding)20 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)10 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)9 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 Exchange (org.apache.qpid.server.model.Exchange)6 Test (org.junit.Test)6 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)5 MessageDestination (org.apache.qpid.server.message.MessageDestination)5 Queue (org.apache.qpid.server.model.Queue)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)3 List (java.util.List)2 UUID (java.util.UUID)2 BindingImpl (org.apache.qpid.server.binding.BindingImpl)2 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)2 ControllerManagementResponse (org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)2 Connection (org.apache.qpid.server.model.Connection)2