コード例 #1
0
  @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));
  }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 @Override
 protected void doClose() throws Throwable {
   try {
     if (acceptor != null) {
       acceptor.unbind(getBindAddress());
     }
   } catch (Throwable e) {
     logger.warn(e.getMessage(), e);
   }
 }
コード例 #5
0
 public boolean isBound() {
   return acceptor.isManaged(getBindAddress());
 }