本文整理汇总了Java中io.netty.util.ReferenceCountUtil类的典型用法代码示例。如果您正苦于以下问题:Java ReferenceCountUtil类的具体用法?Java ReferenceCountUtil怎么用?Java ReferenceCountUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReferenceCountUtil类属于io.netty.util包,在下文中一共展示了ReferenceCountUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//客户端channel已关闭则不转发了
if (!clientChannel.isOpen()) {
ReferenceCountUtil.release(msg);
return;
}
HttpProxyInterceptPipeline interceptPipeline = ((HttpProxyServerHandle) clientChannel.pipeline()
.get("serverHandle")).getInterceptPipeline();
if (msg instanceof HttpResponse) {
interceptPipeline.afterResponse(clientChannel, ctx.channel(), (HttpResponse) msg);
} else if (msg instanceof HttpContent) {
interceptPipeline.afterResponse(clientChannel, ctx.channel(), (HttpContent) msg);
} else {
clientChannel.writeAndFlush(msg);
}
}
示例2: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (dstChannel.isActive()) {
ByteBuf byteBuf = (ByteBuf) msg;
try {
if (!byteBuf.hasArray()) {
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.getBytes(0, bytes);
if (uplink) {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(wrapper.wrap(bytes)));
log.info("\tClient ==========> Target \tSend [{} bytes]", bytes.length);
} else {
bytes = wrapper.unwrap(bytes);
if (bytes != null) {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
log.info("\tClient <========== Target \tGet [{} bytes]", bytes.length);
}
}
}
} finally {
ReferenceCountUtil.release(msg);
}
}
}
示例3: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (dstChannel.isActive()) {
ByteBuf byteBuf = (ByteBuf) msg;
try {
if (!byteBuf.hasArray()) {
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.getBytes(0, bytes);
if (uplink) {
bytes = wrapper.unwrap(bytes);
if (bytes != null) {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
log.info("\tClient ==========> Target \tSend [{} bytes]", bytes.length);
}
} else {
dstChannel.writeAndFlush(Unpooled.wrappedBuffer(wrapper.wrap(bytes)));
log.info("\tClient <========== Target \tGet [{} bytes]", bytes.length);
}
}
} finally {
ReferenceCountUtil.release(msg);
}
}
}
示例4: channelRead0
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx,
FullHttpRequest request) throws Exception {
if (master.config().getProxyMode() == ProxyMode.HTTP && !tunneled) {
if (request.method() == HttpMethod.CONNECT) {
handleTunnelProxyConnection(ctx, request);
} else {
handleHttpProxyConnection(ctx, request);
}
} else {
checkState(outboundChannel != null);
LOGGER.info("[Client ({})] => [Server ({})] : {}",
connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
request);
outboundChannel.writeAndFlush(ReferenceCountUtil.retain(request));
}
}
示例5: encode
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
private ByteBuf encode ( final ChannelHandlerContext ctx, final Object msg )
{
ByteBuf buf = ctx.alloc ().buffer ( 255 );
try
{
this.manager.encodeMessage ( msg, buf );
if ( buf.isReadable () )
{
// copy away the reference so it does not get released
final ByteBuf buf2 = buf;
buf = null;
return buf2;
}
}
finally
{
ReferenceCountUtil.release ( buf );
}
return null;
}
示例6: handleIFormat
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
private void handleIFormat ( final InformationTransfer msg, ByteBuf out )
{
final ByteBuf data = msg.getData ();
try
{
out = out.order ( ByteOrder.LITTLE_ENDIAN );
final int len = data.readableBytes ();
if ( len > Constants.APCI_MAX_DATA_LENGTH )
{
throw new EncoderException ( String.format ( "Packet too big - %s bytes", len ) );
}
out.ensureWritable ( 6 + len );
out.writeByte ( Constants.START_BYTE );
out.writeByte ( 4 + len );
out.writeShort ( msg.getSendSequenceNumber () << 1 );
out.writeShort ( msg.getReceiveSequenceNumber () << 1 );
out.writeBytes ( data );
}
finally
{
ReferenceCountUtil.release ( msg.getData () );
}
}
示例7: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
try {
if (relayChannel.isActive()) {
ByteBuf bytebuff = (ByteBuf) msg;
if (!bytebuff.hasArray()) {
int len = bytebuff.readableBytes();
byte[] arr = new byte[len];
bytebuff.getBytes(0, arr);
connectHandler.sendRemote(arr, arr.length, relayChannel);
}
}
} catch (Exception e) {
logger.error("send data to remoteServer error",e);
} finally {
ReferenceCountUtil.release(msg);
}
}
示例8: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
try {
if (relayChannel.isActive()) {
logger.debug("get remote message" + relayChannel);
ByteBuf bytebuff = (ByteBuf) msg;
if (!bytebuff.hasArray()) {
int len = bytebuff.readableBytes();
byte[] arr = new byte[len];
bytebuff.getBytes(0, arr);
connectHandler.sendLocal(arr, arr.length, relayChannel);
}
}
} catch (Exception e) {
logger.error("receive remoteServer data error", e);
} finally {
ReferenceCountUtil.release(msg);
}
}
示例9: dotStuff
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
private String dotStuff(String testString, int chunkSize) throws Exception {
ByteArrayInputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8));
DotStuffingChunkedStream chunkedStream = new DotStuffingChunkedStream(stream, chunkSize);
CompositeByteBuf destBuffer = ALLOCATOR.compositeBuffer();
while (!chunkedStream.isEndOfInput()) {
destBuffer.addComponent(true, chunkedStream.readChunk(ALLOCATOR));
}
byte[] bytes = new byte[destBuffer.readableBytes()];
destBuffer.getBytes(0, bytes);
ReferenceCountUtil.release(destBuffer);
return new String(bytes, CharsetUtil.UTF_8);
}
示例10: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
if (!(msg instanceof AbstractMessage)) {
Log.warn(SERIAL, "Invalid message received! Message skipped.");
return;
}
Log.debug(SERIAL, "Message received: " + msg);
// Notify that a message was received.
onMessageReceived((AbstractMessage) msg);
} finally {
ReferenceCountUtil.release(msg);
}
}
示例11: beforeRequest
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void beforeRequest(Channel clientChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline) throws Exception {
if (content != null) {
ByteBuf temp = httpContent.content().slice();
content.writeBytes(temp);
if (httpContent instanceof LastHttpContent) {
try {
byte[] contentBts = new byte[content.readableBytes()];
content.readBytes(contentBts);
((HttpRequestInfo) pipeline.getHttpRequest()).setContent(contentBts);
} finally {
ReferenceCountUtil.release(content);
content = null; //状态回归
}
}
}
pipeline.beforeRequest(clientChannel, httpContent);
}
示例12: channelRead
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Message message = (Message) msg;
try {
if (Constants.COMMAND_REGISTER.equals(message.getCommand())) {
Application.Connections.put(message.getContent(), ctx.channel());
logger.debug("token " + message.getContent() + " ==> remote address " + ctx.channel().remoteAddress());
} else if (!Application.clientIsOnline(ctx.channel())) {
ctx.writeAndFlush(Constants.CONTENT_BYE);
ctx.close();
} else {
if (Constants.COMMAND_PULSE.equals(message.getCommand())) {
} else {
ctx.writeAndFlush(Constants.CONTENT_BYE);
ctx.close();
}
}
} finally {
ReferenceCountUtil.release(msg);
}
}
示例13: failPendingBatchMessages
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
/**
* fail any pending batch messages that were enqueued, however batch was not closed out
*
*/
private void failPendingBatchMessages(PulsarClientException ex) {
if (batchMessageContainer.isEmpty()) {
return;
}
int numMessagesInBatch = batchMessageContainer.numMessagesInBatch;
semaphore.release(numMessagesInBatch);
try {
// Need to protect ourselves from any exception being thrown in the future handler from the application
batchMessageContainer.firstCallback.sendComplete(ex);
} catch (Throwable t) {
log.warn("[{}] [{}] Got exception while completing the callback for msg {}:", topic, producerName,
batchMessageContainer.sequenceId, t);
}
ReferenceCountUtil.safeRelease(batchMessageContainer.getBatchedSingleMessageMetadataAndPayload());
batchMessageContainer.clear();
}
示例14: serializeResponseAsBinary
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public ByteBuf serializeResponseAsBinary(final ResponseMessage responseMessage, final ByteBufAllocator allocator) throws SerializationException {
ByteBuf encodedMessage = null;
try {
final byte[] payload = mapper.writeValueAsBytes(responseMessage);
encodedMessage = allocator.buffer(payload.length);
encodedMessage.writeBytes(payload);
return encodedMessage;
} catch (Exception ex) {
if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
logger.warn("Response [{}] could not be serialized by {}.", responseMessage.toString(), AbstractGraphSONMessageSerializerV1d0.class.getName());
throw new SerializationException(ex);
}
}
示例15: serializeRequestAsBinary
import io.netty.util.ReferenceCountUtil; //导入依赖的package包/类
@Override
public ByteBuf serializeRequestAsBinary(final RequestMessage requestMessage, final ByteBufAllocator allocator) throws SerializationException {
ByteBuf encodedMessage = null;
try {
final byte[] header = obtainHeader();
final byte[] payload = mapper.writeValueAsBytes(requestMessage);
encodedMessage = allocator.buffer(header.length + payload.length);
encodedMessage.writeBytes(header);
encodedMessage.writeBytes(payload);
return encodedMessage;
} catch (Exception ex) {
if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
logger.warn("Request [{}] could not be serialized by {}.", requestMessage.toString(), AbstractGraphSONMessageSerializerV1d0.class.getName());
throw new SerializationException(ex);
}
}