Package org.apache.mina.common

Examples of org.apache.mina.common.ConnectFuture


        // Set connect timeout.
        ((IoConnectorConfig) connector.getDefaultConfig())
                .setConnectTimeout(30);

        // Start communication.
        ConnectFuture cf = connector.connect(new InetSocketAddress(
                args[0], Integer.parseInt(args[1])), new NetCatProtocolHandler());
       
        // Wait for the connection attempt to be finished.
        cf.join();
        cf.getSession();
    }
View Full Code Here


    }

    public void fireExceptionCaught(IoSession session, Throwable cause) {
        // Notify the related ConnectFuture
        // if the session is created from SocketConnector.
        ConnectFuture future = (ConnectFuture) session
                .removeAttribute(CONNECT_FUTURE);
        if (future == null) {
            Entry head = this.head;
            callNextExceptionCaught(head, session, cause);
        } else {
            // Please note that this place is not the only place that
            // calls ConnectFuture.setException().
            future.setException(cause);
        }
    }
View Full Code Here

            try {
                session.getHandler().sessionOpened(session);
            } finally {
                // Notify the related ConnectFuture
                // if the session is created from SocketConnector.
                ConnectFuture future = (ConnectFuture) session
                        .removeAttribute(CONNECT_FUTURE);
                if (future != null) {
                    future.setSession(session);
                }
            }
        }
View Full Code Here

            }
        } );

        connector.getDefaultConfig().setThreadModel( ThreadModel.MANUAL );

        ConnectFuture future = connector.connect( address, new IoHandlerAdapter() {
            public void messageReceived( IoSession session, Object message ) throws Exception {
                System.out.println( Thread.currentThread().getName() + ": " + message );
               
                if ( "open new".equals( message ) ) {
                    System.out.println( "opening c2 from " + Thread.currentThread().getName() );

                    ConnectFuture c2Future = connector.connect( address, new IoHandlerAdapter() {
                        public void sessionOpened( IoSession session ) throws Exception {
                            session.write( "re-use c1" );
                        }

                        public void messageReceived( IoSession session, Object message ) throws Exception {
                            System.out.println( Thread.currentThread().getName() + ": " + message );

                            if ( "tell me something on c1 now".equals( message ) ) {
                                latch.countDown();
                                ((IoSession) c1.get()).write( "please don't deadlock via c1" );
                            } else {
                                fail( "unexpected message received " + message );
                            }
                        }
                    } );

                    c2Future.join();

                    latch.await();

                    c2Future.getSession().write( "please don't deadlock via c2" );
                } else {
                    fail( "unexpeced message received " + message );
                }
            }
        } );
View Full Code Here

        cfg.setThreadModel(ReadWriteThreadModel.getInstance());            

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

        _logger.info("send-buffer-size = " + scfg.getSendBufferSize());
        scfg.setReceiveBufferSize(Integer.getInteger("amqj.receiveBufferSize", DEFAULT_BUFFER_SIZE));
        _logger.info("recv-buffer-size = " + scfg.getReceiveBufferSize());
        final InetSocketAddress address = new InetSocketAddress(brokerDetail.getHost(), brokerDetail.getPort());
        _logger.info("Attempting connection to " + address);
        ConnectFuture future = ioConnector.connect(address, protocolHandler);

        // wait for connection to complete
        if (future.join(brokerDetail.getTimeout()))
        {
            // we call getSession which throws an IOException if there has been an error connecting
            future.getSession();
        }
        else
        {
            throw new IOException("Timeout waiting for connection.");
        }
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

    }

    //extablish connection without handling redirect
    boolean connect() throws IOException, InterruptedException
    {
        ConnectFuture future = connectImpl();
        // wait for connection to complete
        future.join();
        // we call getSession which throws an IOException if there has been an error connecting
        try
        {
            future.getSession();
        }
        catch (RuntimeIOException e)
        {
            _connectionMonitor.failed(e);
            _logger.error(new LogMessage("Could not connect to {0}: {1}", this, e), e);
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();
            future.getSession().write( ByteBuffer.allocate( 16 ).putInt( 0 ).flip() ).join();
            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

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.