ARTEMIS-1816 OpenWire should avoid ByteArrayOutputStream lazy allocation

OpenWireMessageConverter::toAMQMessage on bytes messages is lazy
allocating a write buffer with a default size of 1024 even when
it won't be used to write anything.
It avoid an useless allocation by reducing it to new byte[0].
This commit is contained in:
Francesco Nigro 2018-04-19 17:46:26 +02:00 committed by Timothy Bish
parent aa2f4f7bc5
commit 4d27f2e7d7
1 changed files with 10 additions and 1 deletions

View File

@ -504,6 +504,15 @@ public final class OpenWireMessageConverter {
return md; return md;
} }
private static final class EagerActiveMQBytesMessage extends ActiveMQBytesMessage {
EagerActiveMQBytesMessage(int size) {
this.bytesOut = new org.apache.activemq.util.ByteArrayOutputStream(size);
OutputStream os = bytesOut;
this.dataOut = new DataOutputStream(os);
}
}
private static ActiveMQMessage toAMQMessage(MessageReference reference, private static ActiveMQMessage toAMQMessage(MessageReference reference,
ICoreMessage coreMessage, ICoreMessage coreMessage,
WireFormat marshaller, WireFormat marshaller,
@ -518,7 +527,7 @@ public final class OpenWireMessageConverter {
switch (coreType) { switch (coreType) {
case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE: case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE:
amqMsg = new ActiveMQBytesMessage(); amqMsg = new EagerActiveMQBytesMessage(0);
bytes = toAMQMessageBytesType(buffer, isCompressed); bytes = toAMQMessageBytesType(buffer, isCompressed);
break; break;
case org.apache.activemq.artemis.api.core.Message.MAP_TYPE: case org.apache.activemq.artemis.api.core.Message.MAP_TYPE: