use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_8 method getReplyTo.
private String getReplyTo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
String replyTo = serverMsg.getMessageHeader().getReplyTo();
if (replyTo != null) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
final String replyToBindingUrl;
if (messageDestination instanceof Exchange) {
Exchange<?> exchange = (Exchange<?>) messageDestination;
final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
} else if (messageDestination instanceof Queue) {
replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
} else {
replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
}
return replyToBindingUrl;
}
return null;
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class ServerSessionDelegate method queueDeclare.
@Override
public void queueDeclare(ServerSession session, final QueueDeclare method) {
final NamedAddressSpace addressSpace = getAddressSpace(session);
String queueName = method.getQueue();
Queue<?> queue;
// TODO: do we need to check that the queue already exists with exactly the same "configuration"?
final boolean exclusive = method.getExclusive();
final boolean autoDelete = method.getAutoDelete();
if (method.getPassive()) {
queue = getQueue(addressSpace, queueName);
if (queue == null) {
String description = "Queue: " + queueName + " not found on VirtualHost(" + addressSpace + ").";
ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;
exception(session, method, errorCode, description);
} else if (exclusive) {
if (queue.getExclusive() == ExclusivityPolicy.NONE) {
String description = "Cannot passively declare queue ('" + queueName + "')" + " as exclusive as queue with same name is" + " already declared as non-exclusive";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
} else if (!verifySessionAccess(session, queue)) {
String description = "Cannot passively declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
}
}
} else {
try {
final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(queueName, method.getArguments());
final String alternateExchangeName = method.getAlternateExchange();
if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName)) {
validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
arguments.put(Queue.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
}
arguments.put(Queue.NAME, queueName);
if (!arguments.containsKey(Queue.LIFETIME_POLICY)) {
LifetimePolicy lifetime;
if (autoDelete) {
lifetime = exclusive ? LifetimePolicy.DELETE_ON_SESSION_END : LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS;
} else {
lifetime = LifetimePolicy.PERMANENT;
}
arguments.put(Queue.LIFETIME_POLICY, lifetime);
}
if (!arguments.containsKey(Queue.EXCLUSIVE)) {
ExclusivityPolicy exclusivityPolicy = exclusive ? ExclusivityPolicy.SESSION : ExclusivityPolicy.NONE;
arguments.put(Queue.EXCLUSIVE, exclusivityPolicy);
}
arguments.put(Queue.DURABLE, method.getDurable());
queue = addressSpace.createMessageSource(Queue.class, arguments);
} catch (AbstractConfiguredObject.DuplicateNameException qe) {
queue = (Queue<?>) qe.getExisting();
if (!verifySessionAccess(session, queue)) {
String description = "Cannot declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
exception(session, method, errorCode, description);
}
} catch (AccessControlException e) {
exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
} catch (UnknownAlternateBindingException e) {
exception(session, method, ExecutionErrorCode.NOT_FOUND, String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName()));
} catch (IllegalArgumentException | IllegalConfigurationException e) {
exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
}
}
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class ServerSessionDelegate method exchangeBound.
@Override
public void exchangeBound(ServerSession session, ExchangeBound method) {
ExchangeBoundResult result = new ExchangeBoundResult();
NamedAddressSpace addressSpace = getAddressSpace(session);
Exchange<?> exchange;
MessageSource source;
Queue<?> queue;
boolean isDefaultExchange;
if (!nameNullOrEmpty(method.getExchange())) {
isDefaultExchange = false;
exchange = getExchange(addressSpace, method.getExchange());
if (exchange == null) {
result.setExchangeNotFound(true);
}
} else {
isDefaultExchange = true;
exchange = null;
}
if (isDefaultExchange) {
// fake the existence of the "default" exchange for 0-10
if (method.hasQueue()) {
queue = getQueue(session, method.getQueue());
if (queue == null) {
result.setQueueNotFound(true);
} else {
if (method.hasBindingKey()) {
if (!method.getBindingKey().equals(method.getQueue())) {
result.setKeyNotMatched(true);
}
}
}
} else if (method.hasBindingKey()) {
if (getQueue(session, method.getBindingKey()) == null) {
result.setKeyNotMatched(true);
}
}
if (method.hasArguments() && !method.getArguments().isEmpty()) {
result.setArgsNotMatched(true);
}
} else if (method.hasQueue()) {
source = getMessageSource(session, method.getQueue());
if (source == null) {
result.setQueueNotFound(true);
}
if (source == null || source instanceof Queue) {
queue = (Queue<?>) source;
if (exchange != null && queue != null) {
boolean queueMatched = exchange.isBound(queue);
result.setQueueNotMatched(!queueMatched);
if (method.hasBindingKey()) {
if (queueMatched) {
final boolean keyMatched = exchange.isBound(method.getBindingKey(), queue);
result.setKeyNotMatched(!keyMatched);
if (method.hasArguments()) {
if (keyMatched) {
result.setArgsNotMatched(!exchange.isBound(method.getBindingKey(), method.getArguments(), queue));
} else {
result.setArgsNotMatched(!exchange.isBound(method.getArguments(), queue));
}
}
} else {
boolean keyMatched = exchange.isBound(method.getBindingKey());
result.setKeyNotMatched(!keyMatched);
if (method.hasArguments()) {
if (keyMatched) {
result.setArgsNotMatched(!exchange.isBound(method.getBindingKey(), method.getArguments()));
} else {
result.setArgsNotMatched(!exchange.isBound(method.getArguments()));
}
}
}
} else if (method.hasArguments()) {
if (queueMatched) {
result.setArgsNotMatched(!exchange.isBound(method.getArguments(), queue));
} else {
result.setArgsNotMatched(!exchange.isBound(method.getArguments()));
}
}
} else if (exchange != null && method.hasBindingKey()) {
final boolean keyMatched = exchange.isBound(method.getBindingKey());
result.setKeyNotMatched(!keyMatched);
if (method.hasArguments()) {
if (keyMatched) {
result.setArgsNotMatched(!exchange.isBound(method.getBindingKey(), method.getArguments()));
} else {
result.setArgsNotMatched(!exchange.isBound(method.getArguments()));
}
}
}
}
} else if (exchange != null && method.hasBindingKey()) {
final boolean keyMatched = exchange.isBound(method.getBindingKey());
result.setKeyNotMatched(!keyMatched);
if (method.hasArguments()) {
if (keyMatched) {
result.setArgsNotMatched(!exchange.isBound(method.getBindingKey(), method.getArguments()));
} else {
result.setArgsNotMatched(!exchange.isBound(method.getArguments()));
}
}
} else if (exchange != null && method.hasArguments()) {
result.setArgsNotMatched(!exchange.isBound(method.getArguments()));
}
session.executionResult((int) method.getId(), result);
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class ServerSessionDelegate method queueQuery.
@Override
public void queueQuery(ServerSession session, QueueQuery method) {
QueueQueryResult result = new QueueQueryResult();
MessageSource source = getMessageSource(session, method.getQueue());
if (source != null) {
result.setQueue(source.getName());
if (source instanceof Queue) {
final Queue<?> queue = (Queue<?>) source;
result.setDurable(queue.isDurable());
result.setExclusive(queue.isExclusive());
result.setAutoDelete(queue.getLifetimePolicy() != LifetimePolicy.PERMANENT);
Map<String, Object> arguments = new LinkedHashMap<>();
Collection<String> availableAttrs = queue.getAvailableAttributes();
for (String attrName : availableAttrs) {
arguments.put(attrName, queue.getAttribute(attrName));
}
result.setArguments(QueueArgumentsConverter.convertModelArgsToWire(arguments));
result.setMessageCount(queue.getQueueDepthMessages());
result.setSubscriberCount(queue.getConsumerCount());
} else {
result.setDurable(true);
result.setExclusive(false);
result.setAutoDelete(false);
result.setMessageCount(Integer.MAX_VALUE);
result.setSubscriberCount(0);
}
}
session.executionResult((int) method.getId(), result);
}
use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v0_8Test method testToConversionWhenQueueIsSpecified.
public void testToConversionWhenQueueIsSpecified() {
final String testQueue = "testQueue";
InternalMessage message = createTestMessage(testQueue);
final Queue queue = mock(Queue.class);
when(queue.getName()).thenReturn(testQueue);
when(_addressSpace.getAttainedMessageDestination(testQueue)).thenReturn(queue);
final AMQMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
assertEquals("Unexpected exchange", "", messagePublishInfo.getExchange().toString());
assertEquals("Unexpected routing key", testQueue, messagePublishInfo.getRoutingKey().toString());
}
Aggregations