Package org.apache.mina.core.service

Examples of org.apache.mina.core.service.IoAcceptor


     * is CPU-bound, which should not be in same thread with I/O processor.
     *
     * @link http://mina.apache.org/configuring-thread-model.html
     */
    private void acceptConnections() throws IOException {
        IoAcceptor accepter = setupAcceptor();
        accepter.setHandler(new IOHandler());

        DefaultIoFilterChainBuilder filterChainBuilder = accepter.getFilterChain();
        // Add CPU-bound job first,
        ProtocolCodecFilter protocolFiler = new ProtocolCodecFilter(new ResponseEncoder(), new RequestDecoder());
        filterChainBuilder.addLast("protocol", protocolFiler);
        // and then a thread pool. REVIEWME
        filterChainBuilder.addLast("execFilter", new ExecutorFilter(ExecutorFactory.newCachedThreadPool("execFilter")));

        InetAddress host = InetAddress.getLocalHost();
        InetSocketAddress sockAddr = new InetSocketAddress(host, PORT);
        accepter.bind(sockAddr);

        if(JMX_MONITOR_ENABLED) {
            setupMonitor(accepter);
        }
    }
View Full Code Here


                    }

                });
        connector.setHandler(new IoHandlerAdapter());

        IoAcceptor acceptor = new NioSocketAcceptor();
        acceptor.setHandler(new IoHandlerAdapter());

        InetSocketAddress addr = new InetSocketAddress("localhost",
                AvailablePortFinder.getNextAvailable(20000));

        acceptor.bind(addr);
        ConnectFuture future = connector.connect(addr);
        future.awaitUninterruptibly();
        IoSession session = future.getSession();
        WriteFuture wf = session.write(IoBuffer.allocate(1))
                .awaitUninterruptibly();
        assertNotNull(wf.getException());

        connector.dispose();
        acceptor.dispose();
    }
View Full Code Here

    /**
     * Creates a new instance.
     */
    public DummySession() {
        // Initialize dummy service.
        IoAcceptor acceptor = new AbstractIoAcceptor(
                new AbstractIoSessionConfig() {
                    @Override
                    protected void doSetAll(IoSessionConfig config) {
                        // Do nothing
                    }
                },
                new Executor() {
                    public void execute(Runnable command) {
                        // Do nothing
                    }
                }) {

            @Override
            protected Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses) throws Exception {
                throw new UnsupportedOperationException();
            }

            @Override
            protected void unbind0(List<? extends SocketAddress> localAddresses) throws Exception {
                throw new UnsupportedOperationException();
            }

            public IoSession newSession(SocketAddress remoteAddress, SocketAddress localAddress) {
                throw new UnsupportedOperationException();
            }

            public TransportMetadata getTransportMetadata() {
                return TRANSPORT_METADATA;
            }

            @Override
            protected void dispose0() throws Exception {
            }
        };

        // Set meaningless default values.
        acceptor.setHandler(new IoHandlerAdapter());

        service = acceptor;

        processor = new IoProcessor<AbstractIoSession>() {
            public void add(AbstractIoSession session) {
View Full Code Here

        Cache cache = getDirectoryService().getCacheService().getCache( "changePwdReplayCache" );
        replayCache = new ReplayCacheImpl( cache );

        for ( Transport transport : transports )
        {
            IoAcceptor acceptor = transport.getAcceptor();

            // Disable the disconnection of the clients on unbind
            acceptor.setCloseOnDeactivation( false );

            if ( transport instanceof UdpTransport )
            {
                // Allow the port to be reused even if the socket is in TIME_WAIT state
                ( ( DatagramSessionConfig ) acceptor.getSessionConfig() ).setReuseAddress( true );
            }
            else
            {
                // Allow the port to be reused even if the socket is in TIME_WAIT state
                ( ( SocketAcceptor ) acceptor ).setReuseAddress( true );

                // No Nagle's algorithm
                ( ( SocketAcceptor ) acceptor ).getSessionConfig().setTcpNoDelay( true );
            }

            // Set the handler
            acceptor.setHandler( new ChangePasswordProtocolHandler( this, store ) );

            // Bind
            acceptor.bind();
        }

        LOG.info( "ChangePassword service started." );
        //System.out.println( "ChangePassword service started." );
    }
View Full Code Here

    public void stop()
    {
        for ( Transport transport : getTransports() )
        {
            IoAcceptor acceptor = transport.getAcceptor();

            if ( acceptor != null )
            {
                acceptor.dispose();
            }
        }

        replayCache.clear();
View Full Code Here

        // -------------------------------------------------------------------
        // handle the body of this operation below here
        // -------------------------------------------------------------------

        IoAcceptor acceptor = ( IoAcceptor ) requestor.getIoSession().getService();
        List<IoSession> sessions = new ArrayList<IoSession>(
            acceptor.getManagedSessions().values() );

        // build the graceful disconnect message with replicationContexts
        GracefulDisconnectResponse notice = getGracefulDisconnect( req.getTimeOffline(), req.getDelay() );

        // send (synch) the GracefulDisconnect to each client before unbinding
        sendGracefulDisconnect( sessions, notice, requestor.getIoSession() );

        // wait for the specified delay before we unbind the service
        waitForDelay( req.getDelay() );

        // -------------------------------------------------------------------
        // unbind the server socket for the LDAP service here so no new
        // connections are accepted while we process this shutdown request
        // note that the following must be issued before binding the ldap
        // service in order to prevent client disconnects on service unbind:
        //
        // minaRegistry.getAcceptor( service.getTransportType() )
        //                       .setDisconnectClientsOnUnbind( false );
        // -------------------------------------------------------------------
        // This might not work, either.
        acceptor.unbind( requestor.getIoSession().getServiceAddress() );

        // -------------------------------------------------------------------
        // synchronously send a NoD to clients that are not aware of this resp
        // after sending the NoD the client is disconnected if still connected
        // -------------------------------------------------------------------
View Full Code Here

        replayCache = new ReplayCacheImpl( cache, config.getAllowableClockSkew() );

        // Kerberos can use UDP or TCP
        for ( Transport transport : transports )
        {
            IoAcceptor acceptor = transport.getAcceptor();

            // Now, configure the acceptor
            // Inject the chain
            IoFilterChainBuilder chainBuilder = new DefaultIoFilterChainBuilder();

            if ( transport instanceof TcpTransport )
            {
                // Now, configure the acceptor
                // Disable the disconnection of the clients on unbind
                acceptor.setCloseOnDeactivation( false );

                // No Nagle's algorithm
                ( ( NioSocketAcceptor ) acceptor ).getSessionConfig().setTcpNoDelay( true );

                // Allow the port to be reused even if the socket is in TIME_WAIT state
                ( ( NioSocketAcceptor ) acceptor ).setReuseAddress( true );
            }

            // Inject the codec
            ( ( DefaultIoFilterChainBuilder ) chainBuilder ).addFirst( "codec",
                new ProtocolCodecFilter(
                    KerberosProtocolCodecFactory.getInstance() ) );

            acceptor.setFilterChainBuilder( chainBuilder );

            // Inject the protocol handler
            acceptor.setHandler( new KerberosProtocolHandler( this, store ) );

            // Bind to the configured address
            acceptor.bind();
        }

        LOG.info( "Kerberos service started." );

        if ( changePwdServer != null )
View Full Code Here

    public void stop()
    {
        for ( Transport transport : getTransports() )
        {
            IoAcceptor acceptor = transport.getAcceptor();

            if ( acceptor != null )
            {
                acceptor.dispose();
            }
        }

        if ( replayCache != null )
        {
View Full Code Here

        else
        {
            for ( Transport transport : transports )
            {
                // Get the acceptor
                IoAcceptor acceptor = transport.getAcceptor();

                // Set the handler
                acceptor.setHandler( new DnsProtocolHandler( this, store ) );

                if ( transport instanceof UdpTransport )
                {
                    // Allow the port to be reused even if the socket is in TIME_WAIT state
                    ( ( DatagramSessionConfig ) acceptor.getSessionConfig() ).setReuseAddress( true );
                }
                else
                {
                    // Disable the disconnection of the clients on unbind
                    acceptor.setCloseOnDeactivation( false );

                    // Allow the port to be reused even if the socket is in TIME_WAIT state
                    ( ( NioSocketAcceptor ) acceptor ).setReuseAddress( true );

                    // No Nagle's algorithm
                    ( ( NioSocketAcceptor ) acceptor ).getSessionConfig().setTcpNoDelay( true );
                }

                // Start the listener
                acceptor.bind();
            }
        }

        LOG.info( "DNS service started." );
    }
View Full Code Here

    public void stop()
    {
        for ( Transport transport : getTransports() )
        {
            IoAcceptor acceptor = transport.getAcceptor();

            if ( acceptor != null )
            {
                acceptor.dispose();
            }
        }

        LOG.info( "DNS service stopped." );
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.core.service.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.