Search in sources :

Example 16 with Queue

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

the class MessageConverter_Internal_to_v0_8 method createMessagePublishInfo.

private MessagePublishInfo createMessagePublishInfo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
    String to = serverMsg.getTo();
    final String exchangeName;
    final String routingKey;
    if (to == null || "".equals(to)) {
        to = serverMsg.getInitialRoutingAddress();
    }
    if (to != null && !"".equals(to)) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        if (messageDestination instanceof Queue) {
            exchangeName = "";
            routingKey = messageDestination.getName();
        } else if (messageDestination instanceof Exchange) {
            exchangeName = messageDestination.getName();
            routingKey = destinationAddress.getRoutingKey();
        } else {
            exchangeName = "";
            routingKey = to;
        }
    } else {
        exchangeName = "";
        routingKey = "";
    }
    return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageDestination(org.apache.qpid.server.message.MessageDestination) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 17 with Queue

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

the class AsynchronousMessageStoreRecovererTest method testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted.

public void testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted() throws Exception {
    Queue<?> queue = mock(Queue.class);
    when(queue.getId()).thenReturn(UUID.randomUUID());
    when(_virtualHost.getChildren(eq(Queue.class))).thenReturn(Collections.singleton(queue));
    when(_store.getNextMessageId()).thenReturn(3L);
    when(_store.newTransaction()).thenReturn(mock(Transaction.class));
    final List<StoredMessage<?>> testMessages = new ArrayList<>();
    StoredMessage<?> storedMessage = createTestMessage(1L);
    testMessages.add(storedMessage);
    StoredMessage<?> orphanedMessage = createTestMessage(2L);
    testMessages.add(orphanedMessage);
    StoredMessage newMessage = createTestMessage(4L);
    testMessages.add(newMessage);
    final MessageEnqueueRecord messageEnqueueRecord = mock(MessageEnqueueRecord.class);
    UUID id = queue.getId();
    when(messageEnqueueRecord.getQueueId()).thenReturn(id);
    when(messageEnqueueRecord.getMessageNumber()).thenReturn(1L);
    MockStoreReader storeReader = new MockStoreReader(Collections.singletonList(messageEnqueueRecord), testMessages);
    when(_store.newMessageStoreReader()).thenReturn(storeReader);
    AsynchronousMessageStoreRecoverer recoverer = new AsynchronousMessageStoreRecoverer();
    ListenableFuture<Void> result = recoverer.recover(_virtualHost);
    assertNull(result.get());
    verify(orphanedMessage, times(1)).remove();
    verify(newMessage, times(0)).remove();
    verify(queue).recover(argThat(new ArgumentMatcher<ServerMessage>() {

        @Override
        public boolean matches(final Object argument) {
            if (argument instanceof ServerMessage) {
                ServerMessage serverMessage = (ServerMessage) argument;
                return serverMessage.getMessageNumber() == storedMessage.getMessageNumber();
            }
            return false;
        }
    }), same(messageEnqueueRecord));
}
Also used : ArrayList(java.util.ArrayList) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Transaction(org.apache.qpid.server.store.Transaction) StoredMessage(org.apache.qpid.server.store.StoredMessage) ArgumentMatcher(org.mockito.ArgumentMatcher) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue)

Example 18 with Queue

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

the class AsynchronousMessageStoreRecovererTest method testExceptionOnRecovery.

public void testExceptionOnRecovery() throws Exception {
    ServerScopedRuntimeException exception = new ServerScopedRuntimeException("test");
    doThrow(exception).when(_storeReader).visitMessageInstances(any(TransactionLogResource.class), any(MessageInstanceHandler.class));
    Queue<?> queue = mock(Queue.class);
    when(_virtualHost.getChildren(eq(Queue.class))).thenReturn(Collections.singleton(queue));
    AsynchronousMessageStoreRecoverer recoverer = new AsynchronousMessageStoreRecoverer();
    ListenableFuture<Void> result = recoverer.recover(_virtualHost);
    try {
        result.get();
        fail("ServerScopedRuntimeException should be rethrown");
    } catch (ExecutionException e) {
        assertEquals("Unexpected cause", exception, e.getCause());
    }
}
Also used : MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) ExecutionException(java.util.concurrent.ExecutionException) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) Queue(org.apache.qpid.server.model.Queue) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 19 with Queue

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

the class SendingLinkEndpoint method prepareConsumerOptionsAndFilters.

private void prepareConsumerOptionsAndFilters(final SendingDestination destination) throws AmqpErrorException {
    // TODO QPID-7952: this method might modify the source. this is not good encapsulation. furthermore if it does so then it should inform the link/linkregistry about it!
    _destination = destination;
    final Source source = getSource();
    EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
    boolean noLocal = false;
    JMSSelectorFilter messageFilter = null;
    if (destination instanceof ExchangeSendingDestination) {
        options.add(ConsumerOption.ACQUIRES);
        options.add(ConsumerOption.SEES_REQUEUES);
    } else if (destination instanceof StandardSendingDestination) {
        MessageSource messageSource = _destination.getMessageSource();
        if (messageSource instanceof Queue && ((Queue<?>) messageSource).getAvailableAttributes().contains("topic")) {
            source.setDistributionMode(StdDistMode.COPY);
        }
        Map<Symbol, Filter> filters = source.getFilter();
        Map<Symbol, Filter> actualFilters = new HashMap<>();
        if (filters != null) {
            for (Map.Entry<Symbol, Filter> entry : filters.entrySet()) {
                if (entry.getValue() instanceof NoLocalFilter) {
                    actualFilters.put(entry.getKey(), entry.getValue());
                    noLocal = true;
                } else if (messageFilter == null && entry.getValue() instanceof org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) {
                    org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) entry.getValue();
                    try {
                        messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
                        actualFilters.put(entry.getKey(), entry.getValue());
                    } catch (ParseException | SelectorParsingException | TokenMgrError e) {
                        Error error = new Error();
                        error.setCondition(AmqpError.INVALID_FIELD);
                        error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
                        error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
                        throw new AmqpErrorException(error);
                    }
                }
            }
        }
        source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
        if (source.getDistributionMode() != StdDistMode.COPY) {
            options.add(ConsumerOption.ACQUIRES);
            options.add(ConsumerOption.SEES_REQUEUES);
        }
    } else {
        throw new ConnectionScopedRuntimeException("Unknown destination type");
    }
    if (noLocal) {
        options.add(ConsumerOption.NO_LOCAL);
    }
    FilterManager filters = null;
    if (messageFilter != null) {
        filters = new FilterManager();
        filters.add(messageFilter.getName(), messageFilter);
    }
    _consumerOptions = options;
    _consumerFilters = filters;
}
Also used : ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) MessageSource(org.apache.qpid.server.message.MessageSource) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) FilterManager(org.apache.qpid.server.filter.FilterManager) SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue) JMSSelectorFilter(org.apache.qpid.server.filter.JMSSelectorFilter) NoLocalFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.NoLocalFilter) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) ParseException(org.apache.qpid.server.filter.selector.ParseException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 20 with Queue

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

the class ServerSessionDelegate method messageSubscribe.

@Override
public void messageSubscribe(ServerSession session, MessageSubscribe method) {
    /*
          TODO - work around broken Python tests
          Correct code should read like
          if not hasAcceptMode() exception ILLEGAL_ARGUMENT "Accept-mode not supplied"
          else if not method.hasAcquireMode() exception ExecutionErrorCode.ILLEGAL_ARGUMENT, "Acquire-mode not supplied"
        */
    if (!method.hasAcceptMode()) {
        method.setAcceptMode(MessageAcceptMode.EXPLICIT);
    }
    if (!method.hasAcquireMode()) {
        method.setAcquireMode(MessageAcquireMode.PRE_ACQUIRED);
    }
    if (!method.hasQueue()) {
        exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "queue not supplied");
    } else {
        String destination = method.getDestination();
        if (destination == null) {
            exception(session, method, ExecutionErrorCode.INVALID_ARGUMENT, "Subscriber must provide a destination. The protocol specification marking the destination argument as optional is considered a mistake.");
        } else if (session.getSubscription(destination) != null) {
            exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Subscription already exists with destination '" + destination + "'");
        } else {
            String queueName = method.getQueue();
            NamedAddressSpace addressSpace = getAddressSpace(session);
            final Collection<MessageSource> sources = new HashSet<>();
            final MessageSource queue = addressSpace.getAttainedMessageSource(queueName);
            if (method.getArguments() != null && method.getArguments().get("x-multiqueue") instanceof Collection) {
                for (Object object : (Collection<Object>) method.getArguments().get("x-multiqueue")) {
                    String sourceName = String.valueOf(object);
                    sourceName = sourceName.trim();
                    if (sourceName.length() != 0) {
                        MessageSource source = addressSpace.getAttainedMessageSource(sourceName);
                        if (source == null) {
                            sources.clear();
                            break;
                        } else {
                            sources.add(source);
                        }
                    }
                }
                queueName = method.getArguments().get("x-multiqueue").toString();
            } else if (queue != null) {
                sources.add(queue);
            }
            if (sources.isEmpty()) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "Queue: " + queueName + " not found");
            } else if (!verifySessionAccess(session, sources)) {
                exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
            } else {
                ProtocolEngine protocolEngine = getServerConnection(session).getAmqpConnection();
                FlowCreditManager_0_10 creditManager = new WindowCreditManager(0L, 0L);
                FilterManager filterManager = null;
                try {
                    filterManager = FilterManagerFactory.createManager(method.getArguments());
                } catch (AMQInvalidArgumentException amqe) {
                    exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Exception Creating FilterManager");
                    return;
                }
                if (method.hasArguments() && method.getArguments().containsKey(AMQPFilterTypes.REPLAY_PERIOD.toString())) {
                    Object value = method.getArguments().get(AMQPFilterTypes.REPLAY_PERIOD.toString());
                    final long period;
                    if (value instanceof Number) {
                        period = ((Number) value).longValue();
                    } else if (value instanceof String) {
                        try {
                            period = Long.parseLong(value.toString());
                        } catch (NumberFormatException e) {
                            exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Cannot parse value " + value + " as a number for filter " + AMQPFilterTypes.REPLAY_PERIOD.toString());
                            return;
                        }
                    } else {
                        exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "Cannot parse value " + value + " as a number for filter " + AMQPFilterTypes.REPLAY_PERIOD.toString());
                        return;
                    }
                    final long startingFrom = System.currentTimeMillis() - (1000l * period);
                    if (filterManager == null) {
                        filterManager = new FilterManager();
                    }
                    MessageFilter filter = new ArrivalTimeFilter(startingFrom, period == 0);
                    filterManager.add(filter.getName(), filter);
                }
                boolean multiQueue = sources.size() > 1;
                ConsumerTarget_0_10 target = new ConsumerTarget_0_10(session, destination, method.getAcceptMode(), method.getAcquireMode(), MessageFlowMode.WINDOW, creditManager, method.getArguments(), multiQueue);
                Integer priority = null;
                if (method.hasArguments() && method.getArguments().containsKey("x-priority")) {
                    Object value = method.getArguments().get("x-priority");
                    if (value instanceof Number) {
                        priority = ((Number) value).intValue();
                    } else if (value instanceof String) {
                        try {
                            priority = Integer.parseInt(value.toString());
                        } catch (NumberFormatException e) {
                        }
                    }
                }
                session.register(destination, target);
                try {
                    EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
                    if (method.getAcquireMode() == MessageAcquireMode.PRE_ACQUIRED) {
                        options.add(ConsumerOption.ACQUIRES);
                    }
                    if (method.getAcquireMode() != MessageAcquireMode.NOT_ACQUIRED || method.getAcceptMode() == MessageAcceptMode.EXPLICIT) {
                        options.add(ConsumerOption.SEES_REQUEUES);
                    }
                    if (method.getExclusive()) {
                        options.add(ConsumerOption.EXCLUSIVE);
                    }
                    for (MessageSource source : sources) {
                        source.addConsumer(target, filterManager, MessageTransferMessage.class, destination, options, priority);
                    }
                    target.updateNotifyWorkDesired();
                } catch (Queue.ExistingExclusiveConsumer existing) {
                    exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Queue has an exclusive consumer");
                } catch (Queue.ExistingConsumerPreventsExclusive exclusive) {
                    exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Queue has an existing consumer - can't subscribe exclusively");
                } catch (AccessControlException e) {
                    exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
                } catch (MessageSource.ConsumerAccessRefused consumerAccessRefused) {
                    exception(session, method, ExecutionErrorCode.RESOURCE_LOCKED, "Queue has an incompatible exclusivity policy");
                } catch (MessageSource.QueueDeleted queueDeleted) {
                    exception(session, method, ExecutionErrorCode.NOT_FOUND, "Queue was deleted");
                }
            }
        }
    }
}
Also used : ProtocolEngine(org.apache.qpid.server.transport.ProtocolEngine) AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) FilterManager(org.apache.qpid.server.filter.FilterManager) Queue(org.apache.qpid.server.model.Queue) ArrivalTimeFilter(org.apache.qpid.server.filter.ArrivalTimeFilter) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) MessageSource(org.apache.qpid.server.message.MessageSource) AccessControlException(java.security.AccessControlException) Collection(java.util.Collection) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) MessageFilter(org.apache.qpid.server.filter.MessageFilter)

Aggregations

Queue (org.apache.qpid.server.model.Queue)56 HashMap (java.util.HashMap)14 Exchange (org.apache.qpid.server.model.Exchange)12 MessageDestination (org.apache.qpid.server.message.MessageDestination)11 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)9 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)8 MessageSource (org.apache.qpid.server.message.MessageSource)6 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)5 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)4 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)4 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)4 Map (java.util.Map)3 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)3 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)3 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)3