Package org.apache.qpid.server.store.berkeleydb.tuples

Examples of org.apache.qpid.server.store.berkeleydb.tuples.QueueEntryTB


        Cursor cursor = null;
        try
        {
            cursor = _deliveryDb.openCursor(null, null);
            DatabaseEntry key = new DatabaseEntry();
            EntryBinding keyBinding = new QueueEntryTB();

            DatabaseEntry value = new DatabaseEntry();

            while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
            {
                QueueEntryKey qek = (QueueEntryKey) keyBinding.entryToObject(key);

                entries.add(qek);
            }

            try
View Full Code Here


        // _log.debug("public void enqueueMessage(Transaction tx = " + tx + ", AMQShortString name = " + name + ", Long messageId): called");

        AMQShortString name = new AMQShortString(queue.getResourceName());
       
        DatabaseEntry key = new DatabaseEntry();
        EntryBinding keyBinding = new QueueEntryTB();
        QueueEntryKey dd = new QueueEntryKey(name, messageId);
        keyBinding.objectToEntry(dd, key);
        DatabaseEntry value = new DatabaseEntry();
        ByteBinding.byteToEntry((byte) 0, value);

        try
        {
View Full Code Here

    public void dequeueMessage(final com.sleepycat.je.Transaction tx, final TransactionLogResource queue, Long messageId) throws AMQStoreException
    {
        AMQShortString name = new AMQShortString(queue.getResourceName());

        DatabaseEntry key = new DatabaseEntry();
        EntryBinding keyBinding = new QueueEntryTB();
        QueueEntryKey dd = new QueueEntryKey(name, messageId);

        keyBinding.objectToEntry(dd, key);

        if (_log.isDebugEnabled())
        {
            _log.debug("Dequeue message id " + messageId);
        }
View Full Code Here

            DatabaseEntry key = new DatabaseEntry();

            QueueEntryKey dd = new QueueEntryKey(queueName, 0);

            EntryBinding keyBinding = new QueueEntryTB();
            keyBinding.objectToEntry(dd, key);

            DatabaseEntry value = new DatabaseEntry();

            LinkedList<Long> messageIds = new LinkedList<Long>();

            OperationStatus status = cursor.getSearchKeyRange(key, value, LockMode.DEFAULT);
            dd = (QueueEntryKey) keyBinding.entryToObject(key);

            while ((status == OperationStatus.SUCCESS) && dd.getQueueName().equals(queueName))
            {

                messageIds.add(dd.getMessageId());
                status = cursor.getNext(key, value, LockMode.DEFAULT);
                if (status == OperationStatus.SUCCESS)
                {
                    dd = (QueueEntryKey) keyBinding.entryToObject(key);
                }
            }

            return messageIds;
        }
View Full Code Here

        // hold all non existing queues and their messages IDs
        final HashMap<String, HashSet<Long>> phantomMessageQueues = new HashMap<String, HashSet<Long>>();

        // delivery DB visitor to check message delivery and identify non existing queues
        final QueueEntryTB queueEntryTB = new QueueEntryTB();
        DatabaseVisitor messageDeliveryCheckVisitor = new DatabaseVisitor()
        {
            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                QueueEntryKey entryKey = (QueueEntryKey) queueEntryTB.entryToObject(key);
                Long messageId = entryKey.getMessageId();
                AMQShortString queueName = entryKey.getQueueName();
                if (!existingQueues.contains(queueName))
                {
                    String name = queueName.asString();
                    HashSet<Long> messages = phantomMessageQueues.get(name);
                    if (messages == null)
                    {
                        messages = new HashSet<Long>();
                        phantomMessageQueues.put(name, messages);
                    }
                    messages.add(messageId);
                    _count++;
                }
                else
                {
                    queueMessages.add(messageId);
                }
            }
        };
        _oldMessageStore.visitDelivery(messageDeliveryCheckVisitor);

        if (phantomMessageQueues.isEmpty())
        {
            _logger.info("No such messages were found");
        }
        else
        {
            _logger.info("Found " + messageDeliveryCheckVisitor.getVisitedCount()+ " such messages in total");

            for (Entry<String, HashSet<Long>> phantomQueue : phantomMessageQueues.entrySet())
            {
                String queueName = phantomQueue.getKey();
                HashSet<Long> messages = phantomQueue.getValue();

                _logger.info(MessageFormat.format("There are {0} messages which were previously delivered to non-durable queue ''{1}''",messages.size(), queueName));

                boolean createQueue;
                if(!_interactive)
                {
                    createQueue = true;
                    _logger.info("Running in batch-mode, marking queue as durable to ensure retention of the messages.");
                }
                else
                {
                    createQueue = userInteract("Do you want to make this queue durable?\n"
                                             + "NOTE: Answering No will result in these messages being discarded!");
                }

                if (createQueue)
                {
                    for (Long messageId : messages)
                    {
                        queueMessages.add(messageId);
                    }
                    AMQShortString name = new AMQShortString(queueName);
                    existingQueues.add(name);
                    QueueRecord record = new QueueRecord(name, null, false, null);
                    _newMessageStore.createQueue(record);
                }
            }
        }


        //Migrate _messageMetaDataDb;
        _logger.info("Message MetaData");
       
        final Database newMetaDataDB = _newMessageStore.getMetaDataDb();
        final TupleBinding<Object> oldMetaDataTupleBinding = _oldMessageStore.getMetaDataTupleBindingFactory().getInstance();
        final TupleBinding<Object> newMetaDataTupleBinding = _newMessageStore.getMetaDataTupleBindingFactory().getInstance();
       
        DatabaseVisitor metaDataVisitor = new DatabaseVisitor()
        {
            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                _count++;
                MessageMetaData metaData = (MessageMetaData) oldMetaDataTupleBinding.entryToObject(value);

                // get message id
                Long messageId = TupleBinding.getPrimitiveBinding(Long.class).entryToObject(key);

                // ONLY copy data if message is delivered to existing queue
                if (!queueMessages.contains(messageId))
                {
                    return;
                }
                DatabaseEntry newValue = new DatabaseEntry();
                newMetaDataTupleBinding.objectToEntry(metaData, newValue);
               
                newMetaDataDB.put(null, key, newValue);
            }
        };
        _oldMessageStore.visitMetaDataDb(metaDataVisitor);

        logCount(metaDataVisitor.getVisitedCount(), "Message MetaData");


        //Migrate _messageContentDb;
        _logger.info("Message Contents");
        final Database newContentDB = _newMessageStore.getContentDb();
       
        final TupleBinding<MessageContentKey> oldContentKeyTupleBinding = new MessageContentKeyTB_4();
        final TupleBinding<MessageContentKey> newContentKeyTupleBinding = new MessageContentKeyTB_5();
        final TupleBinding contentTB = new ContentTB();
       
        DatabaseVisitor contentVisitor = new DatabaseVisitor()
        {
            long _prevMsgId = -1; //Initialise to invalid value
            int _bytesSeenSoFar = 0;
           
            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                _count++;

                //determine the msgId of the current entry
                MessageContentKey_4 contentKey = (MessageContentKey_4) oldContentKeyTupleBinding.entryToObject(key);
                long msgId = contentKey.getMessageId();

                // ONLY copy data if message is delivered to existing queue
                if (!queueMessages.contains(msgId))
                {
                    return;
                }
                //if this is a new message, restart the byte offset count.
                if(_prevMsgId != msgId)
                {
                    _bytesSeenSoFar = 0;
                }

                //determine the content size
                ByteBuffer content = (ByteBuffer) contentTB.entryToObject(value);
                int contentSize = content.limit();

                //create the new key: id + previously seen data count
                MessageContentKey_5 newKey = new MessageContentKey_5(msgId, _bytesSeenSoFar);
                DatabaseEntry newKeyEntry = new DatabaseEntry();
                newContentKeyTupleBinding.objectToEntry(newKey, newKeyEntry);

                DatabaseEntry newValueEntry = new DatabaseEntry();
                contentTB.objectToEntry(content, newValueEntry);

                newContentDB.put(null, newKeyEntry, newValueEntry);

                _prevMsgId = msgId;
                _bytesSeenSoFar += contentSize;
            }
        };
        _oldMessageStore.visitContentDb(contentVisitor);

        logCount(contentVisitor.getVisitedCount(), "Message Content");


        //Migrate _deliveryDb;
        _logger.info("Delivery Records");
        final Database deliveryDb =_newMessageStore.getDeliveryDb();
        DatabaseVisitor deliveryDbVisitor = new DatabaseVisitor()
        {

            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                _count++;

                // get message id from entry key
                QueueEntryKey entryKey = (QueueEntryKey) queueEntryTB.entryToObject(key);
                AMQShortString queueName = entryKey.getQueueName();

                // ONLY copy data if message queue exists
                if (existingQueues.contains(queueName))
                {
View Full Code Here

        // Look for persistent messages stored for non-durable queues
        _logger.info("Checking for messages previously sent to non-durable queues");

        // delivery DB visitor to check message delivery and identify non existing queues
        final QueueEntryTB queueEntryTB = new QueueEntryTB();
        MessageDeliveryCheckVisitor messageDeliveryCheckVisitor =
                new MessageDeliveryCheckVisitor(queueEntryTB, queueVisitor.getExistingQueues());
        _oldMessageStore.visitDelivery(messageDeliveryCheckVisitor);

        final Set<Long> queueMessages = messageDeliveryCheckVisitor.getQueueMessages();
View Full Code Here

        Cursor cursor = null;
        try
        {
            cursor = _deliveryDb.openCursor(null, null);
            DatabaseEntry key = new DatabaseEntry();
            EntryBinding keyBinding = new QueueEntryTB();

            DatabaseEntry value = new DatabaseEntry();

            while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
            {
                QueueEntryKey qek = (QueueEntryKey) keyBinding.entryToObject(key);

                entries.add(qek);
            }

            try
            {
                cursor.close();
            }
            finally
            {
                cursor = null;
            }

            for(QueueEntryKey entry : entries)
            {
                AMQShortString queueName = entry.getQueueName();
                long messageId = entry.getMessageId();

                qerh.queueEntry(queueName.asString(),messageId);
            }
        }
        catch (DatabaseException e)
        {
            _log.error("Database Error: " + e.getMessage(), e);
            throw e;
        }
        finally
        {
            if (cursor != null)
            {
                cursor.close();
            }
        }

       
       
        TransactionLogRecoveryHandler.DtxRecordRecoveryHandler dtxrh = qerh.completeQueueEntryRecovery();

        cursor = null;
        try
        {
            cursor = _xidDb.openCursor(null, null);
            DatabaseEntry key = new DatabaseEntry();
            XidTB keyBinding = new XidTB();
            PreparedTransactionTB valueBinding = new PreparedTransactionTB();
            DatabaseEntry value = new DatabaseEntry();

            while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
            {
                Xid xid = keyBinding.entryToObject(key);
                PreparedTransaction preparedTransaction = valueBinding.entryToObject(value);
                dtxrh.dtxRecord(xid.getFormat(),xid.getGlobalId(),xid.getBranchId(),
                                preparedTransaction.getEnqueues(),preparedTransaction.getDequeues());
            }
View Full Code Here

                               long messageId) throws AMQStoreException
    {
        AMQShortString name = AMQShortString.valueOf(queue.getResourceName());

        DatabaseEntry key = new DatabaseEntry();
        EntryBinding keyBinding = new QueueEntryTB();
        QueueEntryKey dd = new QueueEntryKey(name, messageId);
        keyBinding.objectToEntry(dd, key);
        DatabaseEntry value = new DatabaseEntry();
        ByteBinding.byteToEntry((byte) 0, value);

        try
        {
View Full Code Here

                               long messageId) throws AMQStoreException
    {
        AMQShortString name = new AMQShortString(queue.getResourceName());

        DatabaseEntry key = new DatabaseEntry();
        EntryBinding keyBinding = new QueueEntryTB();
        QueueEntryKey dd = new QueueEntryKey(name, messageId);

        keyBinding.objectToEntry(dd, key);

        if (_log.isDebugEnabled())
        {
            _log.debug("Dequeue message id " + messageId);
        }
View Full Code Here

            DatabaseEntry key = new DatabaseEntry();

            QueueEntryKey dd = new QueueEntryKey(queueName, 0);

            EntryBinding keyBinding = new QueueEntryTB();
            keyBinding.objectToEntry(dd, key);

            DatabaseEntry value = new DatabaseEntry();

            LinkedList<Long> messageIds = new LinkedList<Long>();

            OperationStatus status = cursor.getSearchKeyRange(key, value, LockMode.DEFAULT);
            dd = (QueueEntryKey) keyBinding.entryToObject(key);

            while ((status == OperationStatus.SUCCESS) && dd.getQueueName().equals(queueName))
            {

                messageIds.add(dd.getMessageId());
                status = cursor.getNext(key, value, LockMode.DEFAULT);
                if (status == OperationStatus.SUCCESS)
                {
                    dd = (QueueEntryKey) keyBinding.entryToObject(key);
                }
            }

            return messageIds;
        }
View Full Code Here

TOP

Related Classes of org.apache.qpid.server.store.berkeleydb.tuples.QueueEntryTB

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.