/** * Debug Helper!!!! * * <p>I'm leaving this message here without any callers for a reason: During debugs it's important * eventually to identify what's on the bodies, and this method will give you a good idea about * them. Add the message.bodyToString() to the Watch variables on the debugger view and this will * show up like a charm!!! * * @return */ public String bodyToString() { getEndOfBodyPosition(); int readerIndex1 = this.buffer.readerIndex(); buffer.readerIndex(0); byte[] buffer1 = new byte[buffer.writerIndex()]; buffer.readBytes(buffer1); buffer.readerIndex(readerIndex1); byte[] buffer2 = null; if (bodyBuffer != null) { int readerIndex2 = this.bodyBuffer.readerIndex(); bodyBuffer.readerIndex(0); buffer2 = new byte[bodyBuffer.writerIndex() - bodyBuffer.readerIndex()]; bodyBuffer.readBytes(buffer2); bodyBuffer.readerIndex(readerIndex2); } return "ServerMessage@" + Integer.toHexString(System.identityHashCode(this)) + "[" + ",bodyStart=" + getEndOfBodyPosition() + " buffer=" + ByteUtil.bytesToHex(buffer1, 1) + ", bodyBuffer=" + ByteUtil.bytesToHex(buffer2, 1); }
private void decode() { endOfBodyPosition = buffer.getInt(BUFFER_HEADER_SPACE); buffer.readerIndex(endOfBodyPosition + DataConstants.SIZE_INT); decodeHeadersAndProperties(buffer); endOfMessagePosition = buffer.readerIndex(); bufferValid = true; }
@Override public void decodeRest(final HornetQBuffer buffer) { // Buffer comes in after having read standard headers and positioned at Beginning of body part message.decodeFromBuffer(buffer); int ri = buffer.readerIndex(); requiresResponse = buffer.readBoolean(); buffer.readerIndex(ri); }
public static void assertEqualsBuffers( final int size, final HornetQBuffer expected, final HornetQBuffer actual) { // assertEquals(expected.length, actual.length); expected.readerIndex(0); actual.readerIndex(0); for (int i = 0; i < size; i++) { byte b1 = expected.readByte(); byte b2 = actual.readByte(); Assert.assertEquals("byte at index " + i, b1, b2); } expected.resetReaderIndex(); actual.resetReaderIndex(); }
public void decode(final HornetQBuffer buffer) { channelID = buffer.readLong(); decodeRest(buffer); size = buffer.readerIndex(); }
@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.writeBoolean(requiresResponse); 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.readerIndex(0); message.resetCopied(); return buffer; }
// Decode from journal or paging 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 synchronized List<PagedMessage> read(StorageManager storage) throws Exception { if (isDebug) { HornetQServerLogger.LOGGER.debug( "reading page " + this.pageId + " on address = " + storeName); } if (!file.isOpen()) { throw HornetQMessageBundle.BUNDLE.invalidPageIO(); } ArrayList<PagedMessage> messages = new ArrayList<PagedMessage>(); size.set((int) file.size()); // Using direct buffer, as described on https://jira.jboss.org/browse/HORNETQ-467 ByteBuffer directBuffer = storage.allocateDirectBuffer((int) file.size()); try { file.position(0); file.read(directBuffer); directBuffer.rewind(); HornetQBuffer fileBuffer = HornetQBuffers.wrappedBuffer(directBuffer); fileBuffer.writerIndex(fileBuffer.capacity()); while (fileBuffer.readable()) { final int position = fileBuffer.readerIndex(); byte byteRead = fileBuffer.readByte(); if (byteRead == Page.START_BYTE) { if (fileBuffer.readerIndex() + DataConstants.SIZE_INT < fileBuffer.capacity()) { int messageSize = fileBuffer.readInt(); int oldPos = fileBuffer.readerIndex(); if (fileBuffer.readerIndex() + messageSize < fileBuffer.capacity() && fileBuffer.getByte(oldPos + messageSize) == Page.END_BYTE) { PagedMessage msg = new PagedMessageImpl(); msg.decode(fileBuffer); byte b = fileBuffer.readByte(); if (b != Page.END_BYTE) { // Sanity Check: This would only happen if there is a bug on decode or any internal // code, as // this // constraint was already checked throw new IllegalStateException( "Internal error, it wasn't possible to locate END_BYTE " + b); } msg.initMessage(storage); if (isTrace) { HornetQServerLogger.LOGGER.trace( "Reading message " + msg + " on pageId=" + this.pageId + " for address=" + storeName); } messages.add(msg); } else { markFileAsSuspect(file.getFileName(), position, messages.size()); break; } } } else { markFileAsSuspect(file.getFileName(), position, messages.size()); break; } } } finally { storage.freeDirectBuffer(directBuffer); } numberOfMessages.set(messages.size()); return messages; }