Package org.apache.activemq.store

Examples of org.apache.activemq.store.MessageStore


            SlaveLevelDBStore slave2 = createSlave(master, directories.get(2));
            asyncStart(slave2);
            masterStart.await();

            LOG.info("Adding messages...");
            MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));
            final int TOTAL = 500;
            for (int i = 0; i < TOTAL; i++) {
                if (i % ((int) (TOTAL * 0.10)) == 0) {
                    LOG.info("" + (100 * i / TOTAL) + "% done");
                }
View Full Code Here


        HashSet<ElectingLevelDBStore> slaves = new HashSet<ElectingLevelDBStore>(stores);
        slaves.remove(master);

        // Start sending messages to the master.
        ArrayList<String> expected_list = new ArrayList<String>();
        MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));
        final int TOTAL = 500;
        for (int i = 0; i < TOTAL; i++) {
            if (i % ((int) (TOTAL * 0.10)) == 0) {
                LOG.info("" + (100 * i / TOTAL) + "% done");
            }
View Full Code Here

        doTestNoDuplicateAfterCacheFullAndAcked(512);
    }

    public void doTestNoDuplicateAfterCacheFullAndAcked(final int auditDepth) throws Exception {
        final PersistenceAdapter persistenceAdapter =  brokerService.getPersistenceAdapter();
        final MessageStore queueMessageStore =
            persistenceAdapter.createQueueMessageStore(destination);
        final ConnectionContext contextNotInTx = new ConnectionContext();
        final ConsumerInfo consumerInfo = new ConsumerInfo();
        final DestinationStatistics destinationStatistics = new DestinationStatistics();
        consumerInfo.setExclusive(true);
        final Queue queue = new Queue(brokerService, destination,
                queueMessageStore, destinationStatistics, brokerService.getTaskRunnerFactory());

        // a workaround for this issue
        // queue.setUseCache(false);
        queue.systemUsage.getMemoryUsage().setLimit(1024 * 1024 * 10);
        queue.setMaxAuditDepth(auditDepth);
        queue.initialize();
        queue.start();


        ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
        ProducerInfo producerInfo = new ProducerInfo();
        ProducerState producerState = new ProducerState(producerInfo);
        producerExchange.setProducerState(producerState);
        producerExchange.setConnectionContext(contextNotInTx);

        final CountDownLatch receivedLatch = new CountDownLatch(count);
        final AtomicLong ackedCount = new AtomicLong(0);
        final AtomicLong enqueueCounter = new AtomicLong(0);
        final Vector<String> errors = new Vector<String>();

        // populate the queue store, exceed memory limit so that cache is disabled
        for (int i = 0; i < count; i++) {
            Message message = getMessage(i);
            queue.send(producerExchange, message);
        }

        assertEquals("store count is correct", count, queueMessageStore.getMessageCount());

        // pull from store in small windows
        Subscription subscription = new Subscription() {

            @Override
            public void add(MessageReference node) throws Exception {
                if (enqueueCounter.get() != node.getMessageId().getProducerSequenceId()) {
                    errors.add("Not in sequence at: " + enqueueCounter.get() + ", received: "
                            + node.getMessageId().getProducerSequenceId());
                }
                assertEquals("is in order", enqueueCounter.get(), node
                        .getMessageId().getProducerSequenceId());
                receivedLatch.countDown();
                enqueueCounter.incrementAndGet();
                node.decrementReferenceCount();
            }

            @Override
            public void add(ConnectionContext context, Destination destination)
                    throws Exception {
            }

            @Override
            public int countBeforeFull() {
                if (isFull()) {
                    return 0;
                } else {
                    return fullWindow - (int) (enqueueCounter.get() - ackedCount.get());
                }
            }

            @Override
            public void destroy() {
            };

            @Override
            public void gc() {
            }

            @Override
            public ConsumerInfo getConsumerInfo() {
                return consumerInfo;
            }

            @Override
            public ConnectionContext getContext() {
                return null;
            }

            @Override
            public long getDequeueCounter() {
                return 0;
            }

            @Override
            public long getDispatchedCounter() {
                return 0;
            }

            @Override
            public int getDispatchedQueueSize() {
                return 0;
            }

            @Override
            public long getEnqueueCounter() {
                return 0;
            }

            @Override
            public int getInFlightSize() {
                return 0;
            }

            @Override
            public int getInFlightUsage() {
                return 0;
            }

            @Override
            public ObjectName getObjectName() {
                return null;
            }

            @Override
            public int getPendingQueueSize() {
                return 0;
            }

            @Override
            public int getPrefetchSize() {
                return 0;
            }

            @Override
            public String getSelector() {
                return null;
            }

            @Override
            public boolean isBrowser() {
                return false;
            }

            @Override
            public boolean isFull() {
                return (enqueueCounter.get() - ackedCount.get()) >= fullWindow;
            }

            @Override
            public boolean isHighWaterMark() {
                return false;
            }

            @Override
            public boolean isLowWaterMark() {
                return false;
            }

            @Override
            public boolean isRecoveryRequired() {
                return false;
            }

            @Override
            public boolean matches(MessageReference node,
                    MessageEvaluationContext context) throws IOException {
                return true;
            }

            @Override
            public boolean matches(ActiveMQDestination destination) {
                return true;
            }

            @Override
            public void processMessageDispatchNotification(
                    MessageDispatchNotification mdn) throws Exception {
            }

            @Override
            public Response pullMessage(ConnectionContext context,
                    MessagePull pull) throws Exception {
                return null;
            }

            @Override
            public List<MessageReference> remove(ConnectionContext context,
                    Destination destination) throws Exception {
                return null;
            }

            @Override
            public void setObjectName(ObjectName objectName) {
            }

            @Override
            public void setSelector(String selector)
                    throws InvalidSelectorException,
                    UnsupportedOperationException {
            }

            @Override
            public void updateConsumerPrefetch(int newPrefetch) {
            }

            @Override
            public boolean addRecoveredMessage(ConnectionContext context,
                    MessageReference message) throws Exception {
                return false;
            }

            @Override
            public ActiveMQDestination getActiveMQDestination() {
                return destination;
            }

            @Override
            public void acknowledge(ConnectionContext context, MessageAck ack)
                    throws Exception {
            }

            @Override
            public int getCursorMemoryHighWaterMark(){
                return 0;
            }

            @Override
            public void setCursorMemoryHighWaterMark(
                    int cursorMemoryHighWaterMark) {
            }

            @Override
            public boolean isSlowConsumer() {
                return false;
            }

            @Override
            public void unmatched(MessageReference node) throws IOException {
            }

            @Override
            public long getTimeOfLastMessageAck() {
                return 0;
            }
        };

        queue.addSubscription(contextNotInTx, subscription);
        int removeIndex = 0;
        do {
            // Simulate periodic acks in small but recent windows
            long receivedCount = enqueueCounter.get();
            if (receivedCount > ackStartIndex) {
                if (receivedCount >= removeIndex + ackWindow) {
                    for (int j = 0; j < ackBatchSize; j++, removeIndex++) {
                        ackedCount.incrementAndGet();
                        MessageAck ack = new MessageAck();
                        ack.setLastMessageId(new MessageId(mesageIdRoot
                                + removeIndex));
                        ack.setMessageCount(1);
                        queue.removeMessage(contextNotInTx, subscription,
                                new IndirectMessageReference(
                                        getMessage(removeIndex)), ack);
                        queue.wakeup();

                    }
                    if (removeIndex % 1000 == 0) {
                        LOG.info("acked: " + removeIndex);
                        persistenceAdapter.checkpoint(true);
                    }
                }
            }

        } while (!receivedLatch.await(0, TimeUnit.MILLISECONDS) && errors.isEmpty());

        assertTrue("There are no errors: " + errors, errors.isEmpty());
        assertEquals(count, enqueueCounter.get());
        assertEquals("store count is correct", count - removeIndex,
                queueMessageStore.getMessageCount());
    }
View Full Code Here

        }
       
    }

    public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException {
        MessageStore rc = new JDBCMessageStore(this, getAdapter(), wireFormat, destination, audit);
        if (transactionStore != null) {
            rc = transactionStore.proxy(rc);
        }
        return rc;
    }
View Full Code Here

                        }
                        super.addSubscription(context, sub);
                    };
                };
            } else {
                MessageStore store = persistenceAdapter.createQueueMessageStore((ActiveMQQueue) destination);
                Queue queue = new Queue(destination, memoryManager, store, destinationStatistics, taskRunnerFactory);
                configureQueue(queue, destination);
                queue.initialize();
                return queue;
            }
View Full Code Here

        for (ActiveMQDestination odest : store.getDestinations()) {
            containerKeyCounter[0]++;
            if (odest instanceof ActiveMQQueue) {
                ActiveMQQueue dest = (ActiveMQQueue) odest;
                MessageStore queue = store.createQueueMessageStore(dest);

                QueuePB.Bean destRecord = new QueuePB.Bean();
                destRecord.setKey(containerKeyCounter[0]);
                destRecord.setBindingKind(ptp_kind);

                final long[] seqKeyCounter = new long[]{0};

                HashMap<String, Object> jsonMap = new HashMap<String, Object>();
                jsonMap.put("@class", "queue_destination");
                jsonMap.put("name", dest.getQueueName());
                String json = mapper.writeValueAsString(jsonMap);
                System.out.println(json);
                destRecord.setBindingData(new UTF8Buffer(json));
                manager.store_queue(destRecord);

                queue.recover(new MessageRecoveryListener() {
                    @Override
                    public boolean hasSpace() {
                        return true;
                    }
View Full Code Here

        return new MemoryPersistenceAdapter();
    }

    @Override
    public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException {
        MessageStore rc = queues.get(destination);
        if (rc == null) {
            rc = new MemoryMessageStore(destination);
            if (transactionStore != null) {
                rc = transactionStore.proxy(rc);
            }
View Full Code Here

    protected MemoryMessageStore asMemoryMessageStore(Object value) {
        if (value instanceof MemoryMessageStore) {
            return (MemoryMessageStore)value;
        }
        if (value instanceof ProxyMessageStore) {
            MessageStore delegate = ((ProxyMessageStore)value).getDelegate();
            if (delegate instanceof MemoryMessageStore) {
                return (MemoryMessageStore) delegate;
            }
        }
        LOG.warn("Expected an instance of MemoryMessageStore but was: " + value);
View Full Code Here

        }

        @Override
        public MessageStore createQueueMessageStore(ActiveMQQueue destination)
                throws IOException {
            MessageStore proxyMessageStoreWithException = new ProxyMessageStoreWithUpdateException(
                    kahaDB.createQueueMessageStore(destination), throwExceptionOnUpdate);
            return proxyMessageStoreWithException;
        }
View Full Code Here

        brokerService.start();
        DestinationStatistics parentStats = new DestinationStatistics();
        parentStats.setEnabled(true);

        TaskRunnerFactory taskFactory = new TaskRunnerFactory();
        MessageStore store = null;

        info.setDestination(destination);
        info.setPrefetchSize(100);

        producerBrokerExchange.setProducerState(producerState);
View Full Code Here

TOP

Related Classes of org.apache.activemq.store.MessageStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.