Package org.apache.qpid.server.store

Examples of org.apache.qpid.server.store.MessageStore


                                           final long toMessageId,
                                           String queueName,
                                           final StoreContext storeContext)
    {
        AMQQueue toQueue = getVirtualHost().getQueueRegistry().getQueue(new AMQShortString(queueName));
        MessageStore store = getVirtualHost().getMessageStore();

        List<QueueEntry> entries = getMessagesOnTheQueue(new QueueEntryFilter()
        {

            public boolean accept(QueueEntry entry)
            {
                final long messageId = entry.getMessage().getMessageId();
                if ((messageId >= fromMessageId)
                    && (messageId <= toMessageId))
                {
                    if (!entry.isDeleted())
                    {
                        return entry.getMessage().incrementReference();
                    }
                }

                return false;
            }

            public boolean filterComplete()
            {
                return false;
            }
        });

        try
        {
            store.beginTran(storeContext);

            // Move the messages in on the message store.
            for (QueueEntry entry : entries)
            {
                AMQMessage message = entry.getMessage();

                if (message.isReferenced() && message.isPersistent() && toQueue.isDurable())
                {
                    store.enqueueMessage(storeContext, toQueue, message.getMessageId());
                }
            }

            // Commit and flush the move transcations.
            try
            {
                store.commitTran(storeContext);
            }
            catch (AMQException e)
            {
                throw new RuntimeException("Failed to commit transaction whilst moving messages on message store.", e);
            }
        }
        catch (AMQException e)
        {
            try
            {
                store.abortTran(storeContext);
            }
            catch (AMQException rollbackEx)
            {
                _logger.error("Failed to rollback transaction when error occured moving messages", rollbackEx);
            }
View Full Code Here


    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();
        ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
        QueueRegistry queueRegistry = virtualHost.getQueueRegistry();
        MessageStore store = virtualHost.getMessageStore();

        QueueDeclareBody body = evt.getMethod();

        // if we aren't given a queue name, we create one which we return to the client
        if (body.queue == null)
        {
            body.queue = createName();
        }

        AMQQueue queue;
        //TODO: do we need to check that the queue already exists with exactly the same "configuration"?

        synchronized (queueRegistry)
        {



            if (((queue = queueRegistry.getQueue(body.queue)) == null))
            {
                if(body.queue != null)
                {
                    body.queue = body.queue.intern();
                }

                if (body.passive)
                {
                    String msg = "Queue: " + body.queue + " not found on VirtualHost(" + virtualHost + ").";
                    throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
                }
                else
                {
                    queue = createQueue(body, virtualHost, session);
                    if (queue.isDurable() && !queue.isAutoDelete())
                    {
                        store.createQueue(queue);
                    }
                    queueRegistry.registerQueue(queue);
                    if (autoRegister)
                    {
                        Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
View Full Code Here

    public synchronized void moveMessagesToAnotherQueue(long fromMessageId, long toMessageId, String queueName,
                                                        StoreContext storeContext)
    {
        AMQQueue toQueue = getVirtualHost().getQueueRegistry().getQueue(new AMQShortString(queueName));

        MessageStore fromStore = getVirtualHost().getMessageStore();
        MessageStore toStore = toQueue.getVirtualHost().getMessageStore();

        if (toStore != fromStore)
        {
            throw new RuntimeException("Can only move messages between queues on the same message store.");
        }

        try
        {
            // Obtain locks to prevent activity on the queues being moved between.
            startMovingMessages();
            toQueue.startMovingMessages();

            // Get the list of messages to move.
            List<AMQMessage> foundMessagesList = getMessagesOnTheQueue(fromMessageId, toMessageId);

            try
            {
                fromStore.beginTran(storeContext);

                // Move the messages in on the message store.
                for (AMQMessage message : foundMessagesList)
                {
                    fromStore.dequeueMessage(storeContext, _name, message.getMessageId());
                    toStore.enqueueMessage(storeContext, toQueue._name, message.getMessageId());
                }

                // Commit and flush the move transcations.
                try
                {
View Full Code Here

    public synchronized void copyMessagesToAnotherQueue(long fromMessageId, long toMessageId, String queueName,
                                                        StoreContext storeContext)
    {
        AMQQueue toQueue = getVirtualHost().getQueueRegistry().getQueue(new AMQShortString(queueName));

        MessageStore fromStore = getVirtualHost().getMessageStore();
        MessageStore toStore = toQueue.getVirtualHost().getMessageStore();

        if (toStore != fromStore)
        {
            throw new RuntimeException("Can only move messages between queues on the same message store.");
        }

        try
        {
            // Obtain locks to prevent activity on the queues being moved between.
            startMovingMessages();
            toQueue.startMovingMessages();

            // Get the list of messages to move.
            List<AMQMessage> foundMessagesList = getMessagesOnTheQueue(fromMessageId, toMessageId);

            try
            {
                fromStore.beginTran(storeContext);

                // Move the messages in on the message store.
                for (AMQMessage message : foundMessagesList)
                {
                    toStore.enqueueMessage(storeContext, toQueue._name, message.getMessageId());
                    message.takeReference();
                }

                // Commit and flush the move transcations.
                try
View Full Code Here

     * @param storeContext  The context of the message store under which to perform the move. This is associated with
     *                      the stores transactional context.
     */
    public synchronized void removeMessagesFromQueue(long fromMessageId, long toMessageId, StoreContext storeContext)
    {
        MessageStore fromStore = getVirtualHost().getMessageStore();

        try
        {
            // Obtain locks to prevent activity on the queues being moved between.
            startMovingMessages();

            // Get the list of messages to move.
            List<AMQMessage> foundMessagesList = getMessagesOnTheQueue(fromMessageId, toMessageId);

            try
            {
                fromStore.beginTran(storeContext);

                // remove the messages in on the message store.
                for (AMQMessage message : foundMessagesList)
                {
                    fromStore.dequeueMessage(storeContext, _name, message.getMessageId());
                }

                // Commit and flush the move transcations.
                try
                {
                    fromStore.commitTran(storeContext);
                }
                catch (AMQException e)
                {
                    throw new RuntimeException("Failed to commit transaction whilst moving messages on message store.", e);
                }

                // remove the messages on the in-memory queues.
                _deliveryMgr.removeMovedMessages(foundMessagesList);
            }
            // Abort the move transactions on move failures.
            catch (AMQException e)
            {
                try
                {
                    fromStore.abortTran(storeContext);
                }
                catch (AMQException ae)
                {
                    throw new RuntimeException("Failed to abort transaction whilst moving messages on message store.", ae);
                }
View Full Code Here

            {
                delvProps.setExpiration(System.currentTimeMillis() + delvProps.getTtl());
            }

            MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
            final MessageStore store = getVirtualHost().getMessageStore();
            StoredMessage<MessageMetaData_0_10> storeMessage = store.addMessage(messageMetaData);
            storeMessage.addContent(0,xfr.getBody());
            storeMessage.flushToStore();
            MessageTransferMessage message = new MessageTransferMessage(storeMessage, ((ServerSession)_session).getReference());

            ArrayList<? extends BaseQueue> queues = exchange.route(message);
View Full Code Here

            exchangeInUse = exchange;
        }

        if(!queues.isEmpty())
        {
            final MessageStore store = getVirtualHost(ssn).getMessageStore();
            final StoredMessage<MessageMetaData_0_10> storeMessage = createAndFlushStoreMessage(xfr, messageMetaData, store);
            MessageTransferMessage message = new MessageTransferMessage(storeMessage, ((ServerSession)ssn).getReference());
            ((ServerSession) ssn).enqueue(message, queues);
        }
        else
View Full Code Here

        if (!(o instanceof MessageStore))
        {
            throw new ClassCastException("Message store class must implement " + MessageStore.class + ". Class " + clazz +
                                         " does not.");
        }
        MessageStore messageStore = (MessageStore) o;
        VirtualHostConfigRecoveryHandler recoveryHandler = new VirtualHostConfigRecoveryHandler(this);

        MessageStoreLogSubject storeLogSubject = new MessageStoreLogSubject(this, messageStore);

        messageStore.configureConfigStore(this.getName(),
                                          recoveryHandler,
                                          hostConfig.getStoreConfiguration(),
                                          storeLogSubject);

        messageStore.configureMessageStore(this.getName(),
                                           recoveryHandler,
                                           hostConfig.getStoreConfiguration(),
                                           storeLogSubject);
        messageStore.configureTransactionLog(this.getName(),
                                           recoveryHandler,
                                           hostConfig.getStoreConfiguration(),
                                           storeLogSubject);

        _messageStore = messageStore;
View Full Code Here

    }

    private MessageStore initialiseMessageStore(VirtualHostConfiguration hostConfig) throws Exception
    {
        String storeType = hostConfig.getConfig().getString("store.type");
        MessageStore  messageStore = null;
        if (storeType == null)
        {
            final Class<?> clazz = Class.forName(hostConfig.getMessageStoreClass());
            final Object o = clazz.newInstance();

            if (!(o instanceof MessageStore))
            {
                throw new ClassCastException(clazz + " does not implement " + MessageStore.class);
            }

            messageStore = (MessageStore) o;
        }
        else
        {
            messageStore = new MessageStoreCreator().createMessageStore(storeType);
        }

        final MessageStoreLogSubject storeLogSubject = new MessageStoreLogSubject(this, messageStore.getClass().getSimpleName());
        OperationalLoggingListener.listen(messageStore, storeLogSubject);

        messageStore.addEventListener(new BeforeActivationListener(), Event.BEFORE_ACTIVATE);
        messageStore.addEventListener(new AfterActivationListener(), Event.AFTER_ACTIVATE);
        messageStore.addEventListener(new BeforeCloseListener(), Event.BEFORE_CLOSE);
        messageStore.addEventListener(new BeforePassivationListener(), Event.BEFORE_PASSIVATE);
        if (messageStore instanceof HAMessageStore)
        {
            messageStore.addEventListener(new AfterInitialisationListener(), Event.AFTER_INIT);
        }

        return messageStore;
    }
View Full Code Here

    {
        BasicPublishBody publish = new BasicPublishBody();
        publish.exchange = new NullExchange().getName();
        ContentHeaderBody header = new ContentHeaderBody();
        List<ContentBody> body = new ArrayList<ContentBody>();
        MessageStore messageStore = new SkeletonMessageStore();
        // channel can be null since it is only used in ack processing which does not apply to this test
        TransactionalContext txContext = new NonTransactionalContext(messageStore, null,
                                                                     new LinkedList<RequiredDeliveryException>());
        body.add(new ContentBody());
        MessageHandleFactory factory = new MessageHandleFactory();
View Full Code Here

TOP

Related Classes of org.apache.qpid.server.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.