Package org.glassfish.grizzly

Examples of org.glassfish.grizzly.Buffer


        if (!connection.isOpen()) {
            completionHandler.failed(new IllegalStateException("Connection is not open."));
            return;
        }

        final Buffer message = Buffers.wrap(connection.getTransport().getMemoryManager(), buffer);

        final EmptyCompletionHandler emptyCompletionHandler = new EmptyCompletionHandler() {
            @Override
            public void cancelled() {
                if (completionHandler != null) {
View Full Code Here


        if (tyrusConnection != null) {
            // this is websocket with completed handshake
            if (message.getContent().hasRemaining()) {

                // get the frame(s) content
                Buffer buffer = message.getContent();
                final ByteBuffer webSocketBuffer = buffer.toByteBuffer();
                message.recycle();
                final ReadHandler readHandler = tyrusConnection.getReadHandler();

                TaskProcessor taskProcessor = TASK_PROCESSOR.get(ctx.getConnection());
                taskProcessor.processTask(new ProcessTask(webSocketBuffer, readHandler));
View Full Code Here

        // tyrusConnection is not null
        // this is websocket with the completed handshake
        if (message.getContent().hasRemaining()) {
            // get the frame(s) content

            Buffer buffer = message.getContent();
            message.recycle();
            final ReadHandler readHandler = tyrusConnection.getReadHandler();
            TaskProcessor taskProcessor = getTaskProcessor(ctx);
            if (!buffer.isComposite()) {
                taskProcessor.processTask(new ProcessTask(buffer.toByteBuffer(), readHandler));
            } else {
                final ByteBufferArray byteBufferArray = buffer.toByteBufferArray();
                final ByteBuffer[] array = byteBufferArray.getArray();

                for (int i = 0; i < byteBufferArray.size(); i++) {
                    taskProcessor.processTask(new ProcessTask(array[i], readHandler));
                }
View Full Code Here

     * Read post body in an array.
     */
    protected int readPostBody(byte body[], int len)
            throws IOException {

        Buffer b = coyoteRequest.getPostBody(len).duplicate();
        final int length = b.limit() - b.position();
        b.get(body, b.position(), length);
        return length;

    }
View Full Code Here

     * Read post body in an array.
     */
    protected int readPostBody(byte body[], int len)
            throws IOException {

        Buffer b = coyoteRequest.getPostBody(len).duplicate();
        final int length = b.limit() - b.position();
        b.get(body, b.position(), length);
        return length;

    }
View Full Code Here

     * Read post body in an array.
     */
    protected int readPostBody(byte body[], int len)
            throws IOException {

        Buffer b = coyoteRequest.getPostBody(len).duplicate();
        final int length = b.limit() - b.position();
        b.get(body, b.position(), length);
        return length;

    }
View Full Code Here

     * Read post body in an array.
     */
    protected int readPostBody(byte body[], int len)
            throws IOException {

        Buffer b = coyoteRequest.getPostBody(len).duplicate();
        final int length = b.limit() - b.position();
        b.get(body, b.position(), length);
        return length;

    }
View Full Code Here

     * Read post body in an array.
     */
    protected int readPostBody(byte body[], int len)
            throws IOException {

        Buffer b = coyoteRequest.getPostBody(len).duplicate();
        final int length = b.limit() - b.position();
        b.get(body, b.position(), length);
        return length;

    }
View Full Code Here

                upstreamCodec.encode(channel, output, msg);
            }
           
            GrizzlyChannel.removeChannelIfDisconnectd(connection);
            byte[] bytes = output.toByteArray();
            Buffer buffer = connection.getTransport().getMemoryManager().allocate(bytes.length);
            buffer.put(bytes);
            buffer.flip();
            buffer.allowBufferDispose(true);
            context.setMessage(buffer);
        } finally {
            GrizzlyChannel.removeChannelIfDisconnectd(connection);
        }
        return context.getInvokeAction();
View Full Code Here

        Object message = context.getMessage();
        Connection<?> connection = context.getConnection();
        Channel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
        try {
            if (message instanceof Buffer) { // 收到新的数据包
                Buffer buffer = (Buffer) message; // 缓存
                int readable = buffer.capacity(); // 本次可读取新数据的大小
                if (readable == 0) {
                    return context.getStopAction();
                }
                byte[] bytes; // byte[]缓存区,将Buffer转成byte[],再转成UnsafeByteArrayInputStream
                int offset; // 指向已用数据的偏移量,off之前的数据都是已用过的
                int limit; // 有效长度,limit之后的长度是空白或无效数据,off到limit之间的数据是准备使用的有效数据
                Object[] remainder = (Object[]) channel.getAttribute(BUFFER_KEY); // 上次序列化剩下的数据
                channel.removeAttribute(BUFFER_KEY);
                if (remainder == null) { // 如果没有,创建新的bytes缓存
                    bytes = new byte[bufferSize];
                    offset = 0;
                    limit = 0;
                } else { // 如果有,使用剩下的bytes缓存
                    bytes = (byte[]) remainder[0];
                    offset = (Integer) remainder[1];
                    limit = (Integer) remainder[2];
                }
                return receive(context, channel, buffer, readable, bytes, offset, limit);
            } else if (message instanceof Object[]) { // 同一Buffer多轮Filter,即:一个Buffer里有多个请求
                Object[] remainder = (Object[]) message;
                Buffer buffer = (Buffer) remainder[0];
                int readable = (Integer) remainder[1];
                byte[] bytes = (byte[]) remainder[2];
                int offset = (Integer) remainder[3];
                int limit = (Integer) remainder[4];
                return receive(context, channel, buffer, readable, bytes, offset, limit);
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.Buffer

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.