Package org.glassfish.grizzly.memory

Examples of org.glassfish.grizzly.memory.MemoryManager


        final AtomicInteger counter = new AtomicInteger();
       
        return new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                final MemoryManager mm = config.getMemoryManager();
                final ThreadLocalPoolProvider threadLocalPoolProvider;
               
                if (mm instanceof ThreadLocalPoolProvider) {
                    threadLocalPoolProvider = (ThreadLocalPoolProvider) mm;
                } else {
View Full Code Here


    }

    public static Buffer allocateAndReadBuffer(final TCPNIOConnection connection)
            throws IOException {
       
        final MemoryManager memoryManager =
                connection.getTransport().getMemoryManager();
       
        int read;
        Throwable error = null;
        Buffer buffer = null;
       
        try {
            final int receiveBufferSize =
                    Math.min(TCPNIOTransport.MAX_RECEIVE_BUFFER_SIZE,
                            connection.getReadBufferSize());
       
            if (!memoryManager.willAllocateDirect(receiveBufferSize)) {
                final DirectByteBufferRecord ioRecord =
                        DirectByteBufferRecord.get();
                final ByteBuffer directByteBuffer =
                        ioRecord.allocate(receiveBufferSize);
               
                try {
                    read = readSimpleByteBuffer(connection, directByteBuffer);
                    if (read > 0) {
                        directByteBuffer.flip();
                        buffer = memoryManager.allocate(read);
                        buffer.put(directByteBuffer);
                    }
                } finally {
                    ioRecord.release();
                }
            } else {
                buffer = memoryManager.allocateAtLeast(receiveBufferSize);
                read = readBuffer(connection, buffer);
            }
        } catch (Throwable e) {
            error = e;
            read = -1;
View Full Code Here

        return new SslResult(output, sslEngineResult);
    }

    Buffer wrapAll(final Buffer input,
            final Allocator allocator) throws SSLException {
        final MemoryManager memoryManager =
                connection.getTransport().getMemoryManager();
       
        final ByteBufferArray bba =
                input.toByteBufferArray(inputByteBufferArray);
        final ByteBuffer[] inputArray = bba.getArray();
View Full Code Here

    }


    @Override
    protected TransformationResult<Buffer, Buffer> transformImpl(AttributeStorage storage, Buffer input) throws TransformationException {
        final MemoryManager memoryManager = obtainMemoryManager(storage);
        final LZMAOutputState state = (LZMAOutputState) obtainStateObject(storage);

        if (!state.isInitialized()) {
            initializeOutput(state);
        }
View Full Code Here

        return input.hasRemaining();
    }

    @Override
    protected TransformationResult<Buffer, Buffer> transformImpl(AttributeStorage storage, Buffer input) throws TransformationException {
        final MemoryManager memoryManager = obtainMemoryManager(storage);

        final LZMAInputState state = (LZMAInputState) obtainStateObject(storage);
        state.setMemoryManager(memoryManager);

        Buffer decodedBuffer = null;
View Full Code Here

    }

    @Override
    protected TransformationResult<Buffer, Buffer> transformImpl(
            AttributeStorage storage, Buffer input) throws TransformationException {
        final MemoryManager memoryManager = obtainMemoryManager(storage);

        final GZipInputState state = (GZipInputState) obtainStateObject(storage);

        if (!state.isInitialized()) {
            if (!initializeInput(input, state)) {
View Full Code Here

     */
    @Override
    protected TransformationResult<Buffer, Buffer> transformImpl(
            AttributeStorage storage, Buffer input) throws TransformationException {

        final MemoryManager memoryManager = obtainMemoryManager(storage);
        final GZipOutputState state = (GZipOutputState) obtainStateObject(storage);

        if (!state.isInitialized) {
            state.initialize();
        }
View Full Code Here

     * in succession to the same output stream.
     *
     * @return {@link Buffer} with the last GZIP data to be sent.
     */
    public Buffer finish(AttributeStorage storage) {
        final MemoryManager memoryManager = obtainMemoryManager(storage);
        final GZipOutputState state = (GZipOutputState) obtainStateObject(storage);

        Buffer resultBuffer = null;

        if (state.isInitialized) {
            final Deflater deflater = state.deflater;
            if (!deflater.finished()) {
                deflater.finish();

                while (!deflater.finished()) {
                    resultBuffer = Buffers.appendBuffers(memoryManager,
                            resultBuffer,
                            deflate(deflater, memoryManager));
                }

                // Put GZIP header if needed
                if (!state.isHeaderWritten) {
                    state.isHeaderWritten = true;

                    resultBuffer = Buffers.appendBuffers(memoryManager,
                            getHeader(), resultBuffer);
                }
               
                // Put GZIP member trailer
                final Buffer trailer = memoryManager.allocate(TRAILER_SIZE);
                final CRC32 crc32 = state.crc32;
                putUInt(trailer, (int) crc32.getValue());
                putUInt(trailer, deflater.getTotalIn());
                trailer.flip();

View Full Code Here

            }
        }

        final Connection connection = ctx.getConnection();
       
        final MemoryManager memoryManager = connection.getTransport().getMemoryManager();
        final HttpHeader httpHeader = httpContent.getHttpHeader();
        final ContentParsingState parsingState =
                ((HttpPacketParsing) httpHeader).getContentParsingState();
        final List<ContentEncoding> encodings = httpHeader.getContentEncodings(true);
View Full Code Here

    protected final Buffer encodeHttpPacket(final FilterChainContext ctx,
            final HttpHeader httpHeader, final HttpContent httpContent,
            final boolean isContentAlreadyEncoded) {
        final Connection connection = ctx.getConnection();
        final MemoryManager memoryManager = ctx.getMemoryManager();

        Buffer encodedBuffer = null;
       
        if (!httpHeader.isCommitted()) {
            if (!httpHeader.isRequest()) {
                final HttpResponsePacket response = (HttpResponsePacket) httpHeader;
                if (response.isAcknowledgement()) {
                    encodedBuffer = memoryManager.allocate(128);
                    encodedBuffer = encodeInitialLine(httpHeader,
                                                      encodedBuffer,
                                                      memoryManager);
                    encodedBuffer = put(memoryManager,
                                        encodedBuffer,
                                        CRLF_BYTES);
                    encodedBuffer = put(memoryManager,
                                        encodedBuffer,
                                        CRLF_BYTES);
                    onInitialLineEncoded(httpHeader, ctx);
                    encodedBuffer.trim();
                    encodedBuffer.allowBufferDispose(true);

                    HttpProbeNotifier.notifyHeaderSerialize(this, connection,
                            httpHeader, encodedBuffer);

                    response.acknowledged();
                    return encodedBuffer; // DO NOT MARK COMMITTED
                }
            }
            setContentEncodingsOnSerializing(httpHeader);
            setTransferEncodingOnSerializing(ctx,
                                             httpHeader,
                                             httpContent);

            encodedBuffer = memoryManager.allocateAtLeast(2048);

            encodedBuffer = encodeInitialLine(httpHeader, encodedBuffer, memoryManager);
            encodedBuffer = put(memoryManager, encodedBuffer, CRLF_BYTES);
            onInitialLineEncoded(httpHeader, ctx);
View Full Code Here

TOP

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

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.