use of org.apache.qpid.server.model.Queue in project qpid by apache.
the class QmfManagementAgent method onEvent.
// ******************************* QmfEventListener implementation method *******************************
/**
* Callback method triggered when the underlying QMF2 Agent has WorkItems available for processing.
* The purpose of this method is mainly to handle the METHOD_CALL WorkItem and demultiplex & delegate
* to the invokeMethod() call on the relevant concrete QmfAgentData Object.
* @param wi the WorkItem that has been passed by the QMF2 Agent to be processed here (mainly METHOD_CALL).
*/
@Override
public void onEvent(final WorkItem wi) {
if (wi.getType() == METHOD_CALL) {
MethodCallWorkItem item = (MethodCallWorkItem) wi;
MethodCallParams methodCallParams = item.getMethodCallParams();
String methodName = methodCallParams.getName();
ObjectId objectId = methodCallParams.getObjectId();
// Look up QmfAgentData by ObjectId from the Agent's internal Object store.
QmfAgentData object = _agent.getObject(objectId);
if (object == null) {
_agent.raiseException(item.getHandle(), "No object found with ID=" + objectId);
} else {
// other classes yet.
if (object instanceof org.apache.qpid.server.qmf2.agentdata.Broker) {
org.apache.qpid.server.qmf2.agentdata.Broker broker = (org.apache.qpid.server.qmf2.agentdata.Broker) object;
broker.invokeMethod(_agent, item.getHandle(), methodName, methodCallParams.getArgs());
} else if (object instanceof org.apache.qpid.server.qmf2.agentdata.Queue) {
org.apache.qpid.server.qmf2.agentdata.Queue queue = (org.apache.qpid.server.qmf2.agentdata.Queue) object;
queue.invokeMethod(_agent, item.getHandle(), methodName, methodCallParams.getArgs());
} else {
_agent.raiseException(item.getHandle(), "Unknown Method " + methodName + " on " + object.getClass().getSimpleName());
}
}
}
}
use of org.apache.qpid.server.model.Queue 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);
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class StandardQueueTest method testNonDurableImpliesMessageDurabilityNever.
@Test
public void testNonDurableImpliesMessageDurabilityNever() throws Exception {
getQueue().close();
getQueue().delete();
Map<String, Object> attributes = new HashMap<>();
attributes.put(Queue.NAME, getQname());
attributes.put(Queue.DURABLE, Boolean.FALSE);
attributes.put(Queue.MESSAGE_DURABILITY, MessageDurability.ALWAYS);
Queue queue = getVirtualHost().createChild(Queue.class, attributes);
assertNotNull("Queue was not created", queue);
setQueue(queue);
assertEquals(MessageDurability.NEVER, queue.getMessageDurability());
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class QueueEntryImplTestBase method testRouteToAlternateInvokesAction.
@Test
public void testRouteToAlternateInvokesAction() {
String dlqName = "dlq";
Map<String, Object> dlqAttributes = new HashMap<>();
dlqAttributes.put(Queue.ID, UUID.randomUUID());
dlqAttributes.put(Queue.NAME, dlqName);
Queue<?> dlq = (Queue<?>) _queueEntry.getQueue().getVirtualHost().createChild(Queue.class, dlqAttributes);
final AlternateBinding alternateBinding = mock(AlternateBinding.class);
when(alternateBinding.getDestination()).thenReturn(dlqName);
_queueEntry.getQueue().setAttributes(Collections.singletonMap(Queue.ALTERNATE_BINDING, alternateBinding));
final Action<? super MessageInstance> action = mock(Action.class);
when(_queueEntry.getMessage().isResourceAcceptable(dlq)).thenReturn(true);
when(_queueEntry.getMessage().checkValid()).thenReturn(true);
_queueEntry.acquire();
int enqueues = _queueEntry.routeToAlternate(action, null, null);
assertEquals("Unexpected number of enqueues", 1, enqueues);
verify(action).performAction(any());
assertEquals("Unexpected number of messages on DLQ", 1, dlq.getQueueDepthMessages());
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testVisitWhenNodeDeletedAfterAdvance.
@Test
public void testVisitWhenNodeDeletedAfterAdvance() {
final QueueEntryList list = mock(QueueEntryList.class);
final Map<String, Object> attributes = new HashMap<>();
attributes.put(Queue.NAME, _qname);
attributes.put(Queue.OWNER, _owner);
@SuppressWarnings("unchecked") final Queue queue = new AbstractQueue(attributes, _virtualHost) {
@Override
QueueEntryList getEntries() {
return list;
}
};
final MessageReference reference = mock(MessageReference.class);
final QueueEntry entry = mock(QueueEntry.class);
when(entry.isDeleted()).thenReturn(true);
when(entry.newMessageReference()).thenReturn(reference);
final QueueEntryIterator iterator = mock(QueueEntryIterator.class);
when(iterator.advance()).thenReturn(true, false);
when(iterator.getNode()).thenReturn(entry);
when(list.iterator()).thenReturn(iterator);
final QueueEntryVisitor visitor = mock(QueueEntryVisitor.class);
queue.visit(visitor);
verifyNoMoreInteractions(visitor);
verify(reference).release();
}
Aggregations