Package org.apache.mina.io

Examples of org.apache.mina.io.IoSession


    }

    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

   
    private void testConnector( IoConnector connector, SocketAddress localAddress ) throws Exception
    {
        EchoConnectorHandler handler = new EchoConnectorHandler();
        ByteBuffer readBuf = handler.readBuf;
        IoSession session = connector.connect(
                new InetSocketAddress( InetAddress.getLocalHost(), port ),
                localAddress,
                handler );
       
        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 < 30; j ++ )
            {
                if( readBuf.position() == ( i + 1 ) * 16 )
                {
                    break;
                }
                Thread.sleep( 10 );
            }
        }
       
        for( int i = 0; i < 30; i++ ) {
            if( readBuf.position() == 160 )
            {
                break;
            }
            else
            {
                Thread.sleep( 100 );
            }
        }

        session.close( true );
       
        Assert.assertEquals( 160, readBuf.position() );
        readBuf.flip();
       
        ByteBuffer expectedBuf = ByteBuffer.allocate( 160 );
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

    }

    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

   
    private void testConnector( IoConnector connector, SocketAddress localAddress ) throws Exception
    {
        EchoConnectorHandler handler = new EchoConnectorHandler();
        ByteBuffer readBuf = handler.readBuf;
        IoSession session = connector.connect(
                new InetSocketAddress( InetAddress.getLocalHost(), port ),
                localAddress,
                handler );
       
        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 < 30; j ++ )
            {
                if( readBuf.position() == ( i + 1 ) * 16 )
                {
                    break;
                }
                Thread.sleep( 10 );
            }
        }
       
        for( int i = 0; i < 30; i++ ) {
            if( readBuf.position() == 160 )
            {
                break;
            }
            else
            {
                Thread.sleep( 100 );
            }
        }

        session.close( true );
       
        Assert.assertEquals( 160, readBuf.position() );
        readBuf.flip();
       
        ByteBuffer expectedBuf = ByteBuffer.allocate( 160 );
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

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.