org.apache.mina.transport.socket.nio.SocketAcceptor Java Examples

The following examples show how to use org.apache.mina.transport.socket.nio.SocketAcceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MinaServer.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
    protected void doOpen() throws Throwable {
        // set thread pool. iothreads线程数默认是Runtime.getRuntime().availableProcessors() + 1
        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));
    }
 
Example #2
Source File: MinaServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #3
Source File: MinaServer.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #4
Source File: MinaServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #5
Source File: ImageServer.java    From javastruct with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException
{
  ImageServerIoHandler handler = new ImageServerIoHandler();
  SocketAcceptor acceptor = new SocketAcceptor();
  acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new ImageCodecFactory(false)));
  acceptor.bind(new InetSocketAddress(PORT), handler);
  System.out.println("server is listenig at port " + PORT);
}
 
Example #6
Source File: MinaServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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));
}