Package org.apache.mina.common

Examples of org.apache.mina.common.ConnectFuture


            @Override
            public void messageReceived(IoSession ioSession, Object object) throws Exception {
                super.messageReceived(ioSession, object);    /** TODO */
            }
        };
        ConnectFuture future = connector.connect(address, ioHandler, endpoint.getConfig());
        future.join();
        session = future.getSession();
    }
View Full Code Here


        IoSession session;
        for( ;; )
        {
            try
            {
                ConnectFuture future = connector.connect(
                        new InetSocketAddress( HOSTNAME, PORT ),
                        new ClientSessionHandler( USE_CUSTOM_CODEC, values ) );
               
                future.join();
                session = future.getSession();
                break;
            }
            catch( IOException e )
            {
                System.err.println( "Failed to connect." );
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

        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( IOException e )
                {
                    // Try again until we succeed to bind.
View Full Code Here

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

        // 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

            }
        } );

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

        ConnectFuture future = connector.connect( address, new IoHandlerAdapter() {
            @Override
            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() {
                        @Override
                        public void sessionOpened( IoSession session ) throws Exception {
                            session.write( "re-use c1" );
                        }

                        @Override
                        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();
                                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

        MockHandler connectorHandler = new MockHandler();

        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

        MockHandler connectorHandler = new MockHandler();

        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();

            // Make sure the connection is closed before recycler closes it.
            while (acceptorHandler.session == null) {
                Thread.yield();
            }
            acceptorHandler.session.close();
            Assert.assertTrue(
                    acceptorHandler.session.getCloseFuture().join(3000));
           
            IoSession oldSession = acceptorHandler.session;
           
            // Wait until all events are processed and clear the state.
            long startTime = System.currentTimeMillis();
            while (acceptorHandler.result.length() < 8) {
                Thread.yield();
                if (System.currentTimeMillis() - startTime > 5000) {
                    throw new Exception();
                }
            }
            acceptorHandler.result.setLength(0);
            acceptorHandler.session = null;
           
            // Write whatever to trigger the acceptor again.
            future.getSession().write(ByteBuffer.allocate(1)).join();
           
            // Make sure the connection is closed before recycler closes it.
            while (acceptorHandler.session == null) {
                Thread.yield();
            }
            acceptorHandler.session.close();
            Assert.assertTrue(
                    acceptorHandler.session.getCloseFuture().join(3000));

            future.getSession().close().join();
           
            Assert.assertNotSame(oldSession, acceptorHandler.session);
        } finally {
            acceptor.unbind(new InetSocketAddress(port));
        }
View Full Code Here

                                                     "AsynchronousWriteFilter");
        cfg.getFilterChain().addLast("AsynchronousWriteFilter", asyncWrite);
       
        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

        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());
        protocolHandler.setUseSSL(brokerDetail.useSSL());
        _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

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.