Exemple #1
0
  public synchronized void write(final PagedMessage message) throws Exception {
    if (!file.isOpen()) {

      return;
    }

    ByteBuffer buffer = fileFactory.newBuffer(message.getEncodeSize() + Page.SIZE_RECORD);

    HornetQBuffer wrap = HornetQBuffers.wrappedBuffer(buffer);
    wrap.clear();

    wrap.writeByte(Page.START_BYTE);
    wrap.writeInt(0);
    int startIndex = wrap.writerIndex();
    message.encode(wrap);
    int endIndex = wrap.writerIndex();
    wrap.setInt(1, endIndex - startIndex); // The encoded length
    wrap.writeByte(Page.END_BYTE);

    buffer.rewind();

    file.writeDirect(buffer, false);

    if (pageCache != null) {
      pageCache.addLiveMessage(message);
    }

    numberOfMessages.incrementAndGet();
    size.addAndGet(buffer.limit());

    storageManager.pageWrite(message, pageId);
  }
Exemple #2
0
 public void encodeHeadersAndProperties(final HornetQBuffer buffer) {
   buffer.writeLong(messageID);
   buffer.writeNullableSimpleString(address);
   if (userID == null) {
     buffer.writeByte(DataConstants.NULL);
   } else {
     buffer.writeByte(DataConstants.NOT_NULL);
     buffer.writeBytes(userID.asBytes());
   }
   buffer.writeByte(type);
   buffer.writeBoolean(durable);
   buffer.writeLong(expiration);
   buffer.writeLong(timestamp);
   buffer.writeByte(priority);
   properties.encode(buffer);
 }
Exemple #3
0
  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);
  }
 @Override
 public void encodeRest(final HornetQBuffer buffer) {
   buffer.writeBoolean(synchronizationIsFinished);
   buffer.writeBoolean(allowsAutoFailBack);
   buffer.writeString(nodeID);
   if (synchronizationIsFinished) return;
   buffer.writeByte(dataType.code);
   buffer.writeInt(ids.length);
   for (long id : ids) {
     buffer.writeLong(id);
   }
 }
Exemple #5
0
  public HornetQBuffer encode(final RemotingConnection connection) {
    HornetQBuffer buffer = connection.createBuffer(PacketImpl.INITIAL_PACKET_SIZE);

    // The standard header fields

    buffer.writeInt(0); // The length gets filled in at the end
    buffer.writeByte(type);
    buffer.writeLong(channelID);

    encodeRest(buffer);

    size = buffer.writerIndex();

    // The length doesn't include the actual length byte
    int len = size - DataConstants.SIZE_INT;

    buffer.setInt(0, len);

    return buffer;
  }
Exemple #6
0
  public HornetQBuffer toHornetQBuffer() throws Exception {
    if (buffer == null) {
      if (bytesBody != null) {
        buffer = HornetQBuffers.dynamicBuffer(bytesBody.length + 512);
      } else {
        buffer = HornetQBuffers.dynamicBuffer(512);
      }

      if (isPing()) {
        buffer.writeByte((byte) 10);
        return buffer;
      }

      StringBuffer head = new StringBuffer();
      head.append(command);
      head.append(Stomp.NEWLINE);
      // Output the headers.
      for (Map.Entry<String, String> header : headers.entrySet()) {
        head.append(header.getKey());
        head.append(Stomp.Headers.SEPARATOR);
        head.append(header.getValue());
        head.append(Stomp.NEWLINE);
      }
      // Add a newline to separate the headers from the content.
      head.append(Stomp.NEWLINE);

      buffer.writeBytes(head.toString().getBytes("UTF-8"));
      if (bytesBody != null) {
        buffer.writeBytes(bytesBody);
      }
      buffer.writeBytes(END_OF_FRAME);

      size = buffer.writerIndex();
    }
    return buffer;
  }