Package org.apache.mina.io

Examples of org.apache.mina.io.IoSession


    protected void processEvent( Object nextFilter0, Session session0,
                                 EventType type, Object data )
    {
        NextFilter nextFilter = ( NextFilter ) nextFilter0;
        IoSession session = ( IoSession ) session0;
        if( type == EventType.READ )
        {
            ByteBuffer buf = ( ByteBuffer ) data;
            nextFilter.dataRead( session, buf );
            buf.release();
View Full Code Here


    private void testConnector( IoConnector connector, boolean useLocalAddress ) throws Exception
    {
        EchoConnectorHandler handler = new EchoConnectorHandler();
        ByteBuffer readBuf = handler.readBuf;

        IoSession session = null;
        if( !useLocalAddress )
        {
            session = connector.connect(
                    new InetSocketAddress( InetAddress.getLocalHost(), port ),
                    handler );
        }
        else
        {
            int clientPort = port;
            for( int i = 0; i < 65536; i ++ )
            {
                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
                try
                {
                    session = connector.connect(
                            new InetSocketAddress( InetAddress.getLocalHost(), port ),
                            new InetSocketAddress( clientPort ),
                            handler );
                    break;
                }
                catch( BindException e )
                {
                    // Try again until we succeed to bind.
                }
            }

            if( session == null )
            {
                Assert.fail( "Failed to find out an appropriate local address." );
            }
        }
       
        for( int i = 0; i < 10; i ++ )
        {
            ByteBuffer buf = ByteBuffer.allocate( 16 );
            buf.limit( 16 );
            fillWriteBuffer( buf, i );
            buf.flip();

            Object marker;
            if( ( i & 1 ) == 0 )
            {
                marker = new Integer( i );
            }
            else
            {
                marker = null;
            }

            session.write( buf, marker );

            // This will align message arrival order in UDP
            for( int j = 0; j < 100; j ++ )
            {
                if( readBuf.position() == ( i + 1 ) * 16 )
                {
                    break;
                }
                Thread.sleep( 10 );
            }
        }
       
        for( int i = 0; i < 100; i++ ) {
            if( readBuf.position() == 160 )
            {
                break;
            }
            else
            {
                Thread.sleep( 10 );
            }
        }

        session.close( true );
       
        Assert.assertEquals( 160, readBuf.position() );
        readBuf.flip();
       
        ByteBuffer expectedBuf = ByteBuffer.allocate( 160 );
View Full Code Here

    }

    public ProtocolSession connect( SocketAddress address,
                                    ProtocolProvider provider ) throws IOException
    {
        IoSession session = connector.connect(
                address, adapter.adapt( provider ) );
        return adapter.toProtocolSession( session );
    }
View Full Code Here

    }

    public ProtocolSession connect( SocketAddress address, SocketAddress localAddress,
                                    ProtocolProvider provider ) throws IOException
    {
        IoSession session = connector.connect(
                address, localAddress, adapter.adapt( provider ) );
        return adapter.toProtocolSession( session );
    }
View Full Code Here

    }

    public ProtocolSession connect( SocketAddress address, int timeout,
                                    ProtocolProvider provider ) throws IOException
    {
        IoSession session = connector.connect(
                address, timeout, adapter.adapt( provider ) );
        return adapter.toProtocolSession( session );
    }
View Full Code Here

    }

    public ProtocolSession connect( SocketAddress address, SocketAddress localAddress,
                                    int timeout, ProtocolProvider provider ) throws IOException
    {
        IoSession session = connector.connect(
                address, localAddress, timeout, adapter.adapt( provider ) );
        return adapter.toProtocolSession( session );
    }
View Full Code Here

    protected void processEvent( Object nextFilter0, Session session0,
                                 EventType type, Object data )
    {
        NextFilter nextFilter = ( NextFilter ) nextFilter0;
        IoSession session = ( IoSession ) session0;
        if( type == EventType.READ )
        {
            ByteBuffer buf = ( ByteBuffer ) data;
            nextFilter.dataRead( session, buf );
            buf.release();
View Full Code Here

    private void testConnector( IoConnector connector, boolean useLocalAddress ) throws Exception
    {
        EchoConnectorHandler handler = new EchoConnectorHandler();
        ByteBuffer readBuf = handler.readBuf;

        IoSession session = null;
        if( !useLocalAddress )
        {
            session = connector.connect(
                    new InetSocketAddress( "localhost", port ),
                    handler );
        }
        else
        {
            int clientPort = port;
            for( int i = 0; i < 65536; i ++ )
            {
                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
                try
                {
                    session = connector.connect(
                            new InetSocketAddress( "localhost", port ),
                            new InetSocketAddress( clientPort ),
                            handler );
                    break;
                }
                catch( BindException e )
                {
                    // Try again until we succeed to bind.
                }
            }

            if( session == null )
            {
                Assert.fail( "Failed to find out an appropriate local address." );
            }
        }
       
        for( int i = 0; i < 10; i ++ )
        {
            ByteBuffer buf = ByteBuffer.allocate( 16 );
            buf.limit( 16 );
            fillWriteBuffer( buf, i );
            buf.flip();

            Object marker;
            if( ( i & 1 ) == 0 )
            {
                marker = new Integer( i );
            }
            else
            {
                marker = null;
            }

            session.write( buf, marker );

            // This will align message arrival order in UDP
            for( int j = 0; j < 100; j ++ )
            {
                if( readBuf.position() == ( i + 1 ) * 16 )
                {
                    break;
                }
                Thread.sleep( 10 );
            }
        }
       
        for( int i = 0; i < 100; i++ ) {
            if( readBuf.position() == 160 )
            {
                break;
            }
            else
            {
                Thread.sleep( 10 );
            }
        }

        session.close( true );
       
        Assert.assertEquals( 160, readBuf.position() );
        readBuf.flip();
       
        ByteBuffer expectedBuf = ByteBuffer.allocate( 160 );
View Full Code Here

    }

    public ProtocolSession connect( SocketAddress address,
                                    ProtocolProvider provider ) throws IOException
    {
        IoSession session = connector.connect(
                address, adapter.adapt( provider ) );
        return adapter.toProtocolSession( session );
    }
View Full Code Here

    }

    public ProtocolSession connect( SocketAddress address, SocketAddress localAddress,
                                    ProtocolProvider provider ) throws IOException
    {
        IoSession session = connector.connect(
                address, localAddress, adapter.adapt( provider ) );
        return adapter.toProtocolSession( session );
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.io.IoSession

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.