Beispiel #1
0
    /** Start a server that handles the supplied protocol. */
    public boolean startServer(final int port) {
      if (server == null) {
        return false; // Did not initialize yet.
      }

      // Create a new connection & state manager.
      final CommManager manager = new CommManager();

      // Create a new pipeline. This time use an anonymous class.
      server.setPipelineFactory(
          new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
              return Channels.pipeline(
                  new PaxosMessageDecoder(), new PaxosMessageEncoder(), manager);
            }
          });

      try { // Try to bind to the given port.
        serverChannel = server.bind(new InetSocketAddress(port));
        return true;
      } catch (Exception e) {
        e.printStackTrace();
        return false;
      }
    }