if (_log.isDebugEnabled())
{
_log.debug("childAdded: " + child.getClass().getSimpleName() + "." + child.getName());
}
QmfAgentData data = null;
// We current don't listen for new virtualhostnodes or new virtualhosts, so any new instances
// of these objects wont be seen through QMF until the Broker is restarted.
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());
}
agentConnection = false; // Only ignore the first Connection, which is the one from the Agent.
}
else if (child instanceof Session)
{
if (!_objects.containsKey(child))
{
QmfAgentData ref = _objects.get(object); // Get the Connection QmfAgentData so we can get connectionRef.
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)
{
// Bindings are a little more complex because in QMF bindings contain exchangeRef and queueRef properties
// whereas with the Java Broker model Binding is a child of Queue and Exchange. To cope with this we
// first try to create or retrieve the QMF Binding Object then add either the Queue or Exchange reference
// 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 (!eName.equals("<<default>>")) // Don't send Event for Binding to default direct.
{
// 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 (child instanceof Consumer) // AKA Subscription
{
// Subscriptions are a little more complex because in QMF Subscriptions contain sessionRef and queueRef
// properties whereas with the Java Broker model Consumer is a child of Queue and Session. To cope with
// this we first try to create or retrieve the QMF Subscription Object then add either the Queue or
// 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