Ejemplo n.º 1
0
 private Message buildHeatBeat() {
   Message message = new Message();
   Header h = new Header();
   h.setType(MessageType.HEARTBEAT_REQ.value());
   message.setHeader(h);
   return message;
 }
Ejemplo n.º 2
0
  @Override
  protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    // TODO Auto-generated method stub
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
      return null;
    }

    Message message = new Message();
    Header header = new Header();

    header.setSrcCode(in.readInt());
    header.setLength(in.readInt());
    header.setSessionId(in.readLong());
    header.setType(in.readByte());
    header.setPriority(in.readByte());
    int size = in.readInt();
    if (size > 0) {
      Map<String, Object> attch = new HashMap<String, Object>(size);
      int keySize = 0;
      byte[] keyArray = null;
      String key = null;
      for (int i = 0; i < size; i++) {
        keySize = in.readInt();
        keyArray = new byte[keySize];
        in.readBytes(keyArray);
        key = new String(keyArray, "UTF-8");
        attch.put(key, nettyMarshallingDecoder.decode(ctx, in));
      }
      keyArray = null;
      key = null;
      header.setAttachment(attch);
    }
    return message;
  }