Example usage for io.netty.buffer ByteBufHolder release

List of usage examples for io.netty.buffer ByteBufHolder release

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufHolder release.

Prototype

boolean release();

Source Link

Document

Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0 .

Usage

From source file:com.codeabovelab.dm.platform.http.async.ByteBufHolderAdapter.java

License:Apache License

@Override
public void onRemove(ByteBufHolder chunk) {
    chunk.release();
}

From source file:com.corundumstudio.socketio.transport.WebSocketTransport.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof CloseWebSocketFrame) {
        ctx.channel().close();/*w  w w  .j  a va2  s  .c  om*/
        ReferenceCountUtil.release(msg);
    } else if (msg instanceof BinaryWebSocketFrame || msg instanceof TextWebSocketFrame) {
        ByteBufHolder frame = (ByteBufHolder) msg;
        ClientHead client = clientsBox.get(ctx.channel());
        if (client == null) {
            log.debug("Client with was already disconnected. Channel closed!");
            ctx.channel().close();
            frame.release();
            return;
        }

        ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content(), Transport.WEBSOCKET));
        frame.release();
    } else if (msg instanceof FullHttpRequest) {
        FullHttpRequest req = (FullHttpRequest) msg;
        QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
        String path = queryDecoder.path();
        List<String> transport = queryDecoder.parameters().get("transport");
        List<String> sid = queryDecoder.parameters().get("sid");

        if (transport != null && NAME.equals(transport.get(0))) {
            try {
                if (!configuration.getTransports().contains(Transport.WEBSOCKET)) {
                    log.debug("{} transport not supported by configuration.", Transport.WEBSOCKET);
                    ctx.channel().close();
                    return;
                }
                if (sid != null && sid.get(0) != null) {
                    final UUID sessionId = UUID.fromString(sid.get(0));
                    handshake(ctx, sessionId, path, req);
                } else {
                    ClientHead client = ctx.channel().attr(ClientHead.CLIENT).get();
                    // first connection
                    handshake(ctx, client.getSessionId(), path, req);
                }
            } finally {
                req.release();
            }
        } else {
            ctx.fireChannelRead(msg);
        }
    } else {
        ctx.fireChannelRead(msg);
    }
}

From source file:com.linecorp.armeria.common.HttpMessageAggregator.java

License:Apache License

@Override
public void accept(Void unused, Throwable cause) {
    if (cause != null) {
        fail(cause);//from   ww  w .  j a va  2s  .co  m
        return;
    }

    final HttpData content;
    if (contentLength == 0) {
        content = HttpData.EMPTY_DATA;
    } else {
        if (alloc != null) {
            final ByteBuf merged = alloc.buffer(contentLength);
            for (int i = 0; i < contentList.size(); i++) {
                final HttpData data = contentList.set(i, null);
                if (data instanceof ByteBufHolder) {
                    ByteBufHolder byteBufData = (ByteBufHolder) data;
                    try {
                        merged.writeBytes(byteBufData.content());
                    } finally {
                        byteBufData.release();
                    }
                } else {
                    merged.writeBytes(data.array(), data.offset(), data.length());
                }
            }
            content = new ByteBufHttpData(merged, true);
        } else {
            final byte[] merged = new byte[contentLength];
            for (int i = 0, offset = 0; i < contentList.size(); i++) {
                final HttpData data = contentList.set(i, null);
                final int dataLength = data.length();
                System.arraycopy(data.array(), data.offset(), merged, offset, dataLength);
                offset += dataLength;
            }
            content = HttpData.of(merged);
        }
    }

    try {
        future.complete(onSuccess(content));
    } catch (Throwable e) {
        future.completeExceptionally(e);
    }
}