Package org.apache.mina.common

Examples of org.apache.mina.common.IoAcceptor


    // Set this to false to use object serialization instead of custom codec.
    private static final boolean USE_CUSTOM_CODEC = true;

    public static void main( String[] args ) throws Throwable
    {
        IoAcceptor acceptor = new SocketAcceptor();
       
        // Prepare the service configuration.
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.setReuseAddress( true );
        if( USE_CUSTOM_CODEC )
        {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter( new SumUpProtocolCodecFactory( true ) ) );
        }
        else
        {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );
        }
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );

        acceptor.bind(
                new InetSocketAddress( SERVER_PORT ),
                new ServerSessionHandler( ), cfg );

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


{
    private static final int PORT = 8080;

    public static void main( String[] args ) throws Exception
    {
        IoAcceptor acceptor = new SocketAcceptor();

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

        // Bind
        acceptor.bind(
                new InetSocketAddress( PORT ),
                new ReverseProtocolHandler(), cfg );

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

            System.out.println( Main.class.getName() + " <proxy-port> <server-hostname> <server-port>" );
            return;
        }

        // Create TCP/IP acceptor.
        IoAcceptor acceptor = new SocketAcceptor();
        ( ( SocketAcceptorConfig ) acceptor.getDefaultConfig() ).setReuseAddress( true );
       
        // Create TCP/IP connector.
        IoConnector connector = new SocketConnector();

        // Set connect timeout.
        ( ( IoConnectorConfig ) connector.getDefaultConfig()).setConnectTimeout( 30 );
       
        ClientToProxyIoHandler handler = new ClientToProxyIoHandler(
                new ServerToProxyIoHandler(), connector,
                new InetSocketAddress( args[ 1 ],
                        Integer.parseInt( args[ 2 ] ) ) );
       
        // Start proxy.
        acceptor.bind( new InetSocketAddress( Integer.parseInt( args[ 0 ] ) ), handler );

        System.out.println( "Listening on port " + Integer.parseInt( args[ 0 ] ) );
    }
View Full Code Here

   
    private static final boolean USE_SSL = false;

    public static void main( String[] args ) throws Exception
    {
        IoAcceptor acceptor = new SocketAcceptor();
        IoAcceptorConfig config = new SocketAcceptorConfig();
        DefaultIoFilterChainBuilder chain = config.getFilterChain();

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

        // Bind
        acceptor.bind(
                new InetSocketAddress( PORT ),
                new HttpProtocolHandler(),
                config );

        System.out.println( "Listening on 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
    {
        IoAcceptor acceptor = new SocketAcceptor();
        IoAcceptorConfig config = new SocketAcceptorConfig();
        DefaultIoFilterChainBuilder chain = config.getFilterChain();
       
        // Add SSL filter if SSL is enabled.
        if( USE_SSL )
        {
            addSSLSupport( chain  );
        }
       
        chain.addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory() ) );
       
        addLogger( chain );
       
        // Bind
        acceptor.bind(
                new InetSocketAddress( PORT ),
                new ChatProtocolHandler(),
                config );

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

        IoServiceConfig config1 =
            ( IoServiceConfig ) MockControl.createControl( IoServiceConfig.class ).getMock();
        IoServiceConfig config2 =
            ( IoServiceConfig ) MockControl.createControl( IoServiceConfig.class ).getMock();
        MockControl mockIoAcceptor = MockControl.createControl( IoAcceptor.class );
        IoAcceptor acceptor = ( IoAcceptor ) mockIoAcceptor.getMock();
       
        acceptor.bind( new InetSocketAddress( 80 ), handler1, config1 );
        acceptor.bind( new InetSocketAddress( "192.168.0.1", 22 ), handler2, config2 );
        acceptor.bind( new InetSocketAddress( "10.0.0.1", 9876 ), handler3 );
        acceptor.unbind( new InetSocketAddress( 80 ) );
        acceptor.unbind( new InetSocketAddress( "192.168.0.1", 22 ) );
        acceptor.unbind( new InetSocketAddress( "10.0.0.1", 9876 ) );
       
        mockIoAcceptor.replay();
       
        IoAcceptorFactoryBean factory = new IoAcceptorFactoryBean();
        factory.setTarget( acceptor );
View Full Code Here

        assertEquals( IoAcceptor.class, new IoAcceptorFactoryBean().getObjectType() );
    }
   
    public void testGetObject() throws Exception
    {
        IoAcceptor acceptor =
            ( IoAcceptor ) MockControl.createControl( IoAcceptor.class ).getMock();
        IoAcceptorFactoryBean factory = new IoAcceptorFactoryBean();
        factory.setTarget( acceptor );

        assertEquals( acceptor, factory.getObject() );
View Full Code Here

        }
    }

    public void testStartAcceptor() throws IOException
    {
        IoAcceptor acceptor = null;
        acceptor = new SocketAcceptor();
       
        SocketAcceptorConfig config = (SocketAcceptorConfig) acceptor.getDefaultConfig();
        SocketSessionConfig sc = (SocketSessionConfig) config.getSessionConfig();
        sc.setTcpNoDelay(true);
        sc.setSendBufferSize(32768);
        sc.setReceiveBufferSize(32768);

        config.setThreadModel(ReadWriteThreadModel.getInstance());

        acceptor.bind(new InetSocketAddress(PORT),
                      new TestHandler());
        _logger.info("Bound on port " + PORT);
    }
View Full Code Here

        }
    }

    public void startAcceptor() throws IOException
    {
        IoAcceptor acceptor;
        if (Boolean.getBoolean("multinio"))
        {
            _logger.warn("Using MultiThread NIO");
            acceptor = new org.apache.mina.transport.socket.nio.MultiThreadSocketAcceptor();
        }
        else
        {
            _logger.warn("Using MINA NIO");
            acceptor = new org.apache.mina.transport.socket.nio.SocketAcceptor();
        }


        SocketSessionConfig sc = (SocketSessionConfig) acceptor.getDefaultConfig().getSessionConfig();
        sc.setTcpNoDelay(true);
        sc.setSendBufferSize(32768);
        sc.setReceiveBufferSize(32768);

        ByteBuffer.setAllocator(new SimpleByteBufferAllocator());

        //The old mina style
//        acceptor.setLocalAddress(new InetSocketAddress(_PORT));
//        acceptor.setHandler(new TestHandler());
//        acceptor.bind();
        acceptor.bind(new InetSocketAddress(_PORT), new TestHandler());

        _logger.info("Bound on port " + _PORT + ":" + _logger.isDebugEnabled());
        _logger.debug("debug on");
    }
View Full Code Here

    {
        synchronized (_acceptors)
        {
            for (InetSocketAddress bindAddress : _acceptors.keySet())
            {
                IoAcceptor acceptor = _acceptors.get(bindAddress);
                acceptor.unbind(bindAddress);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.common.IoAcceptor

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.