Package org.apache.mina.common

Examples of org.apache.mina.common.ConnectFuture


        cfg.getFilterChain().addLast("logger", new LoggingFilter());

        IoSession session;
        for (;;) {
            try {
                ConnectFuture future = connector.connect(new InetSocketAddress(
                        HOSTNAME, PORT), new ClientSessionHandler(values), cfg);

                future.join();
                session = future.getSession();
                break;
            } catch (RuntimeIOException e) {
                System.err.println("Failed to connect.");
                e.printStackTrace();
                Thread.sleep(5000);
View Full Code Here


    protected abstract ConnectFuture connect( int port, IoHandler handler) throws Exception;
    protected abstract SocketAddress createServerSocketAddress( int port );
   
    public void testSuspendResumeReadWrite() throws Exception
    {
        ConnectFuture future = connect( port, new ClientIoHandler() );
        future.join();
        IoSession session = future.getSession();
       
        // We wait for the sessionCreated() event is fired becayse we cannot guarentee that
        // it is invoked already.
        while( session.getAttribute( "lock" ) == null )
        {
View Full Code Here

    
        IoConnector connector = new VmPipeConnector();
        IoSession[] sessions = new IoSession[ 5 ];
        for( int i = 0; i < sessions.length; i++ )
        {
            ConnectFuture future = connector.connect( addr, new IoHandlerAdapter() );
            future.join();
            sessions[ i ] = future.getSession();
            Assert.assertTrue( sessions[ i ].isConnected() );
        }
       
        // Wait for the server side sessions to be created.
        Thread.sleep( 500 );
View Full Code Here

        EchoConnectorHandler handler = new EchoConnectorHandler();
       
        IoSession session = null;
        if( !useLocalAddress )
        {
            ConnectFuture future = connector.connect(
                    new InetSocketAddress( "localhost", port ),
                    handler );
            future.join();
            session = future.getSession();
        }
        else
        {
            int clientPort = port;
            for( int i = 0; i < 65536; i ++ )
            {
                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
                try
                {
                    ConnectFuture future = connector.connect(
                            new InetSocketAddress( "localhost", port ),
                            new InetSocketAddress( clientPort ),
                            handler );
                    future.join();
                    session = future.getSession();
                    break;
                }
                catch( RuntimeIOException e )
                {
                    // Try again until we succeed to bind.
View Full Code Here

        // Set up server
        acceptor.bind( address, new TennisPlayer() );

        // Connect to the server.
        VmPipeConnector connector = new VmPipeConnector();
        ConnectFuture future = connector.connect( address,
                                                  new TennisPlayer() );
        future.join();
        IoSession session = future.getSession();

        // Send the first ping message
        session.write( new TennisBall( 10 ) );

        // Wait until the match ends.
View Full Code Here

                SSLFilter sslFilter = new SSLFilter( sslContext );
                sslFilter.setUseClientMode( true );
                config.getFilterChain().addLast( "sslFilter", sslFilter );
            }
    
            ConnectFuture future1 = connector.connect( address, handler, config );
            future1.join();
            if( ! future1.isConnected() )
            {
                return false;
            }
            session = future1.getSession();
           
            return true;
        }
        catch ( Exception e)
        {
View Full Code Here

        connector.connect( address, connectorHandler ).addListener(
                new IoFutureListener()
        {
            public void operationComplete( IoFuture f )
            {
                ConnectFuture future = ( ConnectFuture ) f;
                try
                {
                    future.getSession().setAttachment( session );
                    session.setAttachment( future.getSession() );
                    future.getSession().setTrafficMask( TrafficMask.ALL );
                }
                catch( RuntimeIOException e )
                {
                    // Connect failed
                    session.close();
View Full Code Here

        IoSession session;
        for( ;; )
        {
            try
            {
                ConnectFuture future = connector.connect(
                        new InetSocketAddress( HOSTNAME, PORT ),
                        new ClientSessionHandler( values ), cfg );
               
                future.join();
                session = future.getSession();
                break;
            }
            catch( RuntimeIOException e )
            {
                System.err.println( "Failed to connect." );
View Full Code Here

       
        acceptor.bind( new InetSocketAddress( port ), acceptorHandler, config );
       
        try
        {
            ConnectFuture future = connector.connect(
                    new InetSocketAddress( "localhost", port ), connectorHandler, config );
            future.join();
           
            // Write whatever to trigger the acceptor.
            future.getSession().write( ByteBuffer.allocate(1) ).join();

            // Wait until the connection is closed.
            future.getSession().getCloseFuture().join( 3000 );
            Assert.assertTrue( future.getSession().getCloseFuture().isClosed() );
            acceptorHandler.session.getCloseFuture().join( 3000 );
            Assert.assertTrue( acceptorHandler.session.getCloseFuture().isClosed() );
           
            Thread.sleep( 1000 );
View Full Code Here

        expectedConfig.getFilterChain().addLast( "mock", mockFilter );
        acceptor.bind( new InetSocketAddress( port ), mockHandler, expectedConfig );
       
        try
        {
            ConnectFuture future = connector.connect( new InetSocketAddress( "localhost", port ), new IoHandlerAdapter() );
            future.join();
           
            WriteFuture writeFuture = future.getSession().write( ByteBuffer.allocate( 16 ).putInt( 0 ).flip() );
            writeFuture.join();
            Assert.assertTrue( writeFuture.isWritten() );
           
            future.getSession().close();
   
            for( int i = 0; i < 30; i ++ )
            {
                if ( result.length() == 2 )
                {
View Full Code Here

TOP

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

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.