@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));
  }
 public Channel getChannel(InetSocketAddress remoteAddress) {
   Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
   for (IoSession session : sessions) {
     if (session.getRemoteAddress().equals(remoteAddress)) {
       return MinaChannel.getOrAddChannel(session, getUrl(), this);
     }
   }
   return null;
 }
 public Collection<Channel> getChannels() {
   Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
   Collection<Channel> channels = new HashSet<Channel>();
   for (IoSession session : sessions) {
     if (session.isConnected()) {
       channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this));
     }
   }
   return channels;
 }
 @Override
 protected void doClose() throws Throwable {
   try {
     if (acceptor != null) {
       acceptor.unbind(getBindAddress());
     }
   } catch (Throwable e) {
     logger.warn(e.getMessage(), e);
   }
 }
 public boolean isBound() {
   return acceptor.isManaged(getBindAddress());
 }