Ejemplo n.º 1
0
  public void start() throws Exception {
    acceptor = new SocketAcceptor();

    // Prepare the configuration
    SocketAcceptorConfig cfg = new SocketAcceptorConfig();
    cfg.setReuseAddress(true);
    Charset charset = Charset.forName("UTF-8");
    cfg.getFilterChain()
        .addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));

    // Bind
    acceptor.bind(new InetSocketAddress(port), new ReverseProtocolHandler(), cfg);
  }
  @Override
  protected void doOpen() throws Throwable {
    // set thread pool.
    acceptor =
        new SocketAcceptor(
            getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS),
            Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true)));
    // config
    SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig();
    cfg.setThreadModel(ThreadModel.MANUAL);
    // set codec.
    acceptor
        .getFilterChain()
        .addLast(
            "codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));

    acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this));
  }