Exemplo n.º 1
0
    /** Send the message over the channel specified by the message. */
    protected void write(Channel channel, PaxosMessage msg) {
      ChannelFuture future;

      // Send out a command.
      future = channel.write(msg); // Write the contents to the channel.
      future.addListener(this);
    }
Exemplo n.º 2
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();
      }
    }
Exemplo n.º 3
0
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
   e.getCause().printStackTrace();
   Channel ch = e.getChannel();
   ch.close();
 }
Exemplo n.º 4
0
 @Override
 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
   Channel ch = e.getChannel();
   ch.write(e.getMessage());
 }
Exemplo n.º 5
0
 /** Stop listening and close the server channel. */
 public void stopListening() {
   serverChannel.close();
 }