public synchronized HornetQBuffer getEncodedBuffer() { HornetQBuffer buff = encodeToBuffer(); if (bufferUsed) { HornetQBuffer copied = buff.copy(0, buff.capacity()); copied.setIndex(0, endOfMessagePosition); return copied; } else { buffer.setIndex(0, endOfMessagePosition); bufferUsed = true; return buffer; } }
protected void createBody(final int initialMessageBufferSize) { buffer = HornetQBuffers.dynamicBuffer(initialMessageBufferSize); // There's a bug in netty which means a dynamic buffer won't resize until you write a byte buffer.writeByte((byte)0); int limit = BUFFER_HEADER_SPACE + DataConstants.SIZE_INT; buffer.setIndex(limit, limit); }
public synchronized HornetQBuffer getEncodedBuffer() { HornetQBuffer buff = encodeToBuffer(); if (bufferUsed) { HornetQBuffer copied = buff.copy(0, buff.capacity()); copied.setIndex(0, endOfMessagePosition); return copied; } else { buffer.setIndex(0, endOfMessagePosition); bufferUsed = true; return buffer; } }
public void createBody(final int initialMessageBufferSize) { buffer = HornetQBuffers.dynamicBuffer(initialMessageBufferSize); // There's a bug in netty which means a dynamic buffer won't resize until you write a byte buffer.writeByte((byte) 0); buffer.setIndex(BODY_OFFSET, BODY_OFFSET); }
public void write(final HornetQBuffer bytes, final boolean sync, final IOAsyncTask callback) throws Exception { if (timedBuffer != null) { bytes.setIndex(0, bytes.capacity()); timedBuffer.addBytes(bytes, sync, callback); } else { ByteBuffer buffer = factory.newBuffer(bytes.capacity()); buffer.put(bytes.toByteBuffer().array()); buffer.rewind(); writeDirect(buffer, sync, callback); } }
public void write(final HornetQBuffer bytes, final boolean sync, final IOAsyncTask callback) throws IOException { if (timedBuffer != null) { bytes.setIndex(0, bytes.capacity()); timedBuffer.addBytes(bytes, sync, callback); } else { ByteBuffer buffer = factory.newBuffer(bytes.capacity()); buffer.put(bytes.toByteBuffer().array()); buffer.rewind(); writeDirect(buffer, sync, callback); } }
public void write(final HornetQBuffer bytes, final boolean sync, final IOAsyncTask callback) throws IOException { if (timedBuffer != null) { bytes.setIndex(0, bytes.capacity()); timedBuffer.addBytes(bytes, sync, callback); } else { ByteBuffer buffer = factory.newBuffer(bytes.capacity()); buffer.put(bytes.toByteBuffer().array()); buffer.rewind(); writeDirect(buffer, sync, callback); } }
public synchronized HornetQBuffer getBodyBufferCopy() { // Must copy buffer before sending it HornetQBuffer newBuffer = buffer.copy(0, buffer.capacity()); newBuffer.setIndex(0, getEndOfBodyPosition()); return new ResetLimitWrappedHornetQBuffer(BODY_OFFSET, newBuffer, null); }
private void forceCopy() { // Must copy buffer before sending it buffer = buffer.copy(0, buffer.capacity()); buffer.setIndex(0, getEndOfBodyPosition()); if (bodyBuffer != null) { bodyBuffer.setBuffer(buffer); } bufferUsed = false; }
private void forceCopy() { // Must copy buffer before sending it buffer = buffer.copy(0, buffer.capacity()); buffer.setIndex(0, getEndOfBodyPosition()); if (bodyBuffer != null) { bodyBuffer.setBuffer(buffer); } bufferUsed = false; }
public synchronized HornetQBuffer getBodyBufferCopy() { // Must copy buffer before sending it HornetQBuffer newBuffer = buffer.copy(0, buffer.capacity()); newBuffer.setIndex(0, getEndOfBodyPosition()); return new ResetLimitWrappedHornetQBuffer(BODY_OFFSET, newBuffer, null); }
public void decode(final HornetQBuffer buff) { int start = buff.readerIndex(); endOfBodyPosition = buff.readInt(); endOfMessagePosition = buff.getInt(endOfBodyPosition - BUFFER_HEADER_SPACE + start); int length = endOfMessagePosition - BUFFER_HEADER_SPACE; buffer.setIndex(0, BUFFER_HEADER_SPACE); buffer.writeBytes(buff, start, length); decode(); buff.readerIndex(start + length); }
public void decode(final HornetQBuffer buff) { int start = buff.readerIndex(); endOfBodyPosition = buff.readInt(); endOfMessagePosition = buff.getInt(endOfBodyPosition - BUFFER_HEADER_SPACE + start); int length = endOfMessagePosition - BUFFER_HEADER_SPACE; buffer.setIndex(0, BUFFER_HEADER_SPACE); buffer.writeBytes(buff, start, length); decode(); buff.readerIndex(start + length); }
@Override public void decode(final HornetQBuffer buffer) { channelID = buffer.readLong(); message.decodeFromBuffer(buffer); consumerID = buffer.readLong(); deliveryCount = buffer.readInt(); size = buffer.readerIndex(); // Need to position buffer for reading buffer.setIndex(PACKET_HEADERS_SIZE + DataConstants.SIZE_INT, message.getEndOfBodyPosition()); }
@Override public void decode(final HornetQBuffer buffer) { channelID = buffer.readLong(); message.decodeFromBuffer(buffer); consumerID = buffer.readLong(); deliveryCount = buffer.readInt(); size = buffer.readerIndex(); // Need to position buffer for reading buffer.setIndex(PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT, message.getEndOfBodyPosition()); }
@Override public HornetQBuffer encode(final RemotingConnection connection) { HornetQBuffer buffer = message.getEncodedBuffer(); // Sanity check if (buffer.writerIndex() != message.getEndOfMessagePosition()) { throw new IllegalStateException("Wrong encode position"); } buffer.writeLong(consumerID); buffer.writeInt(deliveryCount); size = buffer.writerIndex(); // Write standard headers int len = size - DataConstants.SIZE_INT; buffer.setInt(0, len); buffer.setByte(DataConstants.SIZE_INT, type); buffer.setLong(DataConstants.SIZE_INT + DataConstants.SIZE_BYTE, channelID); // Position reader for reading by Netty buffer.setIndex(0, size); return buffer; }
@Override public HornetQBuffer encode(final RemotingConnection connection) { HornetQBuffer buffer = message.getEncodedBuffer(); // Sanity check if (buffer.writerIndex() != message.getEndOfMessagePosition()) { throw new IllegalStateException("Wrong encode position"); } buffer.writeLong(consumerID); buffer.writeInt(deliveryCount); size = buffer.writerIndex(); // Write standard headers int len = size - DataConstants.SIZE_INT; buffer.setInt(0, len); buffer.setByte(DataConstants.SIZE_INT, getType()); buffer.setLong(DataConstants.SIZE_INT + DataConstants.SIZE_BYTE, channelID); // Position reader for reading by Netty buffer.setIndex(0, size); return buffer; }
protected MessageImpl(final MessageImpl other, TypedProperties properties) { messageID = other.getMessageID(); userID = other.getUserID(); address = other.getAddress(); type = other.getType(); durable = other.isDurable(); expiration = other.getExpiration(); timestamp = other.getTimestamp(); priority = other.getPriority(); this.properties = new TypedProperties(properties); // This MUST be synchronized using the monitor on the other message to prevent it running concurrently // with getEncodedBuffer(), otherwise can introduce race condition when delivering concurrently to // many subscriptions and bridging to other nodes in a cluster synchronized (other) { bufferValid = other.bufferValid; endOfBodyPosition = other.endOfBodyPosition; endOfMessagePosition = other.endOfMessagePosition; copied = other.copied; if (other.buffer != null) { other.bufferUsed = true; // We need to copy the underlying buffer too, since the different messsages thereafter might have different // properties set on them, making their encoding different buffer = other.buffer.copy(0, other.buffer.writerIndex()); buffer.setIndex(other.buffer.readerIndex(), buffer.capacity()); } } }