Package org.apache.mina.common

Examples of org.apache.mina.common.IoConnector


        List<IoFilter> filters = configuration.getFilters();
        final int processorCount = Runtime.getRuntime().availableProcessors() + 1;

        IoAcceptor acceptor = new SocketAcceptor(processorCount,
                getCamelContext().getExecutorServiceStrategy().newCachedThreadPool(this, "MinaSocketAcceptor"));
        IoConnector connector = new SocketConnector(processorCount,
                getCamelContext().getExecutorServiceStrategy().newCachedThreadPool(this, "MinaSocketConnector"));
        SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());

        // connector config
        SocketConnectorConfig connectorConfig = new SocketConnectorConfig();
View Full Code Here


        boolean transferExchange = configuration.isTransferExchange();
        boolean sync = configuration.isSync();
        List<IoFilter> filters = configuration.getFilters();

        IoAcceptor acceptor = new DatagramAcceptor(getCamelContext().getExecutorServiceStrategy().newCachedThreadPool(this, "MinaDatagramAcceptor"));
        IoConnector connector = new DatagramConnector(getCamelContext().getExecutorServiceStrategy().newCachedThreadPool(this, "MinaDatagramConnector"));
        SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());

        if (transferExchange) {
            throw new IllegalArgumentException("transferExchange=true is not supported for datagram protocol");
        }
View Full Code Here

* @version $Rev: 575603 $, $Date: 2007-09-14 19:04:45 +0900 (금, 14  92007) $
*/
public class VmPipeSessionCrossCommunicationTest extends TestCase {
    public void testOneSessionTalkingBackAndForthDoesNotDeadlock() throws Exception {
        final VmPipeAddress address = new VmPipeAddress( 1 );
        final IoConnector connector = new VmPipeConnector();
        final AtomicReference c1 = new AtomicReference();
        final CountDownLatch latch = new CountDownLatch( 1 );
        final CountDownLatch messageCount = new CountDownLatch( 2 );
        IoAcceptor acceptor = new VmPipeAcceptor();

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

                if ( "start".equals( message ) ) {
                    session.write( "open new" );
                } else if ( "re-use c1".equals( message ) ) {
                    session.write( "tell me something on c1 now" );
                } else if ( ( (String) message ).startsWith( "please don't deadlock" ) ) {
                    messageCount.countDown();
                } else {
                    fail( "unexpected message received " + message );
                }
            }
        } );

        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 {
View Full Code Here

    public void testConnectorActivation() throws Exception {
        IoServiceListenerSupport support = new IoServiceListenerSupport();

        MockControl connectorControl = MockControl
                .createStrictControl(IoConnector.class);
        IoConnector connector = (IoConnector) connectorControl.getMock();

        final TestSession session = new TestSession(connector, ADDRESS);

        MockControl chainControl = MockControl
                .createStrictControl(IoFilterChain.class);
View Full Code Here

        {
            _logger.info("Using SimpleByteBufferAllocator");
            ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
        }

        final IoConnector ioConnector = _socketConnectorFactory.newSocketConnector();
        SocketConnectorConfig cfg = (SocketConnectorConfig) ioConnector.getDefaultConfig();

        // if we do not use our own thread model we get the MINA default which is to use
        // its own leader-follower model
        boolean readWriteThreading = Boolean.getBoolean("amqj.shared_read_write_pool");
        if (readWriteThreading)
        {
            cfg.setThreadModel(ReadWriteThreadModel.getInstance());
        }

        SocketSessionConfig scfg = (SocketSessionConfig) cfg.getSessionConfig();
        scfg.setTcpNoDelay("true".equalsIgnoreCase(System.getProperty("amqj.tcpNoDelay", "true")));
        scfg.setSendBufferSize(Integer.getInteger("amqj.sendBufferSize", DEFAULT_BUFFER_SIZE));
        _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
View Full Code Here

    {
        IoAcceptor acceptor = new SocketAcceptor();
        ( ( SocketAcceptorConfig ) acceptor.getDefaultConfig() ).setReuseAddress( true );
        SocketAddress address = new InetSocketAddress( "localhost", AvailablePortFinder.getNextAvailable() );

        IoConnector connector = new SocketConnector();

        FixedRandomInputStream stream = new FixedRandomInputStream( 4 * 1024 * 1024 );

        SenderHandler sender = new SenderHandler( stream );
        ReceiverHandler receiver = new ReceiverHandler( stream.size );

        acceptor.bind( address, sender );

        synchronized( sender.lock )
        {
            synchronized( receiver.lock )
            {
                connector.connect( address, receiver );

                sender.lock.wait();
                receiver.lock.wait();
            }
        }
View Full Code Here

    public void testConnectorActivation() throws Exception
    {
        IoServiceListenerSupport support = new IoServiceListenerSupport();

        MockControl connectorControl = MockControl.createStrictControl( IoConnector.class );
        IoConnector connector = ( IoConnector ) connectorControl.getMock();

        final TestSession session = new TestSession( connector, ADDRESS );

        MockControl chainControl = MockControl.createStrictControl( IoFilterChain.class );
        IoFilterChain chain = ( IoFilterChain ) chainControl.getMock();
View Full Code Here

    }

    protected ConnectFuture connect( int port, IoHandler handler )
            throws Exception
    {
        IoConnector connector = new DatagramConnector();
        SocketAddress addr = new InetSocketAddress( "localhost", port );
        return connector.connect( addr, handler );
    }
View Full Code Here

        // TODO: This test is almost identical to the test with the same name in VmPipeBindTest
        bind( false );
       
        SocketAddress addr = createSocketAddress( port );
    
        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() );
        }
       
View Full Code Here

    }

    protected ConnectFuture connect( int port, IoHandler handler )
            throws Exception
    {
        IoConnector connector = new SocketConnector();
        SocketAddress addr = new InetSocketAddress( "localhost", port );
        return connector.connect( addr, handler );
    }
View Full Code Here

TOP

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

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.