Package org.apache.mina.common

Examples of org.apache.mina.common.IoHandlerAdapter


*/
public class IoAcceptorFactoryBeanTest extends TestCase
{
    public void testBindUnbind() throws Exception
    {
        IoHandler handler1 = new IoHandlerAdapter();
        IoHandler handler2 = new IoHandlerAdapter();
        IoHandler handler3 = new IoHandlerAdapter();
        IoServiceConfig config1 =
            ( IoServiceConfig ) MockControl.createControl( IoServiceConfig.class ).getMock();
        IoServiceConfig config2 =
            ( IoServiceConfig ) MockControl.createControl( IoServiceConfig.class ).getMock();
        MockControl mockIoAcceptor = MockControl.createControl( IoAcceptor.class );
View Full Code Here


        {

            if (!_inVmPipeAddress.containsKey(port))
            {
                _logger.info("Creating InVM Qpid.AMQP listening on port " + port);
                IoHandlerAdapter provider = null;
                try
                {
                    VmPipeAddress pipe = new VmPipeAddress(port);

                    provider = createBrokerInstance(port);
View Full Code Here

        // can't use introspection to get Provider as it is a server class.
        // need to go straight to IoHandlerAdapter but that requries the queues and exchange from the ApplicationRegistry which we can't access.

        // get right constructor and pass in instancec ID - "port"
        IoHandlerAdapter provider;
        try
        {
            Class[] cnstr = {Integer.class};
            Object[] params = {port};
            provider = (IoHandlerAdapter) Class.forName(protocolProviderClass).getConstructor(cnstr).newInstance(params);
View Full Code Here

            // ignore
        }
    }

    public void testAnonymousBind() throws Exception {
        acceptor.bind(null, new IoHandlerAdapter());
        Assert.assertEquals(1, acceptor.getManagedServiceAddresses().size());
        acceptor.unbindAll();
        Thread.sleep(500);
        Assert.assertEquals(0, acceptor.getManagedServiceAddresses().size());

        acceptor.bind(createSocketAddress(0), new IoHandlerAdapter());
        Assert.assertEquals(1, acceptor.getManagedServiceAddresses().size());
        SocketAddress address = (SocketAddress) acceptor
                .getManagedServiceAddresses().iterator().next();
        Assert.assertTrue(getPort(address) != 0);
        acceptor.unbind(address);
View Full Code Here

        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

        synchronized (_inVmPipeAddress)
        {
            if (!_inVmPipeAddress.containsKey(port))
            {
                _logger.info("Creating InVM Qpid.AMQP listening on port " + port);
                IoHandlerAdapter provider = null;
                try
                {
                    VmPipeAddress pipe = new VmPipeAddress(port);

                    provider = createBrokerInstance(port);
View Full Code Here

        // can't use introspection to get Provider as it is a server class.
        // need to go straight to IoHandlerAdapter but that requries the queues and exchange from the ApplicationRegistry which we can't access.

        // get right constructor and pass in instancec ID - "port"
        IoHandlerAdapter provider;
        try
        {
            Class[] cnstr = { Integer.class };
            Object[] params = { port };
            provider = (IoHandlerAdapter) Class.forName(protocolProviderClass).getConstructor(cnstr).newInstance(params);
View Full Code Here

        }
    }

    public void testAnonymousBind() throws Exception
    {
        acceptor.bind( null, new IoHandlerAdapter() );
        Assert.assertEquals( 1, acceptor.getManagedServiceAddresses().size() );
        acceptor.unbindAll();
        Thread.sleep(500);
        Assert.assertEquals( 0, acceptor.getManagedServiceAddresses().size() );
       
        acceptor.bind( createSocketAddress( 0 ), new IoHandlerAdapter() );
        Assert.assertEquals( 1, acceptor.getManagedServiceAddresses().size() );
        SocketAddress address =
                acceptor.getManagedServiceAddresses().iterator().next();
        Assert.assertTrue( getPort( address ) != 0 );
        acceptor.unbind( address );
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 ++ )
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() );
        }
       
View Full Code Here

TOP

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

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.