Пример #1
0
    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
      ChannelBuffer buf;
      PaxosMessage msg;

      buf = (ChannelBuffer) e.getMessage();

      // Read in the message string.
      msg = new PaxosMessage();
      msg.unSerialize(buf.array());

      // Send the message upstream to the server handler.
      Channels.fireMessageReceived(ctx, msg);
    }
Пример #2
0
    @Override
    public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) {
      PaxosMessage msg;
      ChannelBuffer sendBuf;
      byte[] data;

      msg = (PaxosMessage) e.getMessage(); // The original message.

      // Serialize the message.
      data = msg.serialize();
      sendBuf = ChannelBuffers.buffer(data.length);
      sendBuf.writeBytes(data); // Write the actual msg.

      // Send the message upstream.
      Channels.write(ctx, e.getFuture(), sendBuf);
    }