當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。