Examples of AsyncReadQueueRecord


Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

    protected void addRecord(Connection connection,
            Buffer buffer,
            CompletionHandler completionHandler,
            Interceptor<ReadResult> interceptor) {
       
        final AsyncReadQueueRecord record = AsyncReadQueueRecord.create(
                connection, buffer,
                completionHandler, interceptor);
        ((UDPNIOConnection) connection).getAsyncReadQueue().offer(record);
    }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

    protected void addRecord(Connection connection,
            Buffer buffer,
            CompletionHandler completionHandler,
            Interceptor<ReadResult> interceptor) {
        final AsyncReadQueueRecord record = AsyncReadQueueRecord.create(
                connection, buffer,
                completionHandler, interceptor);
        ((TCPNIOConnection) connection).getAsyncReadQueue().offer(record);
    }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

        final TaskQueue<AsyncReadQueueRecord> connectionQueue =
                ((NIOConnection) connection).getAsyncReadQueue();


        // create and initialize the read queue record
        final AsyncReadQueueRecord queueRecord = AsyncReadQueueRecord.create(
                connection, buffer, completionHandler, interceptor);

        final ReadResult<Buffer, SocketAddress> currentResult =
                queueRecord.getCurrentResult();
       
        final boolean isCurrent = (connectionQueue.reserveSpace(1) == 1);

        try {

            if (isCurrent) { // If AsyncQueue is empty - try to read Buffer here
                doRead(connection, queueRecord);

                final int interceptInstructions = intercept(
                        Reader.READ_EVENT, queueRecord, currentResult);

                if ((interceptInstructions & Interceptor.COMPLETED) != 0
                        || (interceptor == null && queueRecord.isFinished())) { // if direct read is completed

                    // If message was read directly - set next queue element as current
                    final boolean isQueueEmpty =
                        (connectionQueue.releaseSpaceAndNotify(1) == 0);

                    // Notify callback handler
                    queueRecord.notifyComplete();

                    if (!isQueueEmpty) {
                        onReadyToRead(connection);
                    }

                    intercept(COMPLETE_EVENT, queueRecord, null);
                    queueRecord.recycle();
                } else { // If direct read is not finished
                // Create future
                    if ((interceptInstructions & Interceptor.RESET) != 0) {
                        currentResult.setMessage(null);
                        currentResult.setReadSize(0);
                        queueRecord.setMessage(null);
                    }

                    connectionQueue.setCurrentElement(queueRecord);
                   
                    queueRecord.notifyIncomplete();
                    onReadyToRead(connection);

                    intercept(INCOMPLETE_EVENT, queueRecord, null);
                }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

        final TaskQueue<AsyncReadQueueRecord> connectionQueue =
                nioConnection.getAsyncReadQueue();


        boolean done = false;
        AsyncReadQueueRecord queueRecord = null;
       
        try {
            while ((queueRecord =
                    connectionQueue.poll()) != null) {

                final ReadResult currentResult = queueRecord.getCurrentResult();
                doRead(nioConnection, queueRecord);

                final Interceptor<ReadResult> interceptor =
                        queueRecord.getInterceptor();
                // check if message was completely read
                final int interceptInstructions = intercept(
                        Reader.READ_EVENT, queueRecord,
                        currentResult);

                if ((interceptInstructions & Interceptor.COMPLETED) != 0
                        || (interceptor == null && queueRecord.isFinished())) {

                    // Is here a chance that queue becomes empty?
                    // If yes - we need to switch to manual io event processing
                    // mode to *disable READ interest for SameThreadStrategy*,
                    // so we don't get stuck, when other thread tried to add data
                    // to the queue.
                    if (!context.isManualIOEventControl() &&
                            connectionQueue.spaceInBytes() - 1 <= 0) {
                        context.setManualIOEventControl();
                    }

                    done = (connectionQueue.releaseSpaceAndNotify(1) == 0);

                    queueRecord.notifyComplete();

                    intercept(Reader.COMPLETE_EVENT, queueRecord, null);
                    queueRecord.recycle();

                    // check if there is ready element in the queue
                    if (done) {
                        break;
                    }
                } else { // if there is still some data in current message
                    if ((interceptInstructions & Interceptor.RESET) != 0) {
                        currentResult.setMessage(null);
                        currentResult.setReadSize(0);
                        queueRecord.setMessage(null);
                    }

                    connectionQueue.setCurrentElement(queueRecord);
                    queueRecord.notifyIncomplete();
                    intercept(Reader.INCOMPLETE_EVENT, queueRecord, null);

//                    onReadyToRead(nioConnection);
                    return AsyncResult.INCOMPLETE;
                }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

            EOFException error = cachedEOFException;
            if (error == null) {
                error = new EOFException("Connection closed");
                cachedEOFException = error;
            }
            AsyncReadQueueRecord record;
            while ((record = readQueue.poll()) != null) {
                record.notifyFailure(error);
            }
        }
    }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

        final TaskQueue<AsyncReadQueueRecord> connectionQueue =
                ((NIOConnection) connection).getAsyncReadQueue();


        // create and initialize the read queue record
        final AsyncReadQueueRecord queueRecord = AsyncReadQueueRecord.create(
                connection, buffer, completionHandler, interceptor);

        final ReadResult<Buffer, SocketAddress> currentResult =
                queueRecord.getCurrentResult();
       
        final boolean isCurrent = (connectionQueue.reserveSpace(1) == 1);

        try {

            if (isCurrent) { // If AsyncQueue is empty - try to read Buffer here
                doRead(connection, queueRecord);

                final int interceptInstructions = intercept(
                        Reader.READ_EVENT, queueRecord, currentResult);

                if ((interceptInstructions & Interceptor.COMPLETED) != 0
                        || (interceptor == null && queueRecord.isFinished())) { // if direct read is completed

                    // If message was read directly - set next queue element as current
                    final boolean isQueueEmpty =
                        (connectionQueue.releaseSpaceAndNotify(1) == 0);

                    // Notify callback handler
                    queueRecord.notifyComplete();

                    if (!isQueueEmpty) {
                        onReadyToRead(connection);
                    }

                    intercept(COMPLETE_EVENT, queueRecord, null);
                    queueRecord.recycle();
                } else { // If direct read is not finished
                // Create future
                    if ((interceptInstructions & Interceptor.RESET) != 0) {
                        currentResult.setMessage(null);
                        currentResult.setReadSize(0);
                        queueRecord.setMessage(null);
                    }

                    connectionQueue.setCurrentElement(queueRecord);
                   
                    queueRecord.notifyIncomplete();
                    onReadyToRead(connection);

                    intercept(INCOMPLETE_EVENT, queueRecord, null);
                }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

        final TaskQueue<AsyncReadQueueRecord> connectionQueue =
                nioConnection.getAsyncReadQueue();


        boolean done = false;
        AsyncReadQueueRecord queueRecord = null;
       
        try {
            while ((queueRecord =
                    connectionQueue.obtainCurrentElementAndReserve()) != null) {

                final ReadResult currentResult = queueRecord.getCurrentResult();
                doRead(nioConnection, queueRecord);

                final Interceptor<ReadResult> interceptor =
                        queueRecord.getInterceptor();
                // check if message was completely read
                final int interceptInstructions = intercept(
                        Reader.READ_EVENT, queueRecord,
                        currentResult);

                if ((interceptInstructions & Interceptor.COMPLETED) != 0
                        || (interceptor == null && queueRecord.isFinished())) {

                    // Is here a chance that queue becomes empty?
                    // If yes - we need to switch to manual io event processing
                    // mode to *disable READ interest for SameThreadStrategy*,
                    // so we don't get stuck, when other thread tried to add data
                    // to the queue.
                    if (!context.isManualIOEventControl() &&
                            connectionQueue.spaceInBytes() - 1 <= 0) {
                        context.setManualIOEventControl();
                    }

                    done = (connectionQueue.releaseSpaceAndNotify(1) == 0);

                    queueRecord.notifyComplete();

                    intercept(Reader.COMPLETE_EVENT, queueRecord, null);
                    queueRecord.recycle();

                    // check if there is ready element in the queue
                    if (done) {
                        break;
                    }
                } else { // if there is still some data in current message
                    if ((interceptInstructions & Interceptor.RESET) != 0) {
                        currentResult.setMessage(null);
                        currentResult.setReadSize(0);
                        queueRecord.setMessage(null);
                    }

                    connectionQueue.setCurrentElement(queueRecord);
                    queueRecord.notifyIncomplete();
                    intercept(Reader.INCOMPLETE_EVENT, queueRecord, null);

//                    onReadyToRead(nioConnection);
                    return AsyncResult.INCOMPLETE;
                }
View Full Code Here

Examples of org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord

            EOFException error = cachedEOFException;
            if (error == null) {
                error = new EOFException("Connection closed");
                cachedEOFException = error;
            }
            AsyncReadQueueRecord record;
            while ((record = readQueue.obtainCurrentElementAndReserve()) != null) {
                record.notifyFailure(error);
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.