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


Java ReferenceCountUtil.retain方法代码示例

本文整理汇总了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);
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:19,代码来源:HttpWsSwitch.java

示例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());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:15,代码来源:NetworkSession.java

示例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);
}
 
开发者ID:spccold,项目名称:sailfish,代码行数:11,代码来源:NegotiateChannelHandler.java

示例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);
	}
}
 
开发者ID:mwambler,项目名称:xockets.io,代码行数:8,代码来源:WebSocketValidationHandler.java

示例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();
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:14,代码来源:EmbeddedChannel.java

示例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);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:10,代码来源:DefaultChannelGroup.java

示例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));
    }
}
 
开发者ID:tctxl,项目名称:Seed,代码行数:10,代码来源:Encoder.java

示例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();
      }
   });
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:39,代码来源:AmqpConnection.java

示例9: claim

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
private void claim(ByteBuf buf) {
  if (buf == null) {
    return;
  }
  ReferenceCountUtil.retain(buf);
  trailer.add(buf);
}
 
开发者ID:salesforce,项目名称:coyote,代码行数:8,代码来源:NettyInboundRoadRunnerMessage.java

示例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);			
		}
	}
 
开发者ID:nickman,项目名称:tsdblite,代码行数:36,代码来源:HttpSwitch.java

示例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();//释放计数器
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:7,代码来源:NettyHttpClient.java

示例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);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:10,代码来源:ConnectionManager.java

示例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;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:49,代码来源:NetworkSession.java

示例14: retain

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public FullHttpRequest retain(int increment) {
    ReferenceCountUtil.retain(message, increment);
    return this;
}
 
开发者ID:playframework,项目名称:netty-reactive-streams,代码行数:6,代码来源:EmptyHttpRequest.java

示例15: retain

import io.netty.util.ReferenceCountUtil; //导入方法依赖的package包/类
@Override
public FullHttpResponse retain(int increment) {
    ReferenceCountUtil.retain(message, increment);
    return this;
}
 
开发者ID:playframework,项目名称:netty-reactive-streams,代码行数:6,代码来源:EmptyHttpResponse.java


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