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


Java ReferenceCounted类代码示例

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


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

示例1: tearDown

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@After
public void tearDown() {
  for (Object obj : objectsToRelease) {
    if (!(obj instanceof ReferenceCounted)) {
      continue;
    }

    ReferenceCounted referenceCountedObject = (ReferenceCounted) obj;

    assertThat(referenceCountedObject.refCnt())
        .withFailMessage("Trying to free %s but it has a ref count of %d", obj, referenceCountedObject.refCnt())
        .isEqualTo(1);

    referenceCountedObject.release();
  }
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:17,代码来源:SmtpSessionTest.java

示例2: testFreeCalled

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Test
public void testFreeCalled() throws Exception {
    final CountDownLatch free = new CountDownLatch(1);

    final ReferenceCounted holder = new AbstractReferenceCounted() {
        @Override
        protected void deallocate() {
            free.countDown();
        }
    };

    StringInboundHandler handler = new StringInboundHandler();
    setUp(handler);

    peer.writeAndFlush(holder).sync();

    assertTrue(free.await(10, TimeUnit.SECONDS));
    assertTrue(handler.called);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:20,代码来源:DefaultChannelPipelineTest.java

示例3: shouldHandleTwoMessagesInOneBatch

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
/**
 * This test makes sure that even when more requests arrive in the same batch, they
 * get emitted as separate messages.
 */
@Test
public void shouldHandleTwoMessagesInOneBatch() {
    channel.writeInbound(Unpooled.buffer().writeBytes(GET_REQUEST).writeBytes(GET_REQUEST));

    BinaryMemcacheRequest request = channel.readInbound();
    assertThat(request, instanceOf(BinaryMemcacheRequest.class));
    assertThat(request, notNullValue());
    request.release();

    Object lastContent = channel.readInbound();
    assertThat(lastContent, instanceOf(LastMemcacheContent.class));
    ((ReferenceCounted) lastContent).release();

    request = channel.readInbound();
    assertThat(request, instanceOf(BinaryMemcacheRequest.class));
    assertThat(request, notNullValue());
    request.release();

    lastContent = channel.readInbound();
    assertThat(lastContent, instanceOf(LastMemcacheContent.class));
    ((ReferenceCounted) lastContent).release();
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:27,代码来源:BinaryMemcacheDecoderTest.java

示例4: startAsync

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
public void startAsync(final Executor executor, final Runnable runnable) {
  Channel channel = ctx.channel();
  channel.attr(NEED_FLUSH).set(false);
  channel.attr(ASYNC).set(true);

  ReferenceCounted body = ((ByteBufHolder) req).content();
  body.retain();
  executor.execute(() -> {
    try {
      runnable.run();
    } finally {
      body.release();
    }
  });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:NettyRequest.java

示例5: releaseContentChunks

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void releaseContentChunks() {
    if (!contentChunksWillBeReleasedExternally) {
        contentChunks.forEach(ReferenceCounted::release);
    }
    // Now that the chunks have been released we should clear the chunk list - we can no longer rely on the chunks
    //      for anything, and if this method is called a second time we don't want to re-release the chunks
    //      (which would screw up the reference counting).
    contentChunks.clear();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:14,代码来源:RequestInfoImpl.java

示例6: touch

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
public ReferenceCounted touch(Object hint) {
    for (EncapsulatedRakNetPacket packet : packets) {
        packet.touch(hint);
    }
    return this;
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:8,代码来源:RakNetDatagram.java

示例7: write

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
/**
 * This method is called by users of the ProxyConnection to send stuff out
 * over the socket.
 * 
 * @param msg
 */
void write(Object msg) {
    if (msg instanceof ReferenceCounted) {
        LOG.debug("Retaining reference counted message");
        ((ReferenceCounted) msg).retain();
    }

    doWrite(msg);
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:15,代码来源:ProxyConnection.java

示例8: write

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
void write(Object msg) {
    LOG.debug("Requested write of {}", msg);

    if (msg instanceof ReferenceCounted) {
        LOG.debug("Retaining reference counted message");
        ((ReferenceCounted) msg).retain();
    }

    if (is(DISCONNECTED) && msg instanceof HttpRequest) {
        LOG.debug("Currently disconnected, connect and then write the message");
        connectAndWrite((HttpRequest) msg);
    } else {
        if (isConnecting()) {
            synchronized (connectLock) {
                if (isConnecting()) {
                    LOG.debug("Attempted to write while still in the process of connecting, waiting for connection.");
                    clientConnection.stopReading();
                    try {
                        connectLock.wait(30000);
                    } catch (InterruptedException ie) {
                        LOG.warn("Interrupted while waiting for connect monitor");
                    }
                }
            }
        }

        // only write this message if a connection was established and is not in the process of disconnecting or
        // already disconnected
        if (isConnecting() || getCurrentState().isDisconnectingOrDisconnected()) {
            LOG.debug("Connection failed or timed out while waiting to write message to server. Message will be discarded: {}", msg);
            return;
        }

        LOG.debug("Using existing connection to: {}", remoteAddress);
        doWrite(msg);
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:39,代码来源:ProxyToServerConnection.java

示例9: writeToChannel

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
/**
 * This is the method that executing writing to channel.
 * It will be used both write0 and {@link com.linkedin.mitm.proxy.connectionflow.steps.ConnectionFlowStep}
 *
 * @param channel which channel to write to
 * @param object  which object to write to.
 *
 * */
private ChannelFuture writeToChannel(final Channel channel, final Object object) {
  if (channel == null) {
    throw new IllegalStateException("Failed to write to channel because channel is null");
  }
  if (object instanceof ReferenceCounted) {
    LOG.debug("Retaining reference counted message");
    ((ReferenceCounted) object).retain();
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug(String.format("Writing in channel [%s]:  %s", channel.toString(), object));
  }
  return channel.writeAndFlush(object);
}
 
开发者ID:linkedin,项目名称:flashback,代码行数:22,代码来源:ChannelMediator.java

示例10: write

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
void write(Object msg) {
    LOG.debug("Requested write of {}", msg);

    if (msg instanceof ReferenceCounted) {
        LOG.debug("Retaining reference counted message");
        ((ReferenceCounted) msg).retain();
    }

    if (is(DISCONNECTED) && msg instanceof HttpRequest) {
        LOG.debug("Currently disconnected, connect and then write the message");
        connectAndWrite((HttpRequest) msg);
    } else {
        synchronized (connectLock) {
            if (isConnecting()) {
                LOG.debug("Attempted to write while still in the process of connecting, waiting for connection.");
                clientConnection.stopReading();
                try {
                    connectLock.wait(30000);
                } catch (InterruptedException ie) {
                    LOG.warn("Interrupted while waiting for connect monitor");
                }
                if (is(DISCONNECTED)) {
                    LOG.debug("Connection failed while we were waiting for it, don't write");
                    return;
                }
            }
        }

        LOG.debug("Using existing connection to: {}", remoteAddress);
        doWrite(msg);
    }
}
 
开发者ID:Elitward,项目名称:LittleProxy,代码行数:34,代码来源:ProxyToServerConnection.java

示例11: acceptOutboundMessage

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
public boolean acceptOutboundMessage(Object msg) throws Exception {
    final Message message = (Message) msg;
    final Protocol protocol = this.codecContext.getSession().getProtocol();
    final MessageRegistration registration = protocol.outbound().findByMessageType(message.getClass()).orElse(null);

    if (registration == null) {
        throw new EncoderException("Message type (" + message.getClass().getName() +
                ") is not registered in state " + this.codecContext.getSession().getProtocolState().name() + "!");
    }

    final List<Processor> processors = ((MessageRegistration) protocol.outbound()
            .findByMessageType(message.getClass()).get()).getProcessors();
    // Only process if there are processors found
    if (!processors.isEmpty()) {
        final List<Object> messages = new ArrayList<>();
        for (Processor processor : processors) {
            // The processor should handle the output messages
            processor.process(this.codecContext, message, messages);
        }
        if (message instanceof ReferenceCounted && !messages.contains(message)) {
            ((ReferenceCounted) message).release();
        }
        if (!messages.isEmpty()) {
            this.messages.set(messages);
        }
        return true;
    }
    return false;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:31,代码来源:MessageProcessorHandler.java

示例12: release

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
protected void release()
{
    uploadedFiles.forEach(ReferenceCounted::release);
    if(this.buffer != null)
    {
        this.buffer.release();
    }
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:9,代码来源:HttpBridletRequestImpl.java

示例13: refCnt

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
public int refCnt() {
    if (message instanceof ReferenceCounted) {
        return ((ReferenceCounted) message).refCnt();
    } else {
        return 1;
    }
}
 
开发者ID:playframework,项目名称:netty-reactive-streams,代码行数:9,代码来源:EmptyHttpRequest.java

示例14: rejectReferenceCounted

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Test
public void rejectReferenceCounted() {
    AbstractReferenceCounted item = new AbstractReferenceCounted() {
        @Override
        protected void deallocate() {}

        @Override
        public ReferenceCounted touch(Object hint) {
            return this;
        }
    };
    StreamMessageAndWriter<Object> stream = newStreamWriter(ImmutableList.of(item));
    assertThatThrownBy(() -> stream.write(item)).isInstanceOf(IllegalArgumentException.class);
}
 
开发者ID:line,项目名称:armeria,代码行数:15,代码来源:AbstractStreamMessageAndWriterTest.java

示例15: channelRead

import io.netty.util.ReferenceCounted; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof Message) {
    Message message = (Message) msg;
    if (currentPayload == null) {
      log.error("No payload received for request id '{}': {}", message.getId(), message);
      ctx.fireExceptionCaught(
          new RuntimeException("No payload received for request id '" + message.getId() + "'"));
      reset();
      return;
    }
    if (error) {
      log.error("Multiple payloads received for request id '{}': {}", message.getId(), message);
      ctx.fireExceptionCaught(
          new RuntimeException(
              "Multiple payloads received for request id '" + message.getId() + "'"));
      reset();
      return;
    }
    ServerRequest request =
        new ServerRequest(message.getId(), message.expectsResponse(), currentPayload);
    ctx.fireChannelRead(request);
    reset();
  } else {
    if (currentPayload != null) {
      error = true;
      return;
    }
    if (msg instanceof ReferenceCounted) {
      currentPayload = ((ReferenceCounted) msg).retain();
    } else {
      currentPayload = msg;
    }
  }
}
 
开发者ID:xjdr,项目名称:xio,代码行数:36,代码来源:ServerCodec.java


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