@Override public int getPersistSize() { ensureDataIsValid(); return DataConstants.SIZE_INT + internalPersistSize(); }
/** * Retrieves the AMQP Footer encoded in the data of this message by decoding a * fresh copy from the encoded message data. Changes to the returned value are not * reflected in the value encoded in the original message. * * @return the Footer that was encoded into this AMQP Message. */ public Footer getFooter() { ensureMessageDataScanned(); ensureDataIsValid(); return scanForMessageSection(Math.max(0, remainingBodyPosition), Footer.class); }
/** * Retrieves the AMQP Section that composes the body of this message by decoding a * fresh copy from the encoded message data. Changes to the returned value are not * reflected in the value encoded in the original message. * * @return the Section that makes up the body of this message. */ public Section getBody() { ensureMessageDataScanned(); ensureDataIsValid(); // We only handle Sections of AmqpSequence, AmqpValue and Data types so we filter on those. // There could also be a Footer and no body so this will prevent a faulty return type in case // of no body or message type we don't handle. return scanForMessageSection(Math.max(0, remainingBodyPosition), AmqpSequence.class, AmqpValue.class, Data.class); }
@Override public int getEncodeSize() { ensureDataIsValid(); // The encoded size will exclude any delivery annotations that are present as we will clip them. return data.remaining() - encodedDeliveryAnnotationsSize + getDeliveryAnnotationsForSendBufferSize(); }
/** * Returns a copy of the DeliveryAnnotations in the message if present or null. Changes to the * returned MessageAnnotations instance do not affect the original Message. * * @return a copy of the {@link MessageAnnotations} present in the message or null if non present. */ public MessageAnnotations getMessageAnnotations() { ensureMessageDataScanned(); ensureDataIsValid(); return scanForMessageSection(messageAnnotationsPosition, MessageAnnotations.class); }
/** * Returns a copy of the {@link ApplicationProperties} present in the message if present or null. * Changes to the returned MessageAnnotations instance do not affect the original Message. * * @return a copy of the {@link ApplicationProperties} present in the message or null if non present. */ public ApplicationProperties getApplicationProperties() { ensureMessageDataScanned(); ensureDataIsValid(); return scanForMessageSection(applicationPropertiesPosition, ApplicationProperties.class); }
/** * Returns a copy of the message Header if one is present, changes to the returned * Header instance do not affect the original Message. * * @return a copy of the Message Header if one exists or null if none present. */ public Header getHeader() { ensureMessageDataScanned(); ensureDataIsValid(); return scanForMessageSection(headerPosition, Header.class); }
/** * Returns a copy of the MessageAnnotations in the message if present or null. Changes to the * returned DeliveryAnnotations instance do not affect the original Message. * * @return a copy of the {@link DeliveryAnnotations} present in the message or null if non present. */ public DeliveryAnnotations getDeliveryAnnotations() { ensureMessageDataScanned(); ensureDataIsValid(); return scanForMessageSection(deliveryAnnotationsPosition, DeliveryAnnotations.class); }
/** * Returns a copy of the message Properties if one is present, changes to the returned * Properties instance do not affect the original Message. * * @return a copy of the Message Properties if one exists or null if none present. */ public Properties getProperties() { ensureMessageDataScanned(); ensureDataIsValid(); return scanForMessageSection(propertiesPosition, Properties.class); }
/** * Would be called by the Artemis Core components to encode the message into * the provided send buffer. Because of how Proton message data handling works * this method is not currently used by the AMQP protocol head and will not be * called for out-bound sends. * * @see #getSendBuffer(int) for the actual method used for message sends. */ @Override public void sendBuffer(ByteBuf buffer, int deliveryCount) { ensureDataIsValid(); NettyWritable writable = new NettyWritable(buffer); writable.put(getSendBuffer(deliveryCount)); }
/** * Gets a ByteBuf from the Message that contains the encoded bytes to be sent on the wire. * <p> * When possible this method will present the bytes to the caller without copying them into * a new buffer copy. If copying is needed a new Netty buffer is created and returned. The * caller should ensure that the reference count on the returned buffer is always decremented * to avoid a leak in the case of a copied buffer being returned. * * @param deliveryCount * The new delivery count for this message. * * @return a Netty ByteBuf containing the encoded bytes of this Message instance. */ public ReadableBuffer getSendBuffer(int deliveryCount) { ensureDataIsValid(); if (deliveryCount > 1) { return createCopyWithNewDeliveryCount(deliveryCount); } else if (deliveryAnnotationsPosition != VALUE_NOT_PRESENT || (deliveryAnnotationsForSendBuffer != null && !deliveryAnnotationsForSendBuffer.getValue().isEmpty())) { return createCopyWithSkippedOrExplicitlySetDeliveryAnnotations(); } else { // Common case message has no delivery annotations, no delivery annotations for the send buffer were set // and this is the first delivery so no re-encoding or section skipping needed. return data.duplicate(); } }
/** * Creates and returns a Proton-J MessageImpl wrapper around the message data. Changes to * the returned Message are not reflected in this message. * * @return a MessageImpl that wraps the AMQP message data in this {@link AMQPMessage} */ public MessageImpl getProtonMessage() { ensureMessageDataScanned(); ensureDataIsValid(); MessageImpl protonMessage = null; if (data != null) { protonMessage = (MessageImpl) Message.Factory.create(); data.rewind(); protonMessage.decode(data.duplicate()); } return protonMessage; }
@Override public org.apache.activemq.artemis.api.core.Message copy() { ensureDataIsValid(); ReadableBuffer view = data.duplicate().rewind(); byte[] newData = new byte[view.remaining()]; // Copy the full message contents with delivery annotations as they will // be trimmed on send and may become useful on the broker at a later time. view.get(newData); AMQPMessage newEncode = new AMQPMessage(this.messageFormat, newData, extraProperties, coreMessageObjectPools); newEncode.setMessageID(this.getMessageID()); return newEncode; }
@Override public void persist(ActiveMQBuffer targetRecord) { ensureDataIsValid(); targetRecord.writeInt(internalPersistSize()); if (data.hasArray()) { targetRecord.writeBytes(data.array(), data.arrayOffset(), data.remaining()); } else { targetRecord.writeBytes(data.byteBuffer()); } }