Package org.glassfish.grizzly.memory

Examples of org.glassfish.grizzly.memory.CompositeBuffer


    }

    private CompositeBuffer toCompositeInputContentBuffer() {
        if (!inputContentBuffer.isComposite()) {
            final CompositeBuffer compositeBuffer = CompositeBuffer.newBuffer(
                    connection.getTransport().getMemoryManager());

            compositeBuffer.allowBufferDispose(true);
            compositeBuffer.allowInternalBuffersDispose(true);

            compositeBuffer.append(inputContentBuffer);
            inputContentBuffer = compositeBuffer;
        }

        return (CompositeBuffer) inputContentBuffer;
    }
View Full Code Here


        }
    }

    private void checkCompositeBuffer() {
        if (compositeBuffer == null) {
            final CompositeBuffer buffer = CompositeBuffer.newBuffer(
                    memoryManager);
            buffer.allowBufferDispose(true);
            buffer.allowInternalBuffersDispose(true);
            compositeBuffer = buffer;
        }
    }
View Full Code Here

        Buffer clone0(final MemoryManager memoryManager,
                final Buffer originalMessage) {
           
            if (originalMessage.isComposite()) {
                final CompositeBuffer compositeBuffer = (CompositeBuffer) originalMessage;
                compositeBuffer.shrink();

                if (!temporaryWriteBuffer.isDisposed()) {
                    if (compositeBuffer.remaining() == temporaryWriteBuffer.remaining()) {
                        compositeBuffer.allowInternalBuffersDispose(false);
                        compositeBuffer.tryDispose();
                        return temporaryWriteBuffer.cloneContent(memoryManager);
                    } else {
                        compositeBuffer.replace(temporaryWriteBuffer,
                                temporaryWriteBuffer.cloneContent(memoryManager));
                    }
                }
               
                return originalMessage;
View Full Code Here

        }
    }

    private void checkCompositeBuffer() {
        if (compositeBuffer == null) {
            final CompositeBuffer buffer = CompositeBuffer.newBuffer(
                    memoryManager);
            buffer.allowBufferDispose(true);
            buffer.allowInternalBuffersDispose(true);
            compositeBuffer = buffer;
        }
    }
View Full Code Here

            if (temporaryWriteBuffer.isDisposed()) {
                return originalMessage;
            }
           
            if (originalMessage.isComposite()) {
                final CompositeBuffer compositeBuffer = (CompositeBuffer) originalMessage;
                compositeBuffer.shrink();

                if (!temporaryWriteBuffer.isDisposed()) {
                    if (compositeBuffer.remaining() == temporaryWriteBuffer.remaining()) {
                        compositeBuffer.allowInternalBuffersDispose(false);
                        compositeBuffer.tryDispose();
                        return temporaryWriteBuffer.cloneContent();
                    } else {
                        compositeBuffer.replace(temporaryWriteBuffer,
                                temporaryWriteBuffer.cloneContent());
                    }
                }
               
                return originalMessage;
View Full Code Here

    }

    private CompositeBuffer toCompositeInputContentBuffer() {
        if (!inputContentBuffer.isComposite()) {
            final CompositeBuffer compositeBuffer = CompositeBuffer.newBuffer(
                    connection.getTransport().getMemoryManager());

            compositeBuffer.allowBufferDispose(true);
            compositeBuffer.allowInternalBuffersDispose(true);

            compositeBuffer.append(inputContentBuffer);
            inputContentBuffer = compositeBuffer;
        }

        return (CompositeBuffer) inputContentBuffer;
    }
View Full Code Here

    protected GrizzlyFuture<Integer> flush0(Buffer buffer,
            final CompletionHandler<Integer> completionHandler)
            throws IOException {
       
        if (buffer != null) {
            CompositeBuffer savedBuffer = outputBufferAttr.get(attributeStorage);
            if (savedBuffer != null) {
                savedBuffer.append(buffer);
                buffer = savedBuffer;
            }

            do {
                final TransformationResult<Buffer, Buffer> result =
View Full Code Here

    public final class TransformerCondition implements Condition {

        @Override
        public boolean check() {
            try {
                CompositeBuffer savedBuffer = inputBufferAttr.get(attributeStorage);
                Buffer bufferToTransform = savedBuffer;
                Buffer chunkBuffer;

                final boolean hasSavedBuffer = (savedBuffer != null);

                if (underlyingInput.isBuffered()) {
                    chunkBuffer = underlyingInput.takeBuffer();
                } else {
                    int size = underlyingInput.size();
                    chunkBuffer = memoryManager.allocate(size);
                    while (size-- >= 0) {
                        chunkBuffer.put(underlyingInput.read());
                    }
                    chunkBuffer.flip();
                }

                if (hasSavedBuffer) {
                    savedBuffer.append(chunkBuffer);
                } else {
                    bufferToTransform = chunkBuffer;
                }

                while (bufferToTransform.hasRemaining()) {
                    final TransformationResult<Buffer, Buffer> result =
                            transformer.transform(attributeStorage,
                            bufferToTransform);
                    final Status status = result.getStatus();

                    if (status == Status.COMPLETE) {
                        final Buffer outputBuffer = result.getMessage();
                        lock.writeLock().lock();
                        try {
                            append(outputBuffer);

                            if (!isCompletionHandlerRegistered) {
                                // if !isCompletionHandlerRegistered - it means StreamReader has enough data to continue processing
                                return true;
                            }
                        } finally {
                            lock.writeLock().unlock();
                        }
                    } else if (status == Status.INCOMPLETE) {
                        if (!hasSavedBuffer) {
                            if (bufferToTransform.isComposite()) {
                                inputBufferAttr.set(attributeStorage,
                                        (CompositeBuffer) bufferToTransform);
                            } else {
                                savedBuffer = CompositeBuffer.newBuffer(memoryManager);
                                savedBuffer.append(bufferToTransform);
                                inputBufferAttr.set(attributeStorage, savedBuffer);
                            }
                        }

                        return false;
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.memory.CompositeBuffer

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.