Package org.apache.mina.transport.socket.nio

Examples of org.apache.mina.transport.socket.nio.NioSocketAcceptor


  public void start() {
    logger.info("Starting {}...", this);

    // allow user to specify number of processors to use for thread pool
    if (numProcessors != null) {
      acceptor = new NioSocketAcceptor(numProcessors);
    } else {
      acceptor = new NioSocketAcceptor();
    }
    acceptor.setReuseAddress(true);
    acceptor.getSessionConfig().setReadBufferSize(readBufferSize);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
View Full Code Here


        List<IoFilter> filters = configuration.getFilters();

        address = new InetSocketAddress(configuration.getHost(), configuration.getPort());

        final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
        acceptor = new NioSocketAcceptor(processorCount);

        // acceptor connectorConfig
        configureCodecFactory("Mina2Consumer", acceptor, configuration);
        ((NioSocketAcceptor) acceptor).setReuseAddress(true);
        acceptor.setCloseOnDeactivation(true);
View Full Code Here

    public Mina2ReverserServer(int port) {
        this.port = port;
    }

    public void start() throws Exception {
        acceptor = new NioSocketAcceptor();

        // Prepare the configuration
        ((NioSocketAcceptor) acceptor).setReuseAddress(true);
        Charset charset = Charset.forName("UTF-8");
        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
View Full Code Here

    public static void main(String[] args) throws IOException {
        // Create a class that handles sessions, incoming and outgoing data
        ImageServerIoHandler handler = new ImageServerIoHandler();
       
        // This socket acceptor will handle incoming connections
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
       
        // add an IoFilter .  This class is responsible for converting the incoming and
        // outgoing raw data to ImageRequest and ImageResponse objects
        acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new ImageCodecFactory(false)));
       
        // get a reference to the filter chain from the acceptor
        DefaultIoFilterChainBuilder filterChainBuilder = acceptor.getFilterChain();
       
        // add an ExecutorFilter to the filter chain.  The preferred order is to put the executor filter
        // after any protocol filters due to the fact that protocol codecs are generally CPU-bound
        // which is the same as I/O filters.
        filterChainBuilder.addLast("threadPool", new ExecutorFilter(Executors.newCachedThreadPool()));
       
        // set this NioSocketAcceptor's handler to the ImageServerHandler
        acceptor.setHandler(handler);
       
        // Bind to the specified address.  This kicks off the listening for
        // incoming connections
        acceptor.bind(new InetSocketAddress(PORT));
        System.out.println("Step 2 server is listenig at port " + PORT);
    }
View Full Code Here

        // this step, we will pass in the MBeanServer so that sessions can be
        // registered on the MBeanServer.
        ImageServerIoHandler handler = new ImageServerIoHandler( mBeanServer );
       
        // This socket acceptor will handle incoming connections
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
       
        // create a JMX-aware bean that wraps a MINA IoService object.  In this
        // case, a NioSocketAcceptor. 
        IoServiceMBean acceptorMBean = new IoServiceMBean( acceptor );
       
        // create a JMX ObjectName.  This has to be in a specific format. 
        ObjectName acceptorName = new ObjectName( acceptor.getClass().getPackage().getName() +
            ":type=acceptor,name=" + acceptor.getClass().getSimpleName());
       
        // register the bean on the MBeanServer.  Without this line, no JMX will happen for
        // this acceptor.
        mBeanServer.registerMBean( acceptorMBean, acceptorName );
       
        // add an IoFilter .  This class is responsible for converting the incoming and
        // outgoing raw data to ImageRequest and ImageResponse objects
        ProtocolCodecFilter protocolFilter = new ProtocolCodecFilter(new ImageCodecFactory(false));
       
        // create a JMX-aware bean that wraps a MINA IoFilter object.  In this
        // case, a ProtocolCodecFilter
        IoFilterMBean protocolFilterMBean = new IoFilterMBean( protocolFilter );
       
        // create a JMX ObjectName.
        ObjectName protocolFilterName = new ObjectName( protocolFilter.getClass().getPackage().getName() +
            ":type=protocolfilter,name=" + protocolFilter.getClass().getSimpleName() );
       
        // register the bean on the MBeanServer.  Without this line, no JMX will happen for
        // this filter.
        mBeanServer.registerMBean( protocolFilterMBean, protocolFilterName );
       
        // add the protocolFilter to the acceptor, otherwise no filtering of data will happen
        acceptor.getFilterChain().addLast("protocol", protocolFilter);
       
        // get a reference to the filter chain from the acceptor
        DefaultIoFilterChainBuilder filterChainBuilder = acceptor.getFilterChain();
       
        // add an ExecutorFilter to the filter chain.  The preferred order is to put the executor filter
        // after any protocol filters due to the fact that protocol codecs are generally CPU-bound
        // which is the same as I/O filters.
        filterChainBuilder.addLast("threadPool", new ExecutorFilter(Executors.newCachedThreadPool()));
       
        // set this NioSocketAcceptor's handler to the ImageServerHandler
        acceptor.setHandler(handler);
       
        // Bind to the specified address.  This kicks off the listening for
        // incoming connections
        acceptor.bind(new InetSocketAddress(PORT));
        System.out.println("Step 3 server is listenig at port " + PORT);
    }
View Full Code Here

    /** Set this to true if you want to make the server SSL */
    private static final boolean USE_SSL = false;

    public static void main(String[] args) throws Exception {
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
        DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();

        MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
        chain.addLast("mdc", mdcInjectionFilter);

        // Add SSL filter if SSL is enabled.
        if (USE_SSL) {
            addSSLSupport(chain);
        }

        chain.addLast("codec", new ProtocolCodecFilter(
                new TextLineCodecFactory()));

        addLogger(chain);

        // Bind
        acceptor.setHandler(new ChatProtocolHandler());
        acceptor.bind(new InetSocketAddress(PORT));

        System.out.println("Listening on port " + PORT);
    }
View Full Code Here

       
        // Create a class that handles sessions, incoming and outgoing data
        ImageServerIoHandler handler = new ImageServerIoHandler();
       
        // This socket acceptor will handle incoming connections
        NioSocketAcceptor acceptor = new NioSocketAcceptor();
       
        // add an IoFilter .  This class is responsible for converting the incoming and
        // outgoing raw data to ImageRequest and ImageResponse objects
        acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new ImageCodecFactory(false)));
       
        // set this NioSocketAcceptor's handler to the ImageServerHandler
        acceptor.setHandler(handler);
       
        // Bind to the specified address.  This kicks off the listening for
        // incoming connections
        acceptor.bind(new InetSocketAddress(PORT));
        System.out.println("Step 1 server is listenig at port " + PORT);
    }
View Full Code Here

//  private String lastStatus = FIRST_RUN;
 
  protected int responseCode = 0;
 
  private DebuggerImpl() throws IOException {
    acceptor = new NioSocketAcceptor();
    acceptor.setCloseOnDeactivation(true);
    acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new CodecFactory()));
    acceptor.setHandler(new ProtocolHandler(this));
    acceptor.bind(new InetSocketAddress(eventPort));
  }
View Full Code Here

    private static final int PORT = 9123;
   
    public static void main(String[] args) throws IOException {
       
        IoAcceptor acceptor = new NioSocketAcceptor();
       
        acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
        acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));
  
        acceptor.setHandlernew TimeServerHandler() );

        acceptor.getSessionConfig().setReadBufferSize( 2048 );
        acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
       
        acceptor.bind( new InetSocketAddress(PORT) );
    }
View Full Code Here

*/

public class HaikuValidationServer {
    public static void main(String... args) throws Exception {
        ExecutorService executor = Executors.newCachedThreadPool();
        SocketAcceptor acceptor = new NioSocketAcceptor(Runtime.getRuntime()
                .availableProcessors());

        acceptor.getFilterChain().addLast("executor",
                new ExecutorFilter(executor));
        acceptor.getFilterChain().addLast(
                "to-string",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("US-ASCII"))));
        acceptor.getFilterChain().addLast("to-haiki", new ToHaikuIoFilter());

        acceptor.setHandler(new HaikuValidatorIoHandler());
        acceptor.bind(new InetSocketAddress(42458));
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.transport.socket.nio.NioSocketAcceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.