Search in sources :

Example 1 with Session

use of org.apache.qpid.server.model.Session 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 2 with Session

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

the class QmfManagementAgent method childRemoved.

/**
 * ConfigurationChangeListener method called when a child ConfiguredObject is removed.
 * <p>
 * This method checks the type of the child ConfiguredObject that has been removed and raises the appropriate
 * QMF2 Events, it then destroys the QMF2 Management Object and removes the mapping between child and the QMF Object.
 *
 * @param object the parent object that the child is being removed from.
 * @param child the child object being removed.
 */
@Override
public void childRemoved(final ConfiguredObject object, final ConfiguredObject child) {
    if (_log.isDebugEnabled()) {
        _log.debug("childRemoved: " + child.getClass().getSimpleName() + "." + child.getName());
    }
    child.removeChangeListener(this);
    // Look up the associated QmfAgentData and mark it for deletion by the Agent.
    QmfAgentData data = _objects.get(child);
    if (data != null) {
        if (child instanceof Connection) {
            // Raise a Client Disconnect Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection) data).createClientDisconnectEvent());
        } else if (child instanceof Session) {
        // no-op, don't need to do anything specific when Session is removed.
        } else if (child instanceof Exchange) {
            // Raise an Exchange Delete Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange) data).createExchangeDeleteEvent());
        } else if (child instanceof Queue) {
            // Raise a Queue Delete Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue) data).createQueueDeleteEvent());
        } else if (child instanceof Binding) {
            String eName = ((Binding) child).getExchange().getName();
            if (// Don't send Event for Unbinding from default direct.
            !eName.equals("<<default>>")) {
                // Raise an Unbind Event.
                _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding) data).createUnbindEvent());
            }
        } else if (child instanceof Consumer) {
            // Raise an Unsubscribe Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Subscription) data).createUnsubscribeEvent());
        }
        data.destroy();
    }
    // Remove the mapping from the internal ConfiguredObject->QmfAgentData Map.
    _objects.remove(child);
}
Also used : Binding(org.apache.qpid.server.model.Binding) 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) Queue(org.apache.qpid.server.model.Queue) Session(org.apache.qpid.server.model.Session)

Aggregations

QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)2 Binding (org.apache.qpid.server.model.Binding)2 Connection (org.apache.qpid.server.model.Connection)2 Consumer (org.apache.qpid.server.model.Consumer)2 Exchange (org.apache.qpid.server.model.Exchange)2 Queue (org.apache.qpid.server.model.Queue)2 Session (org.apache.qpid.server.model.Session)2 QmfException (org.apache.qpid.qmf2.common.QmfException)1 Broker (org.apache.qpid.server.model.Broker)1 VirtualHost (org.apache.qpid.server.model.VirtualHost)1