Package org.glassfish.grizzly.nio

Examples of org.glassfish.grizzly.nio.DirectByteBufferRecord


            final CompositeQueueRecord queueRecord) throws IOException {
       
        final int bufferSize = Math.min(queueRecord.size,
                connection.getWriteBufferSize() * 3 / 2);
       
        final DirectByteBufferRecord directByteBufferRecord =
                DirectByteBufferRecord.get();

        try {
            final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
       
            fill(queueRecord, bufferSize, directByteBufferRecord);
            directByteBufferRecord.finishBufferSlice();
           
            final int arraySize = directByteBufferRecord.getArraySize();

            final int written = arraySize == 1 ?

                    TCPNIOUtils.flushByteBuffer(
                    socketChannel, directByteBufferRecord.getArray()[0]) :

                    TCPNIOUtils.flushByteBuffers(
                    socketChannel, directByteBufferRecord.getArray(), 0, arraySize) ;
           
            return update(queueRecord, written);
        } catch (IOException e) {
            // Mark connection as closed remotely.
            ((TCPNIOConnection) connection).terminate0(null,
                    new CloseReason(CloseType.REMOTELY, e));
            throw e;
        } finally {
            directByteBufferRecord.release();
        }
    }
View Full Code Here


        final int oldLim = buffer.limit();
        buffer.limit(oldPos + bufferSize);
       
        final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
       
        final DirectByteBufferRecord ioRecord = DirectByteBufferRecord.get();
        final BufferArray bufferArray = buffer.toBufferArray();
        int written = 0;
       
        fill(bufferArray, bufferSize, ioRecord);
        ioRecord.finishBufferSlice();
       
        final int arraySize = ioRecord.getArraySize();
       
        try {
            written = arraySize != 1
                    ? flushByteBuffers(socketChannel, ioRecord.getArray(), 0, arraySize)
                    : flushByteBuffer(socketChannel, ioRecord.getArray()[0]);

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (composite) write {1} bytes", new Object[]{
                            connection, written
                        });
            }
        } finally {
            bufferArray.restore();
            bufferArray.recycle();
            ioRecord.release();
        }
       
        Buffers.setPositionLimit(buffer, oldPos + written, oldLim);
        return written;
    }
View Full Code Here

            }
        } else {
            final int bufferSize = calcWriteBufferSize(connection, buffer.remaining());
            buffer.limit(oldPos + bufferSize);
           
            final DirectByteBufferRecord ioRecord =
                    DirectByteBufferRecord.get();
            final ByteBuffer directByteBuffer = ioRecord.allocate(bufferSize);
            fill(buffer, bufferSize, directByteBuffer);
           
            try {
                written = flushByteBuffer(socketChannel, directByteBuffer);
            } finally {
                ioRecord.release();
            }
        }

        Buffers.setPositionLimit(buffer, oldPos + written, oldLim);
        if(LOGGER.isLoggable(Level.FINE))
View Full Code Here

            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);
            }
View Full Code Here

    public InputBufferWrapper() {
    }

    public InputBufferWrapper prepare(final int size) {
        final DirectByteBufferRecord recordLocal = DirectByteBufferRecord.get();
        this.record = recordLocal;
        this.visible = recordLocal.allocate(size);
       
        return this;
    }
View Full Code Here

            if (bufferSize == 0) {
                written = 0;
            } else {               

                final DirectByteBufferRecord directByteBufferRecord =
                        DirectByteBufferRecord.allocate(bufferSize);
               
                try {
                    final ByteBuffer directByteBuffer = directByteBufferRecord.getByteBuffer();
                    final SocketChannel socketChannel = (SocketChannel) connection.getChannel();

                    fillByteBuffer(buffer, 0, bufferSize, directByteBuffer);
                    written = TCPNIOTransport.flushByteBuffer(
                            socketChannel, directByteBuffer);

                    buffer.position(oldPos + (int) written);
                    ((TCPNIOConnection) connection).onWrite(buffer, written);
                } catch (IOException e) {
                    // Mark connection as closed remotely.
                    ((TCPNIOConnection) connection).close0(null,
                            new CloseReason(CloseType.REMOTELY, e));
                    throw e;
                } finally {
                    directByteBufferRecord.release();
                }
            }
        } else if (message instanceof FileTransfer) {
            written = ((FileTransfer) message).writeTo((SocketChannel) connection.getChannel());
            ((TCPNIOConnection) connection).onWrite(null, written);
View Full Code Here

            final CompositeQueueRecord queueRecord) throws IOException {
       
        final int bufferSize = Math.min(queueRecord.size,
                connection.getWriteBufferSize() * 2);
       
        final DirectByteBufferRecord directByteBufferRecord =
                DirectByteBufferRecord.allocate(bufferSize);

        try {
            final ByteBuffer directByteBuffer = directByteBufferRecord.getByteBuffer();
            final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
       
            fillByteBuffer(queueRecord.queue, directByteBuffer);
           
            final int written = TCPNIOTransport.flushByteBuffer(socketChannel,
                    directByteBuffer);

            return update(queueRecord, written);
        } catch (IOException e) {
            // Mark connection as closed remotely.
            ((TCPNIOConnection) connection).close0(null,
                    new CloseReason(CloseType.REMOTELY, e));
            throw e;
        } finally {
            directByteBufferRecord.release();
        }
    }
View Full Code Here

    public InputBufferWrapper() {
    }

    public InputBufferWrapper prepare(final int size) {
        final DirectByteBufferRecord recordLocal = DirectByteBufferRecord.allocate(size);
        this.record = recordLocal;
        this.visible = recordLocal.getByteBuffer();
       
        return this;
    }
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.nio.DirectByteBufferRecord

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.