Search in sources :

Example 1 with LargeBodyEncoder

use of org.apache.activemq.artemis.core.message.LargeBodyEncoder 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 2 with LargeBodyEncoder

use of org.apache.activemq.artemis.core.message.LargeBodyEncoder in project activemq-artemis by apache.

the class XmlDataExporter method printLargeMessageBody.

private void printLargeMessageBody(LargeServerMessage message) throws XMLStreamException {
    xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_IS_LARGE, Boolean.TRUE.toString());
    LargeBodyEncoder encoder = null;
    try {
        encoder = message.toCore().getBodyEncoder();
        encoder.open();
        long totalBytesWritten = 0;
        Long bufferSize;
        long bodySize = encoder.getLargeBodySize();
        for (long i = 0; i < bodySize; i += LARGE_MESSAGE_CHUNK_SIZE) {
            Long remainder = bodySize - totalBytesWritten;
            if (remainder >= LARGE_MESSAGE_CHUNK_SIZE) {
                bufferSize = LARGE_MESSAGE_CHUNK_SIZE;
            } else {
                bufferSize = remainder;
            }
            ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(bufferSize.intValue());
            encoder.encode(buffer, bufferSize.intValue());
            xmlWriter.writeCData(XmlDataExporterUtil.encode(buffer.toByteBuffer().array()));
            totalBytesWritten += bufferSize;
        }
        encoder.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
    } finally {
        if (encoder != null) {
            try {
                encoder.close();
            } catch (ActiveMQException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) LargeBodyEncoder(org.apache.activemq.artemis.core.message.LargeBodyEncoder) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 3 with LargeBodyEncoder

use of org.apache.activemq.artemis.core.message.LargeBodyEncoder in project activemq-artemis by apache.

the class ClientProducerImpl method largeMessageSendServer.

/**
 * Used to send serverMessages through the bridges. No need to validate compression here since
 * the message is only compressed at the client
 *
 * @param sendBlocking
 * @param msgI
 * @param handler
 * @throws ActiveMQException
 */
private void largeMessageSendServer(final boolean sendBlocking, final ICoreMessage msgI, final ClientProducerCredits credits, SendAcknowledgementHandler handler) throws ActiveMQException {
    sendInitialLargeMessageHeader(msgI, credits);
    LargeBodyEncoder context = msgI.getBodyEncoder();
    final long bodySize = context.getLargeBodySize();
    context.open();
    try {
        for (long pos = 0; pos < bodySize; ) {
            final boolean lastChunk;
            final int chunkLength = (int) Math.min((bodySize - pos), minLargeMessageSize);
            final ActiveMQBuffer bodyBuffer = ActiveMQBuffers.fixedBuffer(chunkLength);
            context.encode(bodyBuffer, chunkLength);
            pos += chunkLength;
            lastChunk = pos >= bodySize;
            SendAcknowledgementHandler messageHandler = lastChunk ? handler : null;
            int creditsUsed = sessionContext.sendServerLargeMessageChunk(msgI, -1, sendBlocking, lastChunk, bodyBuffer.toByteBuffer().array(), messageHandler);
            credits.acquireCredits(creditsUsed);
        }
    } finally {
        context.close();
    }
}
Also used : LargeBodyEncoder(org.apache.activemq.artemis.core.message.LargeBodyEncoder) SendAcknowledgementHandler(org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 LargeBodyEncoder (org.apache.activemq.artemis.core.message.LargeBodyEncoder)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 SendAcknowledgementHandler (org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler)1 ChannelBufferWrapper (org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper)1 ResetLimitWrappedActiveMQBuffer (org.apache.activemq.artemis.core.buffers.impl.ResetLimitWrappedActiveMQBuffer)1