Search in sources :

Example 11 with ActiveMQBuffer

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

the class PagingStoreFactoryDatabase method reloadStores.

@Override
public synchronized List<PagingStore> reloadStores(final HierarchicalRepository<AddressSettings> addressSettingsRepository) throws Exception {
    // We assume the directory list < Integer.MAX_VALUE (this is only a list of addresses).
    JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME);
    directoryList.open();
    int size = ((Long) directoryList.size()).intValue();
    ActiveMQBuffer buffer = readActiveMQBuffer(directoryList, size);
    ArrayList<PagingStore> storesReturn = new ArrayList<>();
    while (buffer.readableBytes() > 0) {
        SimpleString table = buffer.readSimpleString();
        JDBCSequentialFileFactory factory = (JDBCSequentialFileFactory) newFileFactory(table.toString(), false);
        factory.start();
        JDBCSequentialFile addressFile = (JDBCSequentialFile) factory.createSequentialFile(ADDRESS_FILE);
        addressFile.open();
        size = ((Long) addressFile.size()).intValue();
        if (size == 0) {
            continue;
        }
        ActiveMQBuffer addrBuffer = readActiveMQBuffer(addressFile, size);
        SimpleString address = addrBuffer.readSimpleString();
        AddressSettings settings = addressSettingsRepository.getMatch(address.toString());
        PagingStore store = new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, factory, this, address, settings, executorFactory.getExecutor(), syncNonTransactional);
        storesReturn.add(store);
    }
    directoryList.close();
    return storesReturn;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 12 with ActiveMQBuffer

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

the class PagingStoreFactoryDatabase method readActiveMQBuffer.

private ActiveMQBuffer readActiveMQBuffer(SequentialFile file, int size) throws Exception {
    ByteBuffer byteBuffer = ByteBuffer.allocate(size);
    byteBuffer.mark();
    file.read(byteBuffer);
    byteBuffer.reset();
    ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(byteBuffer);
    buffer.writerIndex(size);
    return buffer;
}
Also used : ByteBuffer(java.nio.ByteBuffer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 13 with ActiveMQBuffer

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

the class TypedPropertiesTest method testEncodeDecodeEmpty.

@Test
public void testEncodeDecodeEmpty() throws Exception {
    TypedProperties emptyProps = new TypedProperties();
    ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024);
    emptyProps.encode(buffer.byteBuf());
    Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
    TypedProperties decodedProps = new TypedProperties();
    decodedProps.decode(buffer.byteBuf());
    TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps);
}
Also used : TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 14 with ActiveMQBuffer

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

the class CoreMessage method getLargeMessageBuffer.

private ActiveMQBuffer getLargeMessageBuffer() throws ActiveMQException {
    ActiveMQBuffer buffer;
    LargeBodyEncoder encoder = getBodyEncoder();
    encoder.open();
    int bodySize = (int) encoder.getLargeBodySize();
    buffer = new ChannelBufferWrapper(UnpooledByteBufAllocator.DEFAULT.heapBuffer(bodySize));
    encoder.encode(buffer, bodySize);
    encoder.close();
    return buffer;
}
Also used : ChannelBufferWrapper(org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper) LargeBodyEncoder(org.apache.activemq.artemis.core.message.LargeBodyEncoder) ResetLimitWrappedActiveMQBuffer(org.apache.activemq.artemis.core.buffers.impl.ResetLimitWrappedActiveMQBuffer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 15 with ActiveMQBuffer

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

the class CoreMessage method inflate.

private ActiveMQBuffer inflate(ActiveMQBuffer buffer) throws DataFormatException {
    int bytesToRead = buffer.readableBytes();
    Inflater inflater = new Inflater();
    inflater.setInput(ByteUtil.getActiveArray(buffer.readBytes(bytesToRead).toByteBuffer()));
    // get the real size of large message
    long sizeBody = getLongProperty(Message.HDR_LARGE_BODY_SIZE);
    byte[] data = new byte[(int) sizeBody];
    inflater.inflate(data);
    inflater.end();
    ActiveMQBuffer qbuff = ActiveMQBuffers.wrappedBuffer(data);
    qbuff.resetReaderIndex();
    qbuff.resetWriterIndex();
    qbuff.writeBytes(data);
    buffer = qbuff;
    return buffer;
}
Also used : Inflater(java.util.zip.Inflater) ResetLimitWrappedActiveMQBuffer(org.apache.activemq.artemis.core.buffers.impl.ResetLimitWrappedActiveMQBuffer) 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