Package org.apache.mina.common

Examples of org.apache.mina.common.ConnectFuture


       
        try
        {
            final StringBuffer buf = new StringBuffer();
            IoConnector connector = createConnector();
            ConnectFuture future = connector.connect(
                    new InetSocketAddress( "localhost", port ),
                    new IoHandlerAdapter()
                    {
                        public void sessionCreated( IoSession session )
                        {
                            buf.append( "1" );
                        }
                       
                        public void sessionOpened( IoSession session )
                        {
                            buf.append( "2" );
                        }
                       
                        public void exceptionCaught( IoSession session, Throwable cause )
                        {
                            buf.append( "X" );
                        }
                    });
           
            future.join();
            buf.append("3");
            future.getSession().close();
            Assert.assertEquals( "123", buf.toString() );
        }
        finally
        {
            acceptor.unbind( new InetSocketAddress( port ) );
View Full Code Here


    {
        int port = AvailablePortFinder.getNextAvailable( 1025 );
        final StringBuffer buf = new StringBuffer();

        IoConnector connector = createConnector();
        ConnectFuture future = connector.connect(
                new InetSocketAddress( "localhost", port ),
                new IoHandlerAdapter()
                {
                    public void sessionCreated( IoSession session )
                    {
                        buf.append( "X" );
                    }
                   
                    public void sessionOpened( IoSession session )
                    {
                        buf.append( "Y" );
                    }
                   
                    public void exceptionCaught( IoSession session, Throwable cause )
                    {
                        buf.append( "Z" );
                    }
                });
       
        future.join();
        buf.append("1");
        try
        {
            future.getSession().close();
            fail();
        }
        catch( RuntimeIOException e )
        {
            // OK.
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

    
        IoConnector connector = new SocketConnector();
        IoSession[] sessions = new IoSession[ 5 ];
        for( int i = 0; i < sessions.length; i++ )
        {
            ConnectFuture future = connector.connect( new InetSocketAddress( "localhost", port ), 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

        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

    
        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

                    }
                });
       
        final StringBuffer actual = new StringBuffer();
       
        ConnectFuture future = connector.connect(
                new VmPipeAddress( 1 ),
                new IoHandlerAdapter() {

                    public void messageReceived( IoSession session, Object message ) throws Exception
                    {
                        actual.append( message );
                    }

                    public void sessionClosed( IoSession session ) throws Exception
                    {
                        actual.append( "C" );
                    }

                    public void sessionOpened( IoSession session ) throws Exception {
                        actual.append( "A" );
                    }
                   
                });

        future.join();
        future.getSession().getCloseFuture().join();
        acceptor.unbindAll();
       
        // sessionClosed() might not be invoked yet
        // even if the connection is closed.
        while( actual.indexOf("C") < 0 )
View Full Code Here

                        actual.append( "A" );
                    }
                   
                });
       
        ConnectFuture future = connector.connect(
                new VmPipeAddress( 1 ),
                new IoHandlerAdapter() {
                    public void sessionOpened( IoSession session ) throws Exception
                    {
                        session.write("B");
                    }
                   
                    public void messageSent( IoSession session, Object message ) throws Exception
                    {
                        session.close();
                    }
                });

        future.join();
        future.getSession().getCloseFuture().join();
        acceptor.unbindAll();
       
        // sessionClosed() might not be invoked yet
        // even if the connection is closed.
        while( actual.indexOf("C") < 0 )
View Full Code Here

        final VmPipeAddress address = new VmPipeAddress(_port);
        _logger.info("Attempting connection to " + address);
        _networkDriver = new MINANetworkDriver(ioConnector, protocolHandler);
        protocolHandler.setNetworkDriver(_networkDriver);
        ConnectFuture future = ioConnector.connect(address, _networkDriver);
        // wait for connection to complete
        future.join();
        // we call getSession which throws an IOException if there has been an error connecting
        future.getSession();
        _networkDriver.setProtocolEngine(protocolHandler);
    }
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating connector to address: " + address + " using connector: " + connector + " timeout: " + timeout + " millis.");
        }
        IoHandler ioHandler = new ResponseHandler(endpoint);
        // connect and wait until the connection is established
        ConnectFuture future = connector.connect(address, ioHandler, endpoint.getConnectorConfig());
        future.join();
        session = future.getSession();
    }
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.