Search in sources :

Example 1 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class ActiveMQServerImpl method destroyQueue.

@Override
public void destroyQueue(final SimpleString queueName, final SecurityAuth session, final boolean checkConsumerCount, final boolean removeConsumers, final boolean autoDeleteAddress) throws Exception {
    if (postOffice == null) {
        return;
    }
    callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeDestroyQueue(queueName, session, checkConsumerCount, removeConsumers, autoDeleteAddress) : null);
    addressSettingsRepository.clearCache();
    Binding binding = postOffice.getBinding(queueName);
    if (binding == null) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(queueName);
    }
    SimpleString address = binding.getAddress();
    Queue queue = (Queue) binding.getBindable();
    // This check is only valid if checkConsumerCount == true
    if (checkConsumerCount && queue.getConsumerCount() != 0) {
        throw ActiveMQMessageBundle.BUNDLE.cannotDeleteQueue(queue.getName(), queueName, binding.getClass().getName());
    }
    if (session != null) {
        if (queue.isDurable()) {
            // make sure the user has privileges to delete this queue
            securityStore.check(address, queueName, CheckType.DELETE_DURABLE_QUEUE, session);
        } else {
            securityStore.check(address, queueName, CheckType.DELETE_NON_DURABLE_QUEUE, session);
        }
    }
    queue.deleteQueue(removeConsumers);
    callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterDestroyQueue(queue, address, session, checkConsumerCount, removeConsumers, autoDeleteAddress) : null);
    AddressInfo addressInfo = getAddressInfo(address);
    if (autoDeleteAddress && postOffice != null && addressInfo != null && addressInfo.isAutoCreated()) {
        try {
            removeAddressInfo(address, session);
        } catch (ActiveMQDeleteAddressException e) {
        // Could be thrown if the address has bindings or is not deletable.
        }
    }
    callPostQueueDeletionCallbacks(address, queueName);
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) Binding(org.apache.activemq.artemis.core.postoffice.Binding) ProtocolManagerFactory(org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory) ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl) RemotingServiceImpl(org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl) ActiveMQThreadPoolExecutor(org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor) JDBCJournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) Map(java.util.Map) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) EnumSet(java.util.EnumSet) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) ConfigurationUtils(org.apache.activemq.artemis.core.config.ConfigurationUtils) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin) PrintWriter(java.io.PrintWriter) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) BackupManager(org.apache.activemq.artemis.core.server.cluster.BackupManager) ActivateCallback(org.apache.activemq.artemis.core.server.ActivateCallback) Set(java.util.Set) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) HAPolicy(org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy) ResourceManager(org.apache.activemq.artemis.core.transaction.ResourceManager) ReloadManager(org.apache.activemq.artemis.core.server.reload.ReloadManager) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) PostQueueCreationCallback(org.apache.activemq.artemis.core.server.PostQueueCreationCallback) LocalGroupingHandler(org.apache.activemq.artemis.core.server.group.impl.LocalGroupingHandler) DeletionPolicy(org.apache.activemq.artemis.core.settings.impl.DeletionPolicy) AccessController(java.security.AccessController) Bindable(org.apache.activemq.artemis.core.server.Bindable) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Configuration(org.apache.activemq.artemis.core.config.Configuration) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) Version(org.apache.activemq.artemis.core.version.Version) ReusableLatch(org.apache.activemq.artemis.utils.ReusableLatch) ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint) Pair(org.apache.activemq.artemis.api.core.Pair) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CompositeAddress(org.apache.activemq.artemis.utils.CompositeAddress) AddressQueryResult(org.apache.activemq.artemis.core.server.AddressQueryResult) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ArrayList(java.util.ArrayList) VersionLoader(org.apache.activemq.artemis.utils.VersionLoader) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CriticalAnalyzerImpl(org.apache.activemq.artemis.utils.critical.CriticalAnalyzerImpl) ManagementFactory(java.lang.management.ManagementFactory) BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) StringWriter(java.io.StringWriter) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl) IOException(java.io.IOException) File(java.io.File) PersistedRoles(org.apache.activemq.artemis.core.persistence.config.PersistedRoles) OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) ServiceRegistry(org.apache.activemq.artemis.core.server.ServiceRegistry) ActiveMQPluginRunnable(org.apache.activemq.artemis.core.server.plugin.ActiveMQPluginRunnable) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ReloadManagerImpl(org.apache.activemq.artemis.core.server.reload.ReloadManagerImpl) OperationContextImpl(org.apache.activemq.artemis.core.persistence.impl.journal.OperationContextImpl) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) URL(java.net.URL) Date(java.util.Date) JournalType(org.apache.activemq.artemis.core.server.JournalType) RemoteGroupingHandler(org.apache.activemq.artemis.core.server.group.impl.RemoteGroupingHandler) CheckType(org.apache.activemq.artemis.core.security.CheckType) GroupingHandler(org.apache.activemq.artemis.core.server.group.GroupingHandler) ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) SecurityStore(org.apache.activemq.artemis.core.security.SecurityStore) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterImpl(org.apache.activemq.artemis.core.filter.impl.FilterImpl) PersistedAddressSetting(org.apache.activemq.artemis.core.persistence.config.PersistedAddressSetting) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadDumpUtil(org.apache.activemq.artemis.utils.ThreadDumpUtil) PagingStoreFactoryDatabase(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryDatabase) ResourceLimitSettings(org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings) Role(org.apache.activemq.artemis.core.security.Role) CriticalAnalyzerPolicy(org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy) BindingType(org.apache.activemq.artemis.core.postoffice.BindingType) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collection(java.util.Collection) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MemoryManager(org.apache.activemq.artemis.core.server.MemoryManager) Queue(org.apache.activemq.artemis.core.server.Queue) HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) SessionCallback(org.apache.activemq.artemis.spi.core.protocol.SessionCallback) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) CriticalComponent(org.apache.activemq.artemis.utils.critical.CriticalComponent) ReloadCallback(org.apache.activemq.artemis.core.server.reload.ReloadCallback) TimeUtils(org.apache.activemq.artemis.utils.TimeUtils) List(java.util.List) JdbcNodeManager(org.apache.activemq.artemis.core.server.impl.jdbc.JdbcNodeManager) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) PostQueueDeletionCallback(org.apache.activemq.artemis.core.server.PostQueueDeletionCallback) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) Divert(org.apache.activemq.artemis.core.server.Divert) GroupingHandlerConfiguration(org.apache.activemq.artemis.core.server.group.impl.GroupingHandlerConfiguration) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) Entry(java.util.Map.Entry) NetworkHealthCheck(org.apache.activemq.artemis.core.server.NetworkHealthCheck) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) ActivationFailureListener(org.apache.activemq.artemis.core.server.ActivationFailureListener) ActiveMQServerLogger(org.apache.activemq.artemis.core.server.ActiveMQServerLogger) FileStoreMonitor(org.apache.activemq.artemis.core.server.files.FileStoreMonitor) Filter(org.apache.activemq.artemis.core.filter.Filter) ActiveMQMessageBundle(org.apache.activemq.artemis.core.server.ActiveMQMessageBundle) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CriticalAnalyzer(org.apache.activemq.artemis.utils.critical.CriticalAnalyzer) Logger(org.jboss.logging.Logger) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) RemotingService(org.apache.activemq.artemis.core.remoting.server.RemotingService) HashMap(java.util.HashMap) PageCountPending(org.apache.activemq.artemis.core.persistence.impl.PageCountPending) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) SecurityStoreImpl(org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl) SecurityFormatter(org.apache.activemq.artemis.utils.SecurityFormatter) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) EmptyCriticalAnalyzer(org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer) CriticalAction(org.apache.activemq.artemis.utils.critical.CriticalAction) ActiveMQServerControlImpl(org.apache.activemq.artemis.core.management.impl.ActiveMQServerControlImpl) MBeanServer(javax.management.MBeanServer) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) LinkedList(java.util.LinkedList) ResourceManagerImpl(org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl) FileConfigurationParser(org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser) ExecutorService(java.util.concurrent.ExecutorService) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) FileMoveManager(org.apache.activemq.artemis.core.server.files.FileMoveManager) Semaphore(java.util.concurrent.Semaphore) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) CoreAddressConfiguration(org.apache.activemq.artemis.core.config.CoreAddressConfiguration) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) QueueFactory(org.apache.activemq.artemis.core.server.QueueFactory) ActiveMQDeleteAddressException(org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException) TimeUnit(java.util.concurrent.TimeUnit) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) ServiceComponent(org.apache.activemq.artemis.core.server.ServiceComponent) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ActiveMQDeleteAddressException(org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SynchronousQueue(java.util.concurrent.SynchronousQueue) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 2 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class HangConsumerTest method testHangDuplicateQueues.

/**
 * This would recreate the scenario where a queue was duplicated
 *
 * @throws Exception
 */
@Test
public void testHangDuplicateQueues() throws Exception {
    final Semaphore blocked = new Semaphore(1);
    final CountDownLatch latchDelete = new CountDownLatch(1);
    class MyQueueWithBlocking extends QueueImpl {

        /**
         * @param id
         * @param address
         * @param name
         * @param filter
         * @param pageSubscription
         * @param durable
         * @param temporary
         * @param scheduledExecutor
         * @param postOffice
         * @param storageManager
         * @param addressSettingsRepository
         * @param executor
         */
        MyQueueWithBlocking(final long id, final SimpleString address, final SimpleString name, final Filter filter, final SimpleString user, final PageSubscription pageSubscription, final boolean durable, final boolean temporary, final boolean autoCreated, final RoutingType deliveryMode, final Integer maxConsumers, final Boolean purgeOnNoConsumers, final ScheduledExecutorService scheduledExecutor, final PostOffice postOffice, final StorageManager storageManager, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final ArtemisExecutor executor, final ActiveMQServer server) {
            super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, deliveryMode, maxConsumers, purgeOnNoConsumers, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, null);
        }

        @Override
        public synchronized int deleteMatchingReferences(final int flushLimit, final Filter filter) throws Exception {
            latchDelete.countDown();
            blocked.acquire();
            blocked.release();
            return super.deleteMatchingReferences(flushLimit, filter);
        }

        @Override
        public void deliverScheduledMessages() {
        }
    }
    class LocalFactory extends QueueFactoryImpl {

        LocalFactory(final ExecutorFactory executorFactory, final ScheduledExecutorService scheduledExecutor, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final StorageManager storageManager, final ActiveMQServer server) {
            super(executorFactory, scheduledExecutor, addressSettingsRepository, storageManager, server);
        }

        @Override
        public Queue createQueueWith(final QueueConfig config) {
            queue = new MyQueueWithBlocking(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), config.deliveryMode(), config.maxConsumers(), config.isPurgeOnNoConsumers(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
            return queue;
        }

        @Deprecated
        @Override
        public Queue createQueue(final long persistenceID, final SimpleString address, final SimpleString name, final Filter filter, final PageSubscription pageSubscription, final SimpleString user, final boolean durable, final boolean temporary, final boolean autoCreated) {
            queue = new MyQueueWithBlocking(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, RoutingType.MULTICAST, null, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
            return queue;
        }
    }
    LocalFactory queueFactory = new LocalFactory(server.getExecutorFactory(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getStorageManager(), server);
    queueFactory.setPostOffice(server.getPostOffice());
    ((ActiveMQServerImpl) server).replaceQueueFactory(queueFactory);
    queue = server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
    blocked.acquire();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    ClientProducer producer = session.createProducer(QUEUE);
    producer.send(session.createMessage(true));
    session.commit();
    Thread tDelete = new Thread() {

        @Override
        public void run() {
            try {
                server.destroyQueue(QUEUE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    tDelete.start();
    Assert.assertTrue(latchDelete.await(10, TimeUnit.SECONDS));
    try {
        server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
    } catch (Exception expected) {
    }
    blocked.release();
    server.stop();
    tDelete.join();
    session.close();
    // a duplicate binding would impede the server from starting
    server.start();
    waitForServerToStart(server);
    server.stop();
}
Also used : HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) Semaphore(java.util.concurrent.Semaphore) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) QueueFactoryImpl(org.apache.activemq.artemis.core.server.impl.QueueFactoryImpl) Filter(org.apache.activemq.artemis.core.filter.Filter) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) Test(org.junit.Test)

Example 3 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class InterruptedLargeMessageTest method testRestartBeforeDelete.

@Test
public void testRestartBeforeDelete() throws Exception {
    class NoPostACKQueue extends QueueImpl {

        NoPostACKQueue(long id, SimpleString address, SimpleString name, Filter filter, SimpleString user, PageSubscription pageSubscription, boolean durable, boolean temporary, boolean autoCreated, ScheduledExecutorService scheduledExecutor, PostOffice postOffice, StorageManager storageManager, HierarchicalRepository<AddressSettings> addressSettingsRepository, ArtemisExecutor executor) {
            super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, null, null);
        }

        @Override
        public void postAcknowledge(final MessageReference ref) {
            System.out.println("Ignoring postACK on message " + ref);
        }

        @Override
        public void deliverScheduledMessages() {
        }
    }
    final class NoPostACKQueueFactory implements QueueFactory {

        final StorageManager storageManager;

        final PostOffice postOffice;

        final ScheduledExecutorService scheduledExecutor;

        final HierarchicalRepository<AddressSettings> addressSettingsRepository;

        final ExecutorFactory execFactory;

        NoPostACKQueueFactory(StorageManager storageManager, PostOffice postOffice, ScheduledExecutorService scheduledExecutor, HierarchicalRepository<AddressSettings> addressSettingsRepository, final ExecutorFactory execFactory) {
            this.storageManager = storageManager;
            this.postOffice = postOffice;
            this.scheduledExecutor = scheduledExecutor;
            this.addressSettingsRepository = addressSettingsRepository;
            this.execFactory = execFactory;
        }

        @Override
        public Queue createQueueWith(final QueueConfig config) {
            return new NoPostACKQueue(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
        }

        @Deprecated
        @Override
        public Queue createQueue(long persistenceID, SimpleString address, SimpleString name, Filter filter, PageSubscription pageSubscription, SimpleString user, boolean durable, boolean temporary, boolean autoCreated) {
            return new NoPostACKQueue(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
        }

        /* (non-Javadoc)
          * @see org.apache.activemq.artemis.core.server.QueueFactory#setPostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)
          */
        @Override
        public void setPostOffice(PostOffice postOffice) {
        }
    }
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    QueueFactory original = server.getQueueFactory();
    ((ActiveMQServerImpl) server).replaceQueueFactory(new NoPostACKQueueFactory(server.getStorageManager(), server.getPostOffice(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getExecutorFactory()));
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        producer.send(clientFile);
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = cons.receive(5000);
        Assert.assertNotNull(msg);
        msg.saveToOutputStream(new java.io.OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        });
        msg.acknowledge();
        session.commit();
    }
    ((ActiveMQServerImpl) server).replaceQueueFactory(original);
    server.fail(false);
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) IOException(java.io.IOException) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueFactory(org.apache.activemq.artemis.core.server.QueueFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Filter(org.apache.activemq.artemis.core.filter.Filter) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 4 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class SimpleOpenWireTest method checkQueueEmpty.

private void checkQueueEmpty(String qName) {
    PostOffice po = server.getPostOffice();
    LocalQueueBinding binding = (LocalQueueBinding) po.getBinding(SimpleString.toSimpleString(qName));
    try {
        // waiting for last ack to finish
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    assertEquals(0L, binding.getQueue().getMessageCount());
}
Also used : LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)

Example 5 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class ClusterTestBase method waitForBindings.

protected void waitForBindings(final int node, final String address, final int expectedBindingCount, final int expectedConsumerCount, final boolean local) throws Exception {
    log.debug("waiting for bindings on node " + node + " address " + address + " expectedBindingCount " + expectedBindingCount + " consumerCount " + expectedConsumerCount + " local " + local);
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalArgumentException("No server at " + node);
    }
    long timeout = ActiveMQTestBase.WAIT_TIMEOUT;
    if (waitForBindings(server, address, local, expectedBindingCount, expectedConsumerCount, timeout)) {
        return;
    }
    PostOffice po = server.getPostOffice();
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    System.out.println("=======================================================================");
    System.out.println("Binding information for address = " + address + " on node " + node);
    for (Binding binding : bindings.getBindings()) {
        if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
            QueueBinding qBinding = (QueueBinding) binding;
            System.out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
        }
    }
    StringWriter writer = new StringWriter();
    PrintWriter out = new PrintWriter(writer);
    try {
        for (ActiveMQServer activeMQServer : servers) {
            if (activeMQServer != null) {
                out.println(clusterDescription(activeMQServer));
                out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
            }
        }
        for (ActiveMQServer activeMQServer : servers) {
            out.println("Management bindings on " + activeMQServer);
            if (activeMQServer != null) {
                out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
            }
        }
    } catch (Throwable dontCare) {
    }
    logAndSystemOut(writer.toString());
    throw new IllegalStateException("Didn't get the expected number of bindings, look at the logging for more information");
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) StringWriter(java.io.StringWriter) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PrintWriter(java.io.PrintWriter)

Aggregations

PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)12 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)6 Binding (org.apache.activemq.artemis.core.postoffice.Binding)5 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)5 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)4 Test (org.junit.Test)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 Filter (org.apache.activemq.artemis.core.filter.Filter)3 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)3 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)3 QueueConfig (org.apache.activemq.artemis.core.server.QueueConfig)3 HierarchicalRepository (org.apache.activemq.artemis.core.settings.HierarchicalRepository)3 ExecutorFactory (org.apache.activemq.artemis.utils.ExecutorFactory)3 File (java.io.File)2