Package org.apache.mina.util

Examples of org.apache.mina.util.Queue


        this.localAddress = this.serviceAddress = remoteSession.remoteAddress;
        this.remoteAddress = remoteSession.localAddress;
        this.handler = entry.getHandler();
        this.filterChain = new VmPipeFilterChain(this);
        this.remoteSession = remoteSession;
        this.pendingDataQueue = new Queue();
    }
View Full Code Here


            }
        }
    }

    private void releaseWriteBuffers(SocketSessionImpl session) {
        Queue writeRequestQueue = session.getWriteRequestQueue();
        WriteRequest req;

        if ((req = (WriteRequest) writeRequestQueue.pop()) != null) {
            ByteBuffer buf = (ByteBuffer) req.getMessage();
            try {
                buf.release();
            } catch (IllegalStateException e) {
                session.getFilterChain().fireExceptionCaught(session, e);
            } finally {
                // The first unwritten empty buffer must be
                // forwarded to the filter chain.
                if (buf.hasRemaining()) {
                    req.getFuture().setWritten(false);
                } else {
                    session.getFilterChain().fireMessageSent(session, req);                   
                }
            }

            // Discard others.
            while ((req = (WriteRequest) writeRequestQueue.pop()) != null) {
                try {
                    ((ByteBuffer) req.getMessage()).release();
                } catch (IllegalStateException e) {
                    session.getFilterChain().fireExceptionCaught(session, e);
                } finally {
View Full Code Here

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

        SocketChannel ch = session.getChannel();
        Queue writeRequestQueue = session.getWriteRequestQueue();

        for (;;) {
            WriteRequest req;

            synchronized (writeRequestQueue) {
                req = (WriteRequest) writeRequestQueue.first();
            }

            if (req == null)
                break;

            ByteBuffer buf = (ByteBuffer) req.getMessage();
            if (buf.remaining() == 0) {
                synchronized (writeRequestQueue) {
                    writeRequestQueue.pop();
                }

                session.increaseWrittenMessages();

                buf.reset();
View Full Code Here

            }

            // The normal is OP_READ and, if there are write requests in the
            // session's write queue, set OP_WRITE to trigger flushing.
            int ops = SelectionKey.OP_READ;
            Queue writeRequestQueue = session.getWriteRequestQueue();
            synchronized (writeRequestQueue) {
                if (!writeRequestQueue.isEmpty()) {
                    ops |= SelectionKey.OP_WRITE;
                }
            }

            // Now mask the preferred ops with the mask of the current session
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

        super(parent);
    }

    protected void doWrite(IoSession session, WriteRequest writeRequest) {
        SocketSessionImpl s = (SocketSessionImpl) session;
        Queue writeRequestQueue = s.getWriteRequestQueue();

        // SocketIoProcessor.doFlush() will reset it after write is finished
        // because the buffer will be passed with messageSent event.
        ((ByteBuffer) writeRequest.getMessage()).mark();
        synchronized (writeRequestQueue) {
            writeRequestQueue.push(writeRequest);
            if (writeRequestQueue.size() == 1
                    && session.getTrafficMask().isWritable()) {
                // Notify SocketIoProcessor only when writeRequestQueue was empty.
                s.getIoProcessor().flush(s);
            }
        }
View Full Code Here

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

        Queue writeRequestQueue = session.getWriteRequestQueue();

        WriteRequest req;
        for( ;; )
        {
            synchronized( writeRequestQueue )
            {
                req = ( WriteRequest ) writeRequestQueue.first();
            }

            if( req == null )
                break;

            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
            if( buf.remaining() == 0 )
            {
                // pop and fire event
                synchronized( writeRequestQueue )
                {
                    writeRequestQueue.pop();
                }

                req.getFuture().setWritten( true );
                session.increaseWrittenWriteRequests();
                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session, buf );
                continue;
            }

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

            int pos = buf.position();
            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( writeRequestQueue )
                {
                    writeRequestQueue.pop();
                }

                session.increaseWrittenBytes( writtenBytes );
                req.getFuture().setWritten( true );
                session.increaseWrittenWriteRequests();
View Full Code Here

                            WriteRequest writeRequest ) throws Exception
    {
        // If we're already processing a stream we need to queue the WriteRequest.
        if( session.getAttribute( CURRENT_STREAM ) != null )
        {
            Queue queue = ( Queue ) session.getAttribute( WRITE_REQUEST_QUEUE );
            if( queue == null )
            {
                queue = new Queue();
                session.setAttribute( WRITE_REQUEST_QUEUE, queue );
            }
            queue.push( writeRequest );
            return;
        }
       
        Object message = writeRequest.getMessage();
       
View Full Code Here

                // End of stream reached.
                session.removeAttribute( CURRENT_STREAM );
                WriteFuture writeFuture = ( WriteFuture ) session.removeAttribute( INITIAL_WRITE_FUTURE );
               
                // Write queued WriteRequests.
                Queue queue = ( Queue ) session.removeAttribute( WRITE_REQUEST_QUEUE );
                if( queue != null )
                {
                    WriteRequest wr = ( WriteRequest ) queue.pop();
                    while( wr != null )
                    {
                        filterWrite( nextFilter, session, wr );
                        wr = ( WriteRequest ) queue.pop();
                    }
                }
               
                writeFuture.setWritten( true );
                nextFilter.messageSent( session, inputStream );
View Full Code Here

        this.lock = lock;
        this.localAddress = localAddress;
        this.remoteAddress = this.serviceAddress = remoteEntry.getAddress();
        this.handler = handler;
        this.filterChain = new VmPipeFilterChain( this );
        this.pendingDataQueue = new Queue();

        this.managedSessions = remoteEntry.getManagedClientSessions();
       
        remoteSession = new VmPipeSessionImpl( manager, this, remoteEntry );
       
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.