Search in sources :

Example 1 with Binding

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

the class AbstractExchange method performDelete.

private void performDelete() {
    if (_closed.compareAndSet(false, true)) {
        performDeleteTasks();
        for (Binding b : _bindings) {
            final MessageDestination messageDestination = getAttainedMessageDestination(b.getDestination());
            if (messageDestination != null) {
                messageDestination.linkRemoved(this, b);
            }
        }
        for (MessageSender sender : _linkedSenders.keySet()) {
            sender.destinationRemoved(this);
        }
        if (_alternateBindingDestination != null) {
            _alternateBindingDestination.removeReference(AbstractExchange.this);
        }
        getEventLogger().message(_logSubject, ExchangeMessages.DELETED());
    }
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) MessageDestination(org.apache.qpid.server.message.MessageDestination) MessageSender(org.apache.qpid.server.message.MessageSender)

Example 2 with Binding

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

the class QmfManagementAgent method childAdded.

/**
 * ConfigurationChangeListener method called when a child ConfiguredObject is added.
 * <p>
 * This method checks the type of the child ConfiguredObject that has been added and creates the equivalent
 * QMF2 Management Object if one doesn't already exist. In most cases it's a one-to-one mapping, but for
 * Binding for example the Binding child is added to both Queue and Exchange so we only create the Binding
 * QMF2 Management Object once and add the queueRef and exchangeRef reference properties referencing the Queue
 * and Exchange parent Objects respectively, Similarly for Consumer (AKA Subscription).
 * <p>
 * This method is also responsible for raising the appropriate QMF2 Events when Management Objects are created.
 * @param object the parent object that the child is being added to.
 * @param child the child object being added.
 */
@Override
public void childAdded(final ConfiguredObject object, final ConfiguredObject child) {
    if (_log.isDebugEnabled()) {
        _log.debug("childAdded: " + child.getClass().getSimpleName() + "." + child.getName());
    }
    QmfAgentData data = null;
    if (child instanceof Broker) {
        data = new org.apache.qpid.server.qmf2.agentdata.Broker((Broker) child);
    } else if (child instanceof Connection) {
        if (!agentConnection && !_objects.containsKey(child)) {
            // If the parent object is the default vhost set it to null so that the Connection ignores it.
            VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost) object;
            data = new org.apache.qpid.server.qmf2.agentdata.Connection(vhost, (Connection) child);
            _objects.put(child, data);
            // Raise a Client Connect Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection) data).createClientConnectEvent());
        }
        // Only ignore the first Connection, which is the one from the Agent.
        agentConnection = false;
    } else if (child instanceof Session) {
        if (!_objects.containsKey(child)) {
            // Get the Connection QmfAgentData so we can get connectionRef.
            QmfAgentData ref = _objects.get(object);
            if (ref != null) {
                data = new org.apache.qpid.server.qmf2.agentdata.Session((Session) child, ref.getObjectId());
                _objects.put(child, data);
            }
        }
    } else if (child instanceof Exchange) {
        if (!_objects.containsKey(child)) {
            // If the parent object is the default vhost set it to null so that the Connection ignores it.
            VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost) object;
            data = new org.apache.qpid.server.qmf2.agentdata.Exchange(vhost, (Exchange) child);
            _objects.put(child, data);
            // Raise an Exchange Declare Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange) data).createExchangeDeclareEvent());
        }
    } else if (child instanceof Queue) {
        if (!_objects.containsKey(child)) {
            // If the parent object is the default vhost set it to null so that the Connection ignores it.
            VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost) object;
            data = new org.apache.qpid.server.qmf2.agentdata.Queue(vhost, (Queue) child);
            _objects.put(child, data);
            // Raise a Queue Declare Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue) data).createQueueDeclareEvent());
        }
    } else if (child instanceof Binding) {
        // depending on whether Queue or Exchange was the parent of this addChild() call.
        if (!_objects.containsKey(child)) {
            data = new org.apache.qpid.server.qmf2.agentdata.Binding((Binding) child);
            _objects.put(child, data);
            String eName = ((Binding) child).getExchange().getName();
            if (// Don't send Event for Binding to default direct.
            !eName.equals("<<default>>")) {
                // Raise a Bind Event.
                _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding) data).createBindEvent());
            }
        }
        org.apache.qpid.server.qmf2.agentdata.Binding binding = (org.apache.qpid.server.qmf2.agentdata.Binding) _objects.get(child);
        QmfAgentData ref = _objects.get(object);
        if (ref != null) {
            if (object instanceof Queue) {
                binding.setQueueRef(ref.getObjectId());
            } else if (object instanceof Exchange) {
                binding.setExchangeRef(ref.getObjectId());
            }
        }
    } else if (// AKA Subscription
    child instanceof Consumer) {
        // Session reference depending on whether Queue or Session was the parent of this addChild() call.
        if (!_objects.containsKey(child)) {
            data = new org.apache.qpid.server.qmf2.agentdata.Subscription((Consumer) child);
            _objects.put(child, data);
        }
        org.apache.qpid.server.qmf2.agentdata.Subscription subscription = (org.apache.qpid.server.qmf2.agentdata.Subscription) _objects.get(child);
        QmfAgentData ref = _objects.get(object);
        if (ref != null) {
            if (object instanceof Queue) {
                subscription.setQueueRef(ref.getObjectId(), (Queue) object);
                // Raise a Subscribe Event - N.B. Need to do it *after* we've set the queueRef.
                _agent.raiseEvent(subscription.createSubscribeEvent());
            } else if (object instanceof Session) {
                subscription.setSessionRef(ref.getObjectId());
            }
        }
    }
    try {
        // If we've created new QmfAgentData we register it with the Agent.
        if (data != null) {
            _agent.addObject(data);
        }
    } catch (QmfException qmfe) {
        _log.error("QmfException caught in QmfManagementAgent.addObject()", qmfe);
    }
    child.addChangeListener(this);
}
Also used : Binding(org.apache.qpid.server.model.Binding) Broker(org.apache.qpid.server.model.Broker) Connection(org.apache.qpid.server.model.Connection) Exchange(org.apache.qpid.server.model.Exchange) Consumer(org.apache.qpid.server.model.Consumer) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData) VirtualHost(org.apache.qpid.server.model.VirtualHost) Queue(org.apache.qpid.server.model.Queue) Session(org.apache.qpid.server.model.Session) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 3 with Binding

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

the class AbstractQueueTestBase method testBinding.

@Test
public void testBinding() throws Exception {
    _exchange.addBinding(_routingKey, _queue, Collections.EMPTY_MAP);
    assertTrue("Routing key was not bound", _exchange.isBound(_routingKey));
    assertTrue("Queue was not bound to key", _exchange.isBound(_routingKey, _queue));
    assertEquals("Exchange binding count", (long) 1, (long) _queue.getPublishingLinks().size());
    final Binding firstBinding = (Binding) _queue.getPublishingLinks().iterator().next();
    assertEquals("Wrong binding key", _routingKey, firstBinding.getBindingKey());
    _exchange.deleteBinding(_routingKey, _queue);
    assertFalse("Routing key was still bound", _exchange.isBound(_routingKey));
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Test(org.junit.Test)

Example 4 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 5 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)

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