Search in sources :

Example 6 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class QueueEntryImplTestBase method testGetNext.

/**
 * Tests if entries in DEQUEUED or DELETED state are not returned by getNext method.
 */
public void testGetNext() throws Exception {
    int numberOfEntries = 5;
    QueueEntryImpl[] entries = new QueueEntryImpl[numberOfEntries];
    Map<String, Object> queueAttributes = new HashMap<String, Object>();
    queueAttributes.put(Queue.ID, UUID.randomUUID());
    queueAttributes.put(Queue.NAME, getName());
    final QueueManagingVirtualHost virtualHost = BrokerTestHelper.createVirtualHost("testVH");
    StandardQueueImpl queue = new StandardQueueImpl(queueAttributes, virtualHost);
    queue.open();
    OrderedQueueEntryList queueEntryList = queue.getEntries();
    // create test entries
    for (int i = 0; i < numberOfEntries; i++) {
        ServerMessage message = mock(ServerMessage.class);
        when(message.getMessageNumber()).thenReturn((long) i);
        final MessageReference reference = mock(MessageReference.class);
        when(reference.getMessage()).thenReturn(message);
        when(message.newReference()).thenReturn(reference);
        when(message.newReference(any(TransactionLogResource.class))).thenReturn(reference);
        QueueEntryImpl entry = (QueueEntryImpl) queueEntryList.add(message, null);
        entries[i] = entry;
    }
    // test getNext for not acquired entries
    for (int i = 0; i < numberOfEntries; i++) {
        QueueEntryImpl queueEntry = entries[i];
        QueueEntry next = queueEntry.getNextValidEntry();
        if (i < numberOfEntries - 1) {
            assertEquals("Unexpected entry from QueueEntryImpl#getNext()", entries[i + 1], next);
        } else {
            assertNull("The next entry after the last should be null", next);
        }
    }
    // discard second
    entries[1].acquire();
    entries[1].delete();
    // discard third
    entries[2].acquire();
    entries[2].delete();
    QueueEntry next = entries[0].getNextValidEntry();
    assertEquals("expected forth entry", entries[3], next);
    next = next.getNextValidEntry();
    assertEquals("expected fifth entry", entries[4], next);
    next = next.getNextValidEntry();
    assertNull("The next entry after the last should be null", next);
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 7 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class SortedQueueEntryTest method setUp.

@Override
public void setUp() throws Exception {
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(Queue.ID, UUID.randomUUID());
    attributes.put(Queue.NAME, getName());
    attributes.put(Queue.DURABLE, false);
    attributes.put(Queue.LIFETIME_POLICY, LifetimePolicy.PERMANENT);
    attributes.put(SortedQueue.SORT_KEY, "KEY");
    final QueueManagingVirtualHost virtualHost = BrokerTestHelper.createVirtualHost("testVH");
    SortedQueueImpl queue = new SortedQueueImpl(attributes, virtualHost) {

        SelfValidatingSortedQueueEntryList _entries;

        @Override
        protected void onOpen() {
            super.onOpen();
            _entries = new SelfValidatingSortedQueueEntryList(this);
        }

        @Override
        SelfValidatingSortedQueueEntryList getEntries() {
            return _entries;
        }
    };
    queue.open();
    _queueEntryList = (SelfValidatingSortedQueueEntryList) queue.getEntries();
    super.setUp();
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap)

Example 8 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class SendingLinkEndpoint method detach.

@Override
protected void detach(Error error, final boolean close) {
    if (_consumerTarget != null) {
        _consumerTarget.close();
    }
    Source source = getSource();
    TerminusExpiryPolicy expiryPolicy = source.getExpiryPolicy();
    NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
    List<Symbol> sourceCapabilities = source.getCapabilities() == null ? Collections.emptyList() : Arrays.asList(source.getCapabilities());
    if (close || TerminusExpiryPolicy.LINK_DETACH.equals(expiryPolicy) || ((expiryPolicy == null || TerminusExpiryPolicy.SESSION_END.equals(expiryPolicy)) && getSession().isClosing()) || (TerminusExpiryPolicy.CONNECTION_CLOSE.equals(expiryPolicy) && getSession().getConnection().isClosing())) {
        Error closingError = null;
        if (getDestination() instanceof ExchangeSendingDestination && addressSpace instanceof QueueManagingVirtualHost) {
            cleanUpUnsettledDeliveries();
            try {
                ((QueueManagingVirtualHost) addressSpace).removeSubscriptionQueue(((ExchangeSendingDestination) getDestination()).getQueue().getName());
                TerminusDurability sourceDurability = source.getDurable();
                if (sourceDurability != null && !TerminusDurability.NONE.equals(sourceDurability) && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
                    Pattern containerIdPattern = sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) ? ANY_CONTAINER_ID : Pattern.compile("^" + Pattern.quote(getSession().getConnection().getRemoteContainerId()) + "$");
                    Pattern linkNamePattern = Pattern.compile("^" + Pattern.quote(getLinkName()) + "\\|?\\d*$");
                    final Collection<LinkModel> links = addressSpace.findSendingLinks(containerIdPattern, linkNamePattern);
                    for (LinkModel link : links) {
                        if (link instanceof Link_1_0) {
                            ((Link_1_0) link).linkClosed();
                        }
                    }
                }
            } catch (AccessControlException e) {
                LOGGER.error("Error unregistering subscription", e);
                closingError = new Error(AmqpError.NOT_ALLOWED, "Error unregistering subscription");
            } catch (IllegalStateException e) {
                String message;
                if (sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
                    String subscriptionName = getLinkName();
                    int separator = subscriptionName.indexOf("|");
                    if (separator > 0) {
                        subscriptionName = subscriptionName.substring(0, separator);
                    }
                    message = "There are active consumers on the shared subscription '" + subscriptionName + "'";
                } else {
                    message = e.getMessage();
                }
                closingError = new Error(AmqpError.RESOURCE_LOCKED, message);
            } catch (NotFoundException e) {
                closingError = new Error(AmqpError.NOT_FOUND, e.getMessage());
            }
        }
        if (error == null) {
            error = closingError;
        } else {
            LOGGER.warn("Unexpected error on detaching endpoint {}: {}", getLinkName(), error);
        }
    } else if (addressSpace instanceof QueueManagingVirtualHost && ((QueueManagingVirtualHost) addressSpace).isDiscardGlobalSharedSubscriptionLinksOnDetach() && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
        // However, we keep one link (ending with "|global") to perform a null-source lookup upon un-subscription.
        if (!getLinkName().endsWith("|global")) {
            getLink().linkClosed();
        } else {
            Pattern linkNamePattern = Pattern.compile("^" + Pattern.quote(getLinkName()) + "$");
            final Collection<LinkModel> links = addressSpace.findSendingLinks(ANY_CONTAINER_ID, linkNamePattern);
            if (links.size() > 1) {
                getLink().linkClosed();
            }
        }
    }
    super.detach(error, close);
}
Also used : Pattern(java.util.regex.Pattern) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) 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) AccessControlException(java.security.AccessControlException) NotFoundException(org.apache.qpid.server.model.NotFoundException) TerminusDurability(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusDurability) 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) LinkModel(org.apache.qpid.server.protocol.LinkModel) TerminusExpiryPolicy(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusExpiryPolicy) Collection(java.util.Collection)

Example 9 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class HeadersBindingTest method setUp.

@Override
protected void setUp() {
    _count++;
    _queue = mock(Queue.class);
    TaskExecutor executor = new CurrentThreadTaskExecutor();
    executor.start();
    QueueManagingVirtualHost vhost = mock(QueueManagingVirtualHost.class);
    when(_queue.getVirtualHost()).thenReturn(vhost);
    when(_queue.getModel()).thenReturn(BrokerModel.getInstance());
    when(_queue.getTaskExecutor()).thenReturn(executor);
    when(_queue.getChildExecutor()).thenReturn(executor);
    final EventLogger eventLogger = new EventLogger();
    when(vhost.getEventLogger()).thenReturn(eventLogger);
    when(vhost.getTaskExecutor()).thenReturn(executor);
    when(vhost.getChildExecutor()).thenReturn(executor);
    _exchange = mock(Exchange.class);
    when(_exchange.getType()).thenReturn(ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
    when(_exchange.getEventLogger()).thenReturn(eventLogger);
    when(_exchange.getModel()).thenReturn(BrokerModel.getInstance());
    when(_exchange.getTaskExecutor()).thenReturn(executor);
    when(_exchange.getChildExecutor()).thenReturn(executor);
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) EventLogger(org.apache.qpid.server.logging.EventLogger) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) Queue(org.apache.qpid.server.model.Queue)

Example 10 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class BrokerTestHelper method createExchange.

public static Exchange<?> createExchange(String hostName, final boolean durable, final EventLogger eventLogger) throws Exception {
    final QueueManagingVirtualHost virtualHost = mockWithSystemPrincipal(QueueManagingVirtualHost.class, SYSTEM_PRINCIPAL);
    when(virtualHost.getName()).thenReturn(hostName);
    when(virtualHost.getEventLogger()).thenReturn(eventLogger);
    when(virtualHost.getDurableConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
    final ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
    when(virtualHost.getObjectFactory()).thenReturn(objectFactory);
    when(virtualHost.getModel()).thenReturn(objectFactory.getModel());
    when(virtualHost.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
    when(virtualHost.getChildExecutor()).thenReturn(TASK_EXECUTOR);
    when(virtualHost.getCategoryClass()).thenReturn(VirtualHost.class);
    final Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(org.apache.qpid.server.model.Exchange.ID, UUIDGenerator.generateExchangeUUID("amp.direct", virtualHost.getName()));
    attributes.put(org.apache.qpid.server.model.Exchange.NAME, "amq.direct");
    attributes.put(org.apache.qpid.server.model.Exchange.TYPE, "direct");
    attributes.put(org.apache.qpid.server.model.Exchange.DURABLE, durable);
    return Subject.doAs(SYSTEM_SUBJECT, new PrivilegedAction<Exchange<?>>() {

        @Override
        public Exchange<?> run() {
            return (Exchange<?>) objectFactory.create(Exchange.class, attributes, virtualHost);
        }
    });
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap)

Aggregations

QueueManagingVirtualHost (org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)18 HashMap (java.util.HashMap)12 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)3 AccessControlException (java.security.AccessControlException)2 Principal (java.security.Principal)2 Collection (java.util.Collection)2 Map (java.util.Map)2 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 Queue (org.apache.qpid.server.model.Queue)2 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)2 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 LogWriteException (com.sleepycat.je.LogWriteException)1 InetSocketAddress (java.net.InetSocketAddress)1