Search in sources :

Example 86 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class UTF8Test method testBigSize.

@Test
public void testBigSize() throws Exception {
    char[] chars = new char[0xffff + 1];
    for (int i = 0; i < chars.length; i++) {
        chars[i] = ' ';
    }
    String str = new String(chars);
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(0xffff + 4);
    try {
        UTF8Util.saveUTF(buffer.byteBuf(), str);
        Assert.fail("String is too big, supposed to throw an exception");
    } catch (Exception ignored) {
    }
    Assert.assertEquals("A buffer was supposed to be untouched since the string was too big", 0, buffer.writerIndex());
    chars = new char[25000];
    for (int i = 0; i < chars.length; i++) {
        chars[i] = 0x810;
    }
    str = new String(chars);
    try {
        UTF8Util.saveUTF(buffer.byteBuf(), str);
        Assert.fail("Encoded String is too big, supposed to throw an exception");
    } catch (Exception ignored) {
    }
    Assert.assertEquals("A buffer was supposed to be untouched since the string was too big", 0, buffer.writerIndex());
    // Testing a string right on the limit
    chars = new char[0xffff];
    for (int i = 0; i < chars.length; i++) {
        chars[i] = (char) (i % 100 + 1);
    }
    str = new String(chars);
    UTF8Util.saveUTF(buffer.byteBuf(), str);
    Assert.assertEquals(0xffff + DataConstants.SIZE_SHORT, buffer.writerIndex());
    String newStr = UTF8Util.readUTF(buffer);
    Assert.assertEquals(str, newStr);
}
Also used : ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 87 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PrintData method calculateCursorsInfo.

/**
 * Calculate the acks on the page system
 */
private static PageCursorsInfo calculateCursorsInfo(List<RecordInfo> records) throws Exception {
    PageCursorsInfo cursorInfo = new PageCursorsInfo();
    for (RecordInfo record : records) {
        byte[] data = record.data;
        ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(data);
        if (record.userRecordType == JournalRecordIds.ACKNOWLEDGE_CURSOR) {
            CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
            encoding.decode(buff);
            Set<PagePosition> set = cursorInfo.getCursorRecords().get(encoding.queueID);
            if (set == null) {
                set = new HashSet<>();
                cursorInfo.getCursorRecords().put(encoding.queueID, set);
            }
            set.add(encoding.position);
        } else if (record.userRecordType == JournalRecordIds.PAGE_CURSOR_COMPLETE) {
            CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
            encoding.decode(buff);
            Long queueID = Long.valueOf(encoding.queueID);
            Long pageNR = Long.valueOf(encoding.position.getPageNr());
            if (!cursorInfo.getCompletePages(queueID).add(pageNR)) {
                System.err.println("Page " + pageNR + " has been already set as complete on queue " + queueID);
            }
        } else if (record.userRecordType == JournalRecordIds.PAGE_TRANSACTION) {
            if (record.isUpdate) {
                PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding();
                pageUpdate.decode(buff);
                cursorInfo.getPgTXs().add(pageUpdate.pageTX);
            } else {
                PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl();
                pageTransactionInfo.decode(buff);
                pageTransactionInfo.setRecordID(record.id);
                cursorInfo.getPgTXs().add(pageTransactionInfo.getTransactionID());
            }
        }
    }
    return cursorInfo;
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) CursorAckRecordEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding) PageTransactionInfoImpl(org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl) PagePosition(org.apache.activemq.artemis.core.paging.cursor.PagePosition) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) PageUpdateTXEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageUpdateTXEncoding)

Example 88 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class XmlDataExporter method processMessageJournal.

/**
 * Read through the message journal and stuff all the events/data we care about into local data structures.  We'll
 * use this data later to print all the right information.
 *
 * @throws Exception will be thrown if anything goes wrong reading the journal
 */
private void processMessageJournal() throws Exception {
    ArrayList<RecordInfo> acks = new ArrayList<>();
    List<RecordInfo> records = new LinkedList<>();
    // We load these, but don't use them.
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    Journal messageJournal = storageManager.getMessageJournal();
    ActiveMQServerLogger.LOGGER.debug("Reading journal from " + config.getJournalDirectory());
    messageJournal.start();
    // Just logging these, no action necessary
    TransactionFailureCallback transactionFailureCallback = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records1, List<RecordInfo> recordsToDelete) {
            StringBuilder message = new StringBuilder();
            message.append("Encountered failed journal transaction: ").append(transactionID);
            for (int i = 0; i < records1.size(); i++) {
                if (i == 0) {
                    message.append("; Records: ");
                }
                message.append(records1.get(i));
                if (i != (records1.size() - 1)) {
                    message.append(", ");
                }
            }
            for (int i = 0; i < recordsToDelete.size(); i++) {
                if (i == 0) {
                    message.append("; RecordsToDelete: ");
                }
                message.append(recordsToDelete.get(i));
                if (i != (recordsToDelete.size() - 1)) {
                    message.append(", ");
                }
            }
            ActiveMQServerLogger.LOGGER.debug(message.toString());
        }
    };
    messageJournal.load(records, preparedTransactions, transactionFailureCallback, false);
    // Since we don't use these nullify the reference so that the garbage collector can clean them up
    preparedTransactions = null;
    for (RecordInfo info : records) {
        byte[] data = info.data;
        ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(data);
        Object o = DescribeJournal.newObjectEncoding(info, storageManager);
        if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE) {
            messages.put(info.id, ((MessageDescribe) o).getMsg().toCore());
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE_PROTOCOL) {
            messages.put(info.id, ((MessageDescribe) o).getMsg().toCore());
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_LARGE_MESSAGE) {
            messages.put(info.id, ((MessageDescribe) o).getMsg());
        } else if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
            ReferenceDescribe ref = (ReferenceDescribe) o;
            HashMap<Long, ReferenceDescribe> map = messageRefs.get(info.id);
            if (map == null) {
                HashMap<Long, ReferenceDescribe> newMap = new HashMap<>();
                newMap.put(ref.refEncoding.queueID, ref);
                messageRefs.put(info.id, newMap);
            } else {
                map.put(ref.refEncoding.queueID, ref);
            }
        } else if (info.getUserRecordType() == JournalRecordIds.ACKNOWLEDGE_REF) {
            acks.add(info);
        } else if (info.userRecordType == JournalRecordIds.ACKNOWLEDGE_CURSOR) {
            CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
            encoding.decode(buff);
            Set<PagePosition> set = cursorRecords.get(encoding.queueID);
            if (set == null) {
                set = new HashSet<>();
                cursorRecords.put(encoding.queueID, set);
            }
            set.add(encoding.position);
        } else if (info.userRecordType == JournalRecordIds.PAGE_TRANSACTION) {
            if (info.isUpdate) {
                PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding();
                pageUpdate.decode(buff);
                pgTXs.add(pageUpdate.pageTX);
            } else {
                PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl();
                pageTransactionInfo.decode(buff);
                pageTransactionInfo.setRecordID(info.id);
                pgTXs.add(pageTransactionInfo.getTransactionID());
            }
        }
    }
    messageJournal.stop();
    removeAcked(acks);
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) Set(java.util.Set) HashSet(java.util.HashSet) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) HashMap(java.util.HashMap) PageTransactionInfoImpl(org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl) ArrayList(java.util.ArrayList) Journal(org.apache.activemq.artemis.core.journal.Journal) DescribeJournal(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) LinkedList(java.util.LinkedList) PageUpdateTXEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PageUpdateTXEncoding) MessageDescribe(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal.MessageDescribe) CursorAckRecordEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ReferenceDescribe(org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal.ReferenceDescribe) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) HashSet(java.util.HashSet)

Example 89 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class PagingStoreFactoryDatabase method newFileFactory.

@Override
public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception {
    String tableName = "" + storageManager.generateID();
    SequentialFileFactory factory = newFileFactory(tableName, true);
    factory.start();
    SequentialFile file = factory.createSequentialFile(PagingStoreFactoryDatabase.ADDRESS_FILE);
    file.open();
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(SimpleString.sizeofNullableString(address));
    buffer.writeSimpleString(address);
    file.write(buffer, true);
    file.close();
    return factory;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 90 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class LargeMessageTest method fillAddress.

private void fillAddress() throws Exception {
    final int PAGE_MAX = 100 * 1024;
    final int PAGE_SIZE = 10 * 1024;
    // 1k
    final int MESSAGE_SIZE = 1024;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>(), storeType);
    server.start();
    server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.DROP);
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    session.createQueue(ADDRESS, ADDRESS, null, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    ClientMessage message;
    byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < 5000; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 1000 == 0) {
            session.commit();
        }
    }
    session.commit();
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)150 Test (org.junit.Test)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)49 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)38 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ByteBuffer (java.nio.ByteBuffer)34 Configuration (org.apache.activemq.artemis.core.config.Configuration)34 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)27 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)25 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)25 ArrayList (java.util.ArrayList)21 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)21 Queue (org.apache.activemq.artemis.core.server.Queue)18 HashMap (java.util.HashMap)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)15 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)15 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)14