当前位置: 首页>>代码示例>>Java>>正文


Java ReferenceCountUtil.safeRelease方法代码示例

本文整理汇总了Java中io.netty.util.ReferenceCountUtil.safeRelease方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceCountUtil.safeRelease方法的具体用法?Java ReferenceCountUtil.safeRelease怎么用?Java ReferenceCountUtil.safeRelease使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.util.ReferenceCountUtil的用法示例。


在下文中一共展示了ReferenceCountUtil.safeRelease方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:21,代码来源:ProducerImpl.java

示例2: remove

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
/**
 * Will remove the current message, mark its {@link ChannelPromise} as success and return {@code true}. If no
 * flushed message exists at the time this method is called it will return {@code false} to signal that no more
 * messages are ready to be handled.
 */
public boolean remove() {
    Entry e = flushedEntry;
    if (e == null) {
        return false;
    }
    Object msg = e.msg;

    ChannelPromise promise = e.promise;
    int size = e.pendingSize;

    removeEntry(e);

    if (!e.cancelled) {
        // only release message, notify and decrement if it was not canceled before.
        ReferenceCountUtil.safeRelease(msg);
        safeSuccess(promise);
        decrementPendingOutboundBytes(size, false);
    }

    // recycle the entry
    e.recycle();

    return true;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:30,代码来源:ChannelOutboundBuffer.java

示例3: cancel

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
int cancel() {
    if (!cancelled) {
        cancelled = true;
        int pSize = pendingSize;

        // release message and replace with an empty buffer
        ReferenceCountUtil.safeRelease(msg);
        msg = Unpooled.EMPTY_BUFFER;

        pendingSize = 0;
        total = 0;
        progress = 0;
        bufs = null;
        buf = null;
        return pSize;
    }
    return 0;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:ChannelOutboundBuffer.java

示例4: newDirectBuffer

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
/**
 * Returns an off-heap copy of the specified {@link ByteBuf}, and releases the specified holder.
 * The caller must ensure that the holder releases the original {@link ByteBuf} when the holder is released by
 * this method.
 */
protected final ByteBuf newDirectBuffer(Object holder, ByteBuf buf) {
    final int readableBytes = buf.readableBytes();
    if (readableBytes == 0) {
        ReferenceCountUtil.safeRelease(holder);
        return Unpooled.EMPTY_BUFFER;
    }

    final ByteBufAllocator alloc = alloc();
    if (alloc.isDirectBufferPooled()) {
        return newDirectBuffer0(holder, buf, alloc, readableBytes);
    }

    final ByteBuf directBuf = ByteBufUtil.threadLocalDirectBuffer();
    if (directBuf == null) {
        return newDirectBuffer0(holder, buf, alloc, readableBytes);
    }

    directBuf.writeBytes(buf, buf.readerIndex(), readableBytes);
    ReferenceCountUtil.safeRelease(holder);
    return directBuf;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:27,代码来源:AbstractEpollChannel.java

示例5: onResponse

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private void onResponse(
        DnsQuestion question,
        AddressedEnvelope<DnsResponse, InetSocketAddress> envelope,
        CompletableFuture<List<Endpoint>> promise) {
    try {
        final DnsResponse res = envelope.content();
        final DnsResponseCode code = res.code();
        if (code == DnsResponseCode.NOERROR) {
            decodeResponse(question, envelope, promise);
            return;
        }

        if (code != DnsResponseCode.NXDOMAIN) {
            logger.warn(
                    "Name lookup failed on configured name server for hostname: {} - querying other " +
                    "name servers is not supported.", hostname);
        } else {
            logger.warn("No records found for hostname: {}. Is it registered in DNS?", hostname);
        }
        promise.complete(ImmutableList.of());
    } finally {
        ReferenceCountUtil.safeRelease(envelope);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:25,代码来源:DnsServiceEndpointGroup.java

示例6: onData

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private void onData(HttpData data) {
    boolean added = false;
    try {
        if (future.isDone()) {
            return;
        }

        final int dataLength = data.length();
        if (dataLength > 0) {
            final int allowedMaxDataLength = Integer.MAX_VALUE - contentLength;
            if (dataLength > allowedMaxDataLength) {
                subscription.cancel();
                fail(new IllegalStateException("content length greater than Integer.MAX_VALUE"));
                return;
            }

            contentList.add(data);
            contentLength += dataLength;
            added = true;
        }
    } finally {
        if (!added) {
            ReferenceCountUtil.safeRelease(data);
        }
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:27,代码来源:HttpMessageAggregator.java

示例7: cleanupObjects

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
final void cleanupObjects() {
    if (obj1 != null) {
        try {
            onRemoval(obj1);
        } finally {
            ReferenceCountUtil.safeRelease(obj1);
        }
        obj1 = null;
    }
    if (obj2 != null) {
        try {
            onRemoval(obj2);
        } finally {
            ReferenceCountUtil.safeRelease(obj2);
        }
        obj2 = null;
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:20,代码来源:TwoElementFixedStreamMessage.java

示例8: close

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void close() {
    bufferLock.writeLock().lock();
    try {
        ReferenceCountUtil.safeRelease(topicStatsBuf);
        ReferenceCountUtil.safeRelease(tempTopicStatsBuf);
    } finally {
        bufferLock.writeLock().unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:11,代码来源:PulsarStats.java

示例9: releaseBuffers

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private static void releaseBuffers(CompositeByteBuf composite, List<ByteBuf> chunkBuffers) {
    while (composite.numComponents() > 0) {
        composite.removeComponent(0);
    }
    ReferenceCountUtil.safeRelease(composite);
    chunkBuffers.forEach(ReferenceCountUtil::safeRelease);
}
 
开发者ID:eclipse,项目名称:milo,代码行数:8,代码来源:ChunkDecoder.java

示例10: channelRead

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
final public void channelRead(ChannelHandlerContext ctx, Object msg)
		throws Exception {
	if (msg == null || msg == Unpooled.EMPTY_BUFFER || msg instanceof EmptyByteBuf) {
		return;
	}
	try {
		ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
		if (ops != null) {
			ops.onInboundNext(ctx, msg);
		}
		else {
			if (log.isDebugEnabled()) {
				String loggingMsg = msg.toString();
				if (msg instanceof HttpResponse) {
					DecoderResult decoderResult = ((HttpResponse) msg).decoderResult();
					if (decoderResult.isFailure()) {
						log.debug("Decoding failed: " + msg + " : ", decoderResult.cause());
					}
				}
				if (msg instanceof ByteBufHolder) {
					loggingMsg = ((ByteBufHolder) msg).content()
					                                  .toString(Charset.defaultCharset());
				}
				log.debug("{} No ChannelOperation attached. Dropping: {}", ctx
						.channel().toString(), loggingMsg);
			}
			ReferenceCountUtil.release(msg);
		}
	}
	catch (Throwable err) {
		Exceptions.throwIfFatal(err);
		exceptionCaught(ctx, err);
		ReferenceCountUtil.safeRelease(msg);
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:37,代码来源:ChannelOperationsHandler.java

示例11: channelRead0

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, String message) throws Exception {

    try {
        if ((message != null) && message.trim().equals("version")) {
            ctx.write(com.pearson.statsagg.controller.Version.getProjectVersion() + "-" + com.pearson.statsagg.controller.Version.getBuildTimestamp() + "\n");
        }
        else if ((message != null) && (message.length() > 4) && message.startsWith("put ")){
            long currentTimestampInMilliseconds = System.currentTimeMillis();

            List<OpenTsdbMetric> openTsdbMetrics = OpenTsdbMetric.parseOpenTsdbMetrics(message.substring(4), 
                    GlobalVariables.openTsdbPrefix, currentTimestampInMilliseconds);

            for (OpenTsdbMetric openTsdbMetric : openTsdbMetrics) {
                long hashKey = GlobalVariables.metricHashKeyGenerator.incrementAndGet();
                openTsdbMetric.setHashKey(hashKey);
                if (openTsdbMetric.getMetricKey() != null) openTsdbMetric.getMetricKey().hashCode();
                GlobalVariables.openTsdbMetrics.put(openTsdbMetric.getHashKey(), openTsdbMetric);
                GlobalVariables.incomingMetricsCount.incrementAndGet();
            }

            if (ApplicationConfiguration.isDebugModeEnabled()) {
                logger.info("TCP_OpenTsdb_Received_Metrics=" + openTsdbMetrics.size());
                logger.info("TCP_OpenTsdb_String=\"" + message + "\"");
            }
        }
    }
    finally {
        ReferenceCountUtil.safeRelease(message);
    }
}
 
开发者ID:PearsonEducation,项目名称:StatsAgg,代码行数:32,代码来源:TcpServerHandler_OpenTsdb.java

示例12: cleanupObjects

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
final void cleanupObjects() {
    while (fulfilled < objs.length) {
        T obj = objs[fulfilled];
        objs[fulfilled++] = null;
        try {
            onRemoval(obj);
        } finally {
            ReferenceCountUtil.safeRelease(obj);
        }
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:13,代码来源:RegularFixedStreamMessage.java

示例13: close

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
void close(final ClosedChannelException cause) {
    if (inFail) {
        channel.eventLoop().execute(new Runnable() {
            @Override
            public void run() {
                close(cause);
            }
        });
        return;
    }

    inFail = true;

    if (channel.isOpen()) {
        throw new IllegalStateException("close() must be invoked after the channel is closed.");
    }

    if (!isEmpty()) {
        throw new IllegalStateException("close() must be invoked after all flushed writes are handled.");
    }

    // Release all unflushed messages.
    try {
        Entry e = unflushedEntry;
        while (e != null) {
            // Just decrease; do not trigger any events via decrementPendingOutboundBytes()
            int size = e.pendingSize;
            TOTAL_PENDING_SIZE_UPDATER.addAndGet(this, -size);

            if (!e.cancelled) {
                ReferenceCountUtil.safeRelease(e.msg);
                safeFail(e.promise, cause);
            }
            e = e.recycleAndGetNext();
        }
    } finally {
        inFail = false;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:40,代码来源:ChannelOutboundBuffer.java

示例14: doWriteData

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected ChannelFuture doWriteData(
        ChannelHandlerContext ctx, int id, int streamId, HttpData data, boolean endStream) {

    if (id >= minClosedId) {
        ReferenceCountUtil.safeRelease(data);
        return ctx.newFailedFuture(ClosedSessionException.get());
    }

    final int length = data.length();
    if (length == 0) {
        ReferenceCountUtil.safeRelease(data);
        final HttpContent content = endStream ? LastHttpContent.EMPTY_LAST_CONTENT : EMPTY_CONTENT;
        final ChannelFuture future = write(ctx, id, content, endStream);
        ctx.flush();
        return future;
    }

    try {
        if (!isTls || length <= MAX_TLS_DATA_LENGTH) {
            // Cleartext connection or data.length() <= MAX_TLS_DATA_LENGTH
            return doWriteUnsplitData(ctx, id, data, endStream);
        } else {
            // TLS and data.length() > MAX_TLS_DATA_LENGTH
            return doWriteSplitData(ctx, id, data, endStream);
        }
    } catch (Throwable t) {
        return ctx.newFailedFuture(t);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:31,代码来源:Http1ObjectEncoder.java

示例15: doWriteSplitData

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private ChannelFuture doWriteSplitData(
        ChannelHandlerContext ctx, int id, HttpData data, boolean endStream) {

    try {
        int offset = data.offset();
        int remaining = data.length();
        ChannelFuture lastFuture;
        for (;;) {
            // Ensure an HttpContent does not exceed the maximum length of a cleartext TLS record.
            final int chunkSize = Math.min(MAX_TLS_DATA_LENGTH, remaining);
            lastFuture = write(ctx, id, new DefaultHttpContent(dataChunk(data, offset, chunkSize)), false);
            remaining -= chunkSize;
            if (remaining == 0) {
                break;
            }
            offset += chunkSize;
        }

        if (endStream) {
            lastFuture = write(ctx, id, LastHttpContent.EMPTY_LAST_CONTENT, true);
        }

        ctx.flush();
        return lastFuture;
    } finally {
        ReferenceCountUtil.safeRelease(data);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:29,代码来源:Http1ObjectEncoder.java


注:本文中的io.netty.util.ReferenceCountUtil.safeRelease方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。