Ejemplo n.º 1
0
    /** The server has received a message. */
    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
      PaxosMessage msg;

      // Get our consensus message and hand it back to the parent.
      msg = (PaxosMessage) e.getMessage();
      if (msg != null) {
        // Try to get remote connection information.
        // This is used if we need to update the network
        // information later.
        Channel channel = ctx.getChannel();
        InetSocketAddress remote = (InetSocketAddress) channel.getRemoteAddress();

        // Update the message with the remote address.
        msg.setRemoteAddress(remote.getAddress().getHostAddress());

        // Update the client.
        updateCallback(msg);

        // Close the channel so that we don't leak descriptors.
        channel.close();
      }
    }
Ejemplo n.º 2
0
 /** Indicates when the channel is available for writing. */
 @Override
 public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
   if (msg != null) {
     write(ctx.getChannel(), msg);
   }
 }