本文整理汇总了Java中io.netty.util.ReferenceCountUtil.retain方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceCountUtil.retain方法的具体用法?Java ReferenceCountUtil.retain怎么用?Java ReferenceCountUtil.retain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.ReferenceCountUtil
的用法示例。
在下文中一共展示了ReferenceCountUtil.retain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
{
if(!added && msg instanceof HttpRequest)
{
String path = ((HttpRequest)msg).getUri();
WsServerHandler handler = findHandler(path);
if(handler != null)
{
ctx.pipeline().addAfter("switch", "aggregator", new HttpObjectAggregator(65536));
ctx.pipeline().addAfter("aggregator", "wsprotocol", new WebSocketServerProtocolHandler(path, null, true));
ctx.pipeline().addAfter("wsprotocol", "wshandler", new WsFrameHandler(handler));
added = true;
}
}
ReferenceCountUtil.retain(msg);
out.add(msg);
}
示例2: send
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
/**
* Sends a {@link Message}.
*
* @param message The message
*/
public void send(Message message) {
checkNotNull(message, "message");
if (!this.channel.isActive()) {
return;
}
ReferenceCountUtil.retain(message);
// Thrown exceptions will be delegated through the exceptionCaught method
this.channel.writeAndFlush(message, this.channel.voidPromise());
}
示例3: channelRead0
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, Protocol msg) throws Exception {
if (!ChannelUtil.clientSide(ctx) && msg.request() && msg.heartbeat()) {
dealNegotiate(ctx, msg);
return;
}
// no sense to Protocol in fact
ReferenceCountUtil.retain(msg);
ctx.fireChannelRead(msg);
}
示例4: channelRead0
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req)throws Exception {
if(this.isValidRequest(ctx, req)){
ReferenceCountUtil.retain(req);
ctx.fireChannelRead(req);
}
}
示例5: doWrite
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
for (;;) {
Object msg = in.current();
if (msg == null) {
break;
}
ReferenceCountUtil.retain(msg);
outboundMessages.add(msg);
in.remove();
}
}
示例6: safeDuplicate
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private static Object safeDuplicate(Object message) {
if (message instanceof ByteBuf) {
return ((ByteBuf) message).duplicate().retain();
} else if (message instanceof ByteBufHolder) {
return ((ByteBufHolder) message).duplicate().retain();
} else {
return ReferenceCountUtil.retain(message);
}
}
示例7: encode
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
if(msg instanceof DatagramPacket){
ReferenceCountUtil.retain(msg);
out.add(msg);
}else{
out.add(wrappedBuffer((byte[]) msg));
}
}
示例8: onData
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void onData(final ByteBuf incoming) {
// We need to retain until the serializer gets around to processing it.
ReferenceCountUtil.retain(incoming);
serializer.execute(new Runnable() {
@Override
public void run() {
ByteBuffer source = incoming.nioBuffer();
LOG.trace("Client Received from Broker {} bytes:", source.remaining());
if (protonTransport.isClosed()) {
LOG.debug("Ignoring incoming data because transport is closed");
return;
}
do {
ByteBuffer buffer = protonTransport.getInputBuffer();
int limit = Math.min(buffer.remaining(), source.remaining());
ByteBuffer duplicate = source.duplicate();
duplicate.limit(source.position() + limit);
buffer.put(duplicate);
protonTransport.processInput();
source.position(source.position() + limit);
}
while (source.hasRemaining());
ReferenceCountUtil.release(incoming);
// Process the state changes from the latest data and then answer back
// any pending updates to the Broker.
processUpdates();
pumpToProtonTransport();
}
});
}
示例9: claim
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private void claim(ByteBuf buf) {
if (buf == null) {
return;
}
ReferenceCountUtil.retain(buf);
trailer.add(buf);
}
示例10: decode
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
protected void decode(final ChannelHandlerContext ctx, final HttpRequest msg, final List<Object> out) throws Exception {
final String uri = msg.uri();
log.info("-----------------------> URI [{}]", uri);
if(uri.endsWith("/favicon.ico")) {
final DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, favicon);
resp.headers().set(HttpHeaders.CONTENT_TYPE, "image/x-icon");
resp.headers().setInt(HttpHeaders.CONTENT_LENGTH, favSize);
ctx.writeAndFlush(resp);
return;
}
ReferenceCountUtil.retain(msg);
final ChannelPipeline p = ctx.pipeline();
final int index = uri.indexOf("/api/");
final String endpoint = index==-1 ? "" : uri.substring(5);
if(index != -1 && pureJsonEndPoints.contains(endpoint) ) {
log.info("Switching to PureJSON handler");
p.addLast(eventExecutorGroup, "httpToJson", httpToJson);
// p.addLast("jsonLogger", loggingHandler);
p.addLast("jsonDecoder", new JsonObjectDecoder(true));
// p.addLast("jsonLogger", loggingHandler);
p.addLast("traceHandler", traceHandler);
p.remove(this);
if(msg instanceof FullHttpMessage) {
out.add(msg);
}
} else {
log.info("Switching to Http Request Manager");
out.add(msg);
p.addLast(eventExecutorGroup, "requestManager", HttpRequestManager.getInstance());
p.remove(this);
}
}
示例11: messageArrived
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public void messageArrived(JConnection conn, HttpResponse msg) {
ReferenceCountUtil.retain(msg,1);
this.response=msg;
latch.countDown();//释放计数器
}
示例12: channelRead
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @see io.netty.channel.ChannelInboundHandlerAdapter#channelRead(io.netty.channel.ChannelHandlerContext, java.lang.Object)
*/
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
ReferenceCountUtil.retain(msg);
super.channelRead(ctx, msg);
}
示例13: sendWithFuture
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
/**
* Sends a array of {@link Message}s and returns the {@link ChannelFuture}.
*
* @param messages The messages
* @return The channel future
*/
public ChannelFuture sendWithFuture(Message... messages) {
checkNotNull(messages, "messages");
checkArgument(messages.length != 0, "messages cannot be empty");
final ChannelPromise promise = this.channel.newPromise();
if (!this.channel.isActive()) {
return promise;
}
promise.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
// Don't bother checking if we are in the event loop,
// there is only one message.
if (messages.length == 1) {
this.channel.writeAndFlush(messages[0], promise);
} else {
final EventLoop eventLoop = this.channel.eventLoop();
final ChannelPromise voidPromise = this.channel.voidPromise();
if (eventLoop.inEventLoop()) {
final int last = messages.length - 1;
for (int i = 0; i < last; i++) {
ReferenceCountUtil.retain(messages[i]);
this.channel.writeAndFlush(messages[i], voidPromise);
}
ReferenceCountUtil.retain(messages[last]);
this.channel.writeAndFlush(messages[last], promise);
} else {
// If there are more then one message, combine them inside the
// event loop to reduce overhead of wakeup calls and object creation
// Create a copy of the list, to avoid concurrent modifications
final List<Message> messages0 = ImmutableList.copyOf(messages);
messages0.forEach(ReferenceCountUtil::retain);
eventLoop.submit(() -> {
final Iterator<Message> it0 = messages0.iterator();
do {
final Message message0 = it0.next();
// Only use a normal channel promise for the last message
this.channel.writeAndFlush(message0, it0.hasNext() ? voidPromise : promise);
} while (it0.hasNext());
});
}
}
return promise;
}
示例14: retain
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public FullHttpRequest retain(int increment) {
ReferenceCountUtil.retain(message, increment);
return this;
}
示例15: retain
import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public FullHttpResponse retain(int increment) {
ReferenceCountUtil.retain(message, increment);
return this;
}