}
while (pos < minLargeMessageSize);
totalSize += pos;
final SessionSendContinuationMessage chunk;
if (lastPacket)
{
if (!session.isCompressLargeMessages())
{
messageSize.set(totalSize);
}
// This is replacing the last packet by a smaller packet
byte[] buff2 = new byte[pos];
System.arraycopy(buff, 0, buff2, 0, pos);
buff = buff2;
// This is the case where the message is being converted as a regular message
if (!headerSent && session.isCompressLargeMessages() && buff2.length < minLargeMessageSize)
{
msgI.getBodyBuffer().resetReaderIndex();
msgI.getBodyBuffer().resetWriterIndex();
msgI.putLongProperty(Message.HDR_LARGE_BODY_SIZE, deflaterReader.getTotalSize());
msgI.getBodyBuffer().writeBytes(buff, 0, pos);
sendRegularMessage(msgI, sendBlocking, credits, handler);
return;
}
chunk = new SessionSendContinuationMessage(msgI, buff, false, sendBlocking, messageSize.get(), handler);
}
else
{
chunk = new SessionSendContinuationMessage(msgI, buff, true, false, null);
}
if (!headerSent)
{
sendInitialLargeMessageHeader(msgI, credits);
headerSent = true;
}
if (sendBlocking && lastPacket)
{
// When sending it blocking, only the last chunk will be blocking.
channel.sendBlocking(chunk, PacketImpl.NULL_RESPONSE);
}
else
{
channel.send(chunk);
}
try
{
credits.acquireCredits(chunk.getPacketSize());
}
catch (InterruptedException e)
{
throw new HornetQInterruptedException(e);
}