Package org.apache.mina.util

Examples of org.apache.mina.util.Queue


   
    public void testWriteWhileWriteInProgress() throws Exception
    {
        StreamWriteFilter filter = new StreamWriteFilter();
       
        Queue queue = new Queue();
        InputStream stream = new ByteArrayInputStream( new byte[ 5 ] );
       
        /*
         * Record expectations
         */
        mockSession.reset();
        session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
        mockSession.setReturnValue( stream );
        session.getAttribute( StreamWriteFilter.WRITE_REQUEST_QUEUE );
        mockSession.setReturnValue( queue );
       
        /*
         * Replay.
         */
        mockNextFilter.replay();
        mockSession.replay();

        WriteRequest wr = new WriteRequest( new Object() );
        filter.filterWrite( nextFilter, session, wr );
        assertEquals( 1, queue.size() );
        assertSame( wr, queue.pop() );
       
        /*
         * Verify.
         */
        mockNextFilter.verify();
View Full Code Here


        WriteRequest wrs[] = new WriteRequest[] {
                new WriteRequest( new Object() ),
                new WriteRequest( new Object() ),
                new WriteRequest( new Object() )
        };
        Queue queue = new Queue();
        queue.push( wrs[ 0 ] );
        queue.push( wrs[ 1 ] );
        queue.push( wrs[ 2 ] );
        InputStream stream = new ByteArrayInputStream( new byte[ 0 ] );
       
        /*
         * Record expectations
         */
        mockSession.reset();
       
        session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
        mockSession.setReturnValue( stream );
        session.removeAttribute( StreamWriteFilter.CURRENT_STREAM );
        mockSession.setReturnValue( stream );
        session.removeAttribute( StreamWriteFilter.INITIAL_WRITE_FUTURE );
        mockSession.setReturnValue( new WriteFuture() );
        session.removeAttribute( StreamWriteFilter.WRITE_REQUEST_QUEUE );
        mockSession.setReturnValue( queue );
       
        nextFilter.filterWrite( session, wrs[ 0 ] );
        session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
        mockSession.setReturnValue( null );
        nextFilter.filterWrite( session, wrs[ 1 ] );
        session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
        mockSession.setReturnValue( null );
        nextFilter.filterWrite( session, wrs[ 2 ] );
        session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
        mockSession.setReturnValue( null );
       
        nextFilter.messageSent( session, stream );
       
        /*
         * Replay.
         */
        mockNextFilter.replay();
        mockSession.replay();

        filter.messageSent( nextFilter, session, new Object() );
        assertEquals( 0, queue.size() );
       
        /*
         * Verify.
         */
        mockNextFilter.verify();
View Full Code Here

        this.manager = manager;
        this.serviceListeners = listeners;
        this.ioProcessor = ioProcessor;
        this.filterChain = new SocketFilterChain( this );
        this.ch = ch;
        this.writeRequestQueue = new Queue();
        this.handler = defaultHandler;
        this.remoteAddress = ch.socket().getRemoteSocketAddress();
        this.localAddress = ch.socket().getLocalSocketAddress();
        this.serviceAddress = serviceAddress;
        this.serviceConfig = serviceConfig;
View Full Code Here

    private void flush( DatagramSession session ) throws IOException
    {
        DatagramChannel ch = session.getChannel();

        Queue writeBufferQueue = session.getWriteBufferQueue();
        Queue writeMarkerQueue = session.getWriteMarkerQueue();

        ByteBuffer buf;
        Object marker;
        for( ;; )
        {
            synchronized( writeBufferQueue )
            {
                buf = ( ByteBuffer ) writeBufferQueue.first();
                marker = writeMarkerQueue.first();
            }

            if( buf == null )
                break;

            if( buf.remaining() == 0 )
            {
                // pop and fire event
                synchronized( writeBufferQueue )
                {
                    writeBufferQueue.pop();
                    writeMarkerQueue.pop();
                }

                try
                {
                    buf.release();
                }
                catch( IllegalStateException e )
                {
                    session.getManagerFilterChain().exceptionCaught( session, e );
                }

                session.increaseWrittenWriteRequests();
                session.getManagerFilterChain().dataWritten( session, marker );
                continue;
            }

            SelectionKey key = session.getSelectionKey();
            if( key == null )
            {
                scheduleFlush( session );
                break;
            }
            if( !key.isValid() )
            {
                continue;
            }

            int writtenBytes = ch.write( buf.buf() );

            if( writtenBytes == 0 )
            {
                // Kernel buffer is full
                key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
            }
            else if( writtenBytes > 0 )
            {
                key.interestOps( key.interestOps()
                                 & ( ~SelectionKey.OP_WRITE ) );

                // pop and fire event
                synchronized( writeBufferQueue )
                {
                    writeBufferQueue.pop();
                    writeMarkerQueue.pop();
                }

                session.increaseWrittenBytes( writtenBytes );
                session.increaseWrittenWriteRequests();
                session.getManagerFilterChain().dataWritten( session, marker );
View Full Code Here

    private void flush( DatagramSession session ) throws IOException
    {
        DatagramChannel ch = session.getChannel();

        Queue writeBufferQueue = session.getWriteBufferQueue();
        Queue writeMarkerQueue = session.getWriteMarkerQueue();

        ByteBuffer buf;
        Object marker;
        for( ;; )
        {
            synchronized( writeBufferQueue )
            {
                buf = ( ByteBuffer ) writeBufferQueue.first();
                marker = writeMarkerQueue.first();
            }

            if( buf == null )
                break;

            if( buf.remaining() == 0 )
            {
                // pop and fire event
                synchronized( writeBufferQueue )
                {
                    writeBufferQueue.pop();
                    writeMarkerQueue.pop();
                }

                try
                {
                    buf.release();
                }
                catch( IllegalStateException e )
                {
                    session.getManagerFilterChain().exceptionCaught( session, e );
                }

                session.increaseWrittenWriteRequests();
                session.getManagerFilterChain().dataWritten( session, marker );
                continue;
            }

            SelectionKey key = session.getSelectionKey();
            if( key == null )
            {
                scheduleFlush( session );
                break;
            }
            if( !key.isValid() )
            {
                continue;
            }

            int writtenBytes = ch
                    .send( buf.buf(), session.getRemoteAddress() );

            if( writtenBytes == 0 )
            {
                // Kernel buffer is full
                key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
            }
            else if( writtenBytes > 0 )
            {
                key.interestOps( key.interestOps()
                                 & ( ~SelectionKey.OP_WRITE ) );

                // pop and fire event
                synchronized( writeBufferQueue )
                {
                    writeBufferQueue.pop();
                    writeMarkerQueue.pop();
                }

                session.increaseWrittenBytes( writtenBytes );
                session.increaseWrittenWriteRequests();
                session.getManagerFilterChain().dataWritten( session, marker );
View Full Code Here

    {
        this.managerFilterChain = managerFilterChain;
        this.filterChain = new IoSessionFilterChain( managerFilterChain );
        this.ch = ch;
        this.config = new SocketSessionConfig( this );
        this.writeBufferQueue = new Queue();
        this.writeMarkerQueue = new Queue();
        this.handler = defaultHandler;
        this.remoteAddress = ch.socket().getRemoteSocketAddress();
        this.localAddress = ch.socket().getLocalSocketAddress();
    }
View Full Code Here

        }
    }
   
    private void releaseWriteBuffers( SocketSession session )
    {
        Queue writeBufferQueue = session.getWriteBufferQueue();
        session.getWriteMarkerQueue().clear();
        ByteBuffer buf;
       
        while( ( buf = (ByteBuffer) writeBufferQueue.pop() ) != null )
        {
            try
            {
                buf.release();
            }
View Full Code Here

        SelectionKey key = session.getSelectionKey();
        key.interestOps( key.interestOps() & ( ~SelectionKey.OP_WRITE ) );

        SocketChannel ch = session.getChannel();

        Queue writeBufferQueue = session.getWriteBufferQueue();
        Queue writeMarkerQueue = session.getWriteMarkerQueue();

        ByteBuffer buf;
        Object marker;
        for( ;; )
        {
            synchronized( writeBufferQueue )
            {
                buf = ( ByteBuffer ) writeBufferQueue.first();
                marker = writeMarkerQueue.first();
            }

            if( buf == null )
                break;

            if( buf.remaining() == 0 )
            {
                synchronized( writeBufferQueue )
                {
                    writeBufferQueue.pop();
                    writeMarkerQueue.pop();
                }
                try
                {
                    buf.release();
                }
View Full Code Here

    {
        this.managerFilterChain = managerFilterChain;
        this.filterChain = new IoSessionFilterChain( managerFilterChain );
        this.ch = ch;
        this.config = new DatagramSessionConfig( ch );
        this.writeBufferQueue = new Queue();
        this.writeMarkerQueue = new Queue();
        this.handler = defaultHandler;
        this.remoteAddress = ch.socket().getRemoteSocketAddress();
        this.localAddress = ch.socket().getLocalSocketAddress();
    }
View Full Code Here

                synchronized( decoder )
                {
                    decoder.decode( psession, in, psession.decOut );
                }

                Queue queue = psession.decOut.getMessageQueue();
                synchronized( queue )
                {
                    if( !queue.isEmpty() )
                    {
                        do
                        {
                            managerFilterChain.messageReceived( psession, queue.pop() );
                        }
                        while( !queue.isEmpty() );
                    }
                }
            }
            catch( ProtocolViolationException pve )
            {
View Full Code Here

TOP

Related Classes of org.apache.mina.util.Queue

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.