Search in sources :

Example 81 with ActiveMQBuffer

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

the class ChannelImpl method doWrite.

private void doWrite(final Packet packet) {
    final ActiveMQBuffer buffer = packet.encode(connection);
    connection.getTransportConnection().write(buffer, false, false);
}
Also used : ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 82 with ActiveMQBuffer

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

the class ChannelImpl method send.

// This must never called by more than one thread concurrently
private boolean send(final Packet packet, final int reconnectID, final boolean flush, final boolean batch) {
    if (invokeInterceptors(packet, interceptors, connection) != null) {
        return false;
    }
    synchronized (sendLock) {
        packet.setChannelID(id);
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Sending packet nonblocking " + packet + " on channelID=" + id);
        }
        ActiveMQBuffer buffer = packet.encode(connection);
        lock.lock();
        try {
            if (failingOver) {
                waitForFailOver("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " timed-out waiting for fail-over condition on non-blocking send");
            }
            // Sanity check
            if (transferring) {
                throw ActiveMQClientMessageBundle.BUNDLE.cannotSendPacketDuringFailover();
            }
            if (resendCache != null && packet.isRequiresConfirmations()) {
                addResendPacket(packet);
            }
        } finally {
            lock.unlock();
        }
        if (logger.isTraceEnabled()) {
            logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Writing buffer for channelID=" + id);
        }
        checkReconnectID(reconnectID);
        // The actual send must be outside the lock, or with OIO transport, the write can block if the tcp
        // buffer is full, preventing any incoming buffers being handled and blocking failover
        connection.getTransportConnection().write(buffer, flush, batch);
        return true;
    }
}
Also used : ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 83 with ActiveMQBuffer

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

the class ClientConsumerImpl method handleCompressedMessage.

/**
 * This method deals with messages arrived as regular message but its contents are compressed.
 * Such messages come from message senders who are configured to compress large messages, and
 * if some of the messages are compressed below the min-large-message-size limit, they are sent
 * as regular messages.
 * <br>
 * However when decompressing the message, we are not sure how large the message could be..
 * for that reason we fake a large message controller that will deal with the message as it was a large message
 * <br>
 * Say that you sent a 1G message full of spaces. That could be just bellow 100K compressed but you wouldn't have
 * enough memory to decompress it
 */
private void handleCompressedMessage(final ClientMessageInternal clMessage) throws Exception {
    ClientLargeMessageImpl largeMessage = new ClientLargeMessageImpl();
    largeMessage.retrieveExistingData(clMessage);
    File largeMessageCache = null;
    if (session.isCacheLargeMessageClient()) {
        largeMessageCache = File.createTempFile("tmp-large-message-" + largeMessage.getMessageID() + "-", ".tmp");
        largeMessageCache.deleteOnExit();
    }
    ClientSessionFactory sf = session.getSessionFactory();
    ServerLocator locator = sf.getServerLocator();
    long callTimeout = locator.getCallTimeout();
    currentLargeMessageController = new LargeMessageControllerImpl(this, largeMessage.getLargeMessageSize(), callTimeout, largeMessageCache);
    currentLargeMessageController.setLocal(true);
    // sets the packet
    ActiveMQBuffer qbuff = clMessage.toCore().getBodyBuffer();
    int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
    final byte[] body = ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer());
    largeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController));
    currentLargeMessageController.addPacket(body, body.length, false);
    handleRegularMessage(largeMessage);
}
Also used : ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) File(java.io.File) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 84 with ActiveMQBuffer

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

the class AbstractJournalStorageManager method loadBindingJournal.

@Override
public JournalLoadInformation loadBindingJournal(final List<QueueBindingInfo> queueBindingInfos, final List<GroupingInfo> groupingInfos, final List<AddressBindingInfo> addressBindingInfos) throws Exception {
    List<RecordInfo> records = new ArrayList<>();
    List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
    JournalLoadInformation bindingsInfo = bindingsJournal.load(records, preparedTransactions, null);
    HashMap<Long, PersistentQueueBindingEncoding> mapBindings = new HashMap<>();
    for (RecordInfo record : records) {
        long id = record.id;
        ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
        byte rec = record.getUserRecordType();
        if (rec == JournalRecordIds.QUEUE_BINDING_RECORD) {
            PersistentQueueBindingEncoding bindingEncoding = newQueueBindingEncoding(id, buffer);
            mapBindings.put(bindingEncoding.getId(), bindingEncoding);
        } else if (rec == JournalRecordIds.ID_COUNTER_RECORD) {
            idGenerator.loadState(record.id, buffer);
        } else if (rec == JournalRecordIds.ADDRESS_BINDING_RECORD) {
            PersistentAddressBindingEncoding bindingEncoding = newAddressBindingEncoding(id, buffer);
            addressBindingInfos.add(bindingEncoding);
        } else if (rec == JournalRecordIds.GROUP_RECORD) {
            GroupingEncoding encoding = newGroupEncoding(id, buffer);
            groupingInfos.add(encoding);
        } else if (rec == JournalRecordIds.ADDRESS_SETTING_RECORD) {
            PersistedAddressSetting setting = newAddressEncoding(id, buffer);
            mapPersistedAddressSettings.put(setting.getAddressMatch(), setting);
        } else if (rec == JournalRecordIds.SECURITY_RECORD) {
            PersistedRoles roles = newSecurityRecord(id, buffer);
            mapPersistedRoles.put(roles.getAddressMatch(), roles);
        } else if (rec == JournalRecordIds.QUEUE_STATUS_RECORD) {
            QueueStatusEncoding statusEncoding = newQueueStatusEncoding(id, buffer);
            PersistentQueueBindingEncoding queueBindingEncoding = mapBindings.get(statusEncoding.queueID);
            if (queueBindingEncoding != null) {
                queueBindingEncoding.addQueueStatusEncoding(statusEncoding);
            } else {
                // unlikely to happen, so I didn't bother about the Logger method
                ActiveMQServerLogger.LOGGER.infoNoQueueWithID(statusEncoding.queueID, statusEncoding.getId());
                this.deleteQueueStatus(statusEncoding.getId());
            }
        } else {
            // unlikely to happen
            ActiveMQServerLogger.LOGGER.invalidRecordType(rec, new Exception("invalid record type " + rec));
        }
    }
    for (PersistentQueueBindingEncoding queue : mapBindings.values()) {
        queueBindingInfos.add(queue);
    }
    // just to give a hand to GC
    mapBindings.clear();
    // This will instruct the IDGenerator to beforeStop old records
    idGenerator.cleanup();
    return bindingsInfo;
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) QueueStatusEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PersistedRoles(org.apache.activemq.artemis.core.persistence.config.PersistedRoles) PersistedAddressSetting(org.apache.activemq.artemis.core.persistence.config.PersistedAddressSetting) ArrayList(java.util.ArrayList) InvalidParameterException(java.security.InvalidParameterException) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) PersistentAddressBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding) GroupingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.GroupingEncoding) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 85 with ActiveMQBuffer

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

the class UTF8Test method testValidateUTFOnDataInputStream.

private void testValidateUTFOnDataInputStream(final String str, final ActiveMQBuffer wrap) throws Exception {
    UTF8Util.saveUTF(wrap.byteBuf(), str);
    DataInputStream data = new DataInputStream(new ByteArrayInputStream(wrap.toByteBuffer().array()));
    String newStr = data.readUTF();
    Assert.assertEquals(str, newStr);
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream outData = new DataOutputStream(byteOut);
    outData.writeUTF(str);
    ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(byteOut.toByteArray());
    newStr = UTF8Util.readUTF(buffer);
    Assert.assertEquals(str, newStr);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) 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