コード例 #1
0
ファイル: MessageImpl.java プロジェクト: ryanemerson/hornetq
  /**
   * 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);
  }
コード例 #2
0
ファイル: MessageImpl.java プロジェクト: ryanemerson/hornetq
  private void decode() {
    endOfBodyPosition = buffer.getInt(BUFFER_HEADER_SPACE);

    buffer.readerIndex(endOfBodyPosition + DataConstants.SIZE_INT);

    decodeHeadersAndProperties(buffer);

    endOfMessagePosition = buffer.readerIndex();

    bufferValid = true;
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
ファイル: UnitTestCase.java プロジェクト: igorhvr/hornetq
  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();
  }
コード例 #5
0
ファイル: PacketImpl.java プロジェクト: hellojvm/hornetq
  public void decode(final HornetQBuffer buffer) {
    channelID = buffer.readLong();

    decodeRest(buffer);

    size = buffer.readerIndex();
  }
コード例 #6
0
  @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;
  }
コード例 #7
0
ファイル: MessageImpl.java プロジェクト: ryanemerson/hornetq
  // 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);
  }
コード例 #8
0
ファイル: Page.java プロジェクト: nebnagrom/hornetq
  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;
  }