Ejemplo n.º 1
0
  public void writeExternal(IDataOutput output) {
    short flags = 0;

    if (clientIdBytes == null) {
      if (clientId == null) {
        clientIdBytes = null;
      } else {
        clientIdBytes = RandomGUID.toByteArray(clientId);
      }
    }
    if (messageIdBytes == null) {
      if (messageId == null) {
        messageIdBytes = null;
      } else {
        messageIdBytes = RandomGUID.toByteArray(messageId);
      }
    }
    if (body != null) {
      flags = (short) (flags | 0x1);
    }
    if ((clientId != null) && (clientIdBytes == null)) {
      flags = (short) (flags | 0x2);
    }
    if (destination != null) {
      flags = (short) (flags | 0x4);
    }
    if (headers != null) {
      flags = (short) (flags | 0x8);
    }
    if ((messageId != null) && (messageIdBytes == null)) {
      flags = (short) (flags | 0x10);
    }
    if (timestamp != 0L) {
      flags = (short) (flags | 0x20);
    }
    if (timeToLive != 0L) {
      flags = (short) (flags | 0x40);
    }
    if ((clientIdBytes != null) || (messageIdBytes != null)) {
      flags = (short) (flags | 0x80);
    }
    output.writeByte((byte) flags);

    flags = 0;

    if (clientIdBytes != null) {
      flags = (short) (flags | 0x1);
    }
    if (messageIdBytes != null) {
      flags = (short) (flags | 0x2);
    }
    if (flags != 0) {
      output.writeByte((byte) flags);
    }
    if (body != null) {
      output.writeObject(body);
    }
    if ((clientId != null) && (clientIdBytes == null)) {
      output.writeUTF(clientId);
    }
    if (destination != null) {
      output.writeUTF(destination);
    }
    if (headers != null) {
      output.writeObject(headers);
    }
    if ((messageId != null) && (messageIdBytes == null)) {
      output.writeUTF(this.messageId);
    }
    if (timestamp != 0L) {
      output.writeObject(Long.valueOf(timestamp));
    }
    if (this.timeToLive != 0L) {
      output.writeObject(Long.valueOf(timeToLive));
    }
    if (this.clientIdBytes != null) {
      output.writeObject(clientIdBytes);
    }
    if (this.messageIdBytes != null) {
      output.writeObject(messageIdBytes);
    }
  }
Ejemplo n.º 2
0
  @SuppressWarnings("rawtypes")
  public void readExternal(IDataInput input) {
    log.debug("AbstractMessage - Read external");
    short[] flagsArray = readFlags(input);
    for (int i = 0; i < flagsArray.length; ++i) {
      short flags = flagsArray[i];
      short reservedPosition = 0;
      if (i == 0) {
        if ((flags & 0x1) != 0) {
          Object obj = input.readObject();
          log.debug("Body object: {} name: {}", obj, obj.getClass().getName());

          body = obj;
        }
        if ((flags & 0x2) != 0) {
          Object obj = input.readObject();
          log.debug("Client id object: {} name: {}", obj, obj.getClass().getName());

          clientId = ((String) obj);
        }
        if ((flags & 0x4) != 0) {
          Object obj = input.readObject();
          log.debug("Destination object: {} name: {}", obj, obj.getClass().getName());

          destination = ((String) obj);
        }
        if ((flags & 0x8) != 0) {
          Object obj = input.readObject();
          log.debug("Headers object: {} name: {}", obj, obj.getClass().getName());

          headers = ((ObjectMap) obj);
        }
        if ((flags & 0x10) != 0) {
          Object obj = input.readUTF();
          log.debug("Message id object: {} name: {}", obj, obj.getClass().getName());

          messageId = ((String) obj);
        }
        if ((flags & 0x20) != 0) {
          Object obj = input.readObject();
          log.debug("Timestamp object: {} name: {}", obj, obj.getClass().getName());

          timestamp = ((Number) obj).longValue();
        }
        if ((flags & 0x40) != 0) {
          Object obj = input.readObject();
          log.debug("TTL object: {} name: {}", obj, obj.getClass().getName());
          timeToLive = ((Number) obj).longValue();
        }
        reservedPosition = 7;
      } else if (i == 1) {
        if ((flags & 0x1) != 0) {
          Object obj = input.readObject();
          log.debug("Client id (bytes) object: {} name: {}", obj, obj.getClass().getName());
          if (obj instanceof ByteArray) {
            ByteArray ba = (ByteArray) obj;
            clientIdBytes = new byte[ba.length()];
            ba.readBytes(clientIdBytes);
            clientId = RandomGUID.fromByteArray(clientIdBytes);
          }
        }
        if ((flags & 0x2) != 0) {
          Object obj = input.readObject();
          log.debug("Message id (bytes) object: {} name: {}", obj, obj.getClass().getName());
          if (obj instanceof ByteArray) {
            ByteArray ba = (ByteArray) obj;
            messageIdBytes = new byte[ba.length()];
            ba.readBytes(messageIdBytes);
            messageId = RandomGUID.fromByteArray(messageIdBytes);
          }
        }
        reservedPosition = 2;
      }
      if (flags >> reservedPosition == 0) {
        continue;
      }
      for (short j = reservedPosition; j < 6; j = (short) (j + 1)) {
        if ((flags >> j & 0x1) == 0) {
          continue;
        }
        input.readObject();
      }
    }
  }