@Test public void closeTest() throws RestServiceException { Channel channel = new MockChannel(); NettyRequest nettyRequest = createNettyRequest(HttpMethod.POST, "/", null, channel); Queue<HttpContent> httpContents = new LinkedBlockingQueue<HttpContent>(); for (int i = 0; i < 5; i++) { ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes(1024)); HttpContent httpContent = new DefaultHttpContent(Unpooled.wrappedBuffer(content)); nettyRequest.addContent(httpContent); httpContents.add(httpContent); } closeRequestAndValidate(nettyRequest, channel); while (httpContents.peek() != null) { assertEquals("Reference count of http content has changed", 1, httpContents.poll().refCnt()); } }
@Override public void close() { if (channelOpen.compareAndSet(true, false)) { setAutoRead(true); contentLock.lock(); try { logger.trace("Closing NettyRequest {} with {} content chunks unread", getUri(), requestContents.size()); HttpContent content = requestContents.poll(); while (content != null) { ReferenceCountUtil.release(content); content = requestContents.poll(); } } finally { contentLock.unlock(); restRequestMetricsTracker.nioMetricsTracker.markRequestCompleted(); if (digestCalculationTimeInMs >= 0) { nettyMetrics.digestCalculationTimeInMs.update(digestCalculationTimeInMs); } if (callbackWrapper != null) { callbackWrapper.invokeCallback(channelException); } } } }
NettyRequest implements RestRequest { @Override public void close() { if (channelOpen.compareAndSet(true, false)) { setAutoRead(true); contentLock.lock(); try { logger.trace("Closing NettyRequest {} with {} content chunks unread", getUri(), requestContents.size()); HttpContent content = requestContents.poll(); while (content != null) { ReferenceCountUtil.release(content); content = requestContents.poll(); } } finally { contentLock.unlock(); restRequestMetricsTracker.nioMetricsTracker.markRequestCompleted(); if (digestCalculationTimeInMs >= 0) { nettyMetrics.digestCalculationTimeInMs.update(digestCalculationTimeInMs); } if (callbackWrapper != null) { callbackWrapper.invokeCallback(channelException); } } } } }
NettyRequest implements RestRequest { @Override public void close() { if (channelOpen.compareAndSet(true, false)) { setAutoRead(true); contentLock.lock(); try { logger.trace("Closing NettyRequest {} with {} content chunks unread", getUri(), requestContents.size()); HttpContent content = requestContents.poll(); while (content != null) { ReferenceCountUtil.release(content); content = requestContents.poll(); } } finally { contentLock.unlock(); restRequestMetricsTracker.nioMetricsTracker.markRequestCompleted(); if (digestCalculationTimeInMs >= 0) { nettyMetrics.digestCalculationTimeInMs.update(digestCalculationTimeInMs); } if (callbackWrapper != null) { callbackWrapper.invokeCallback(channelException); } } } } NettyRequest(HttpRequest request, Channel channel, NettyMetrics nettyMetrics,
      Set<String> blacklistedQueryParams); }
NettyRequest implements RestRequest { @Override public void close() { if (channelOpen.compareAndSet(true, false)) { setAutoRead(true); contentLock.lock(); try { logger.trace("Closing NettyRequest {} with {} content chunks unread", getUri(), requestContents.size()); HttpContent content = requestContents.poll(); while (content != null) { ReferenceCountUtil.release(content); content = requestContents.poll(); } } finally { contentLock.unlock(); restRequestMetricsTracker.nioMetricsTracker.markRequestCompleted(); if (digestCalculationTimeInMs >= 0) { nettyMetrics.digestCalculationTimeInMs.update(digestCalculationTimeInMs); } if (callbackWrapper != null) { callbackWrapper.invokeCallback(channelException); } } } } NettyRequest(HttpRequest request, Channel channel, NettyMetrics nettyMetrics,
      Set<String> blacklistedQueryParams); @Override String getUri(); @Override String getPath(); @Override RestMethod getRestMethod(); @Override Map<String, Object> getArgs(); @Override Object setArg(String key, Object value); @Override SSLSession getSSLSession(); @Override void prepare(); @Override boolean isOpen(); @Override void close(); @Override RestRequestMetricsTracker getMetricsTracker(); @Override String toString(); @Override long getSize(); @Override Future<Long> readInto(AsyncWritableChannel asyncWritableChannel, Callback<Long> callback); @Override void setDigestAlgorithm(String digestAlgorithm); @Override byte[] getDigest(); @Override long getBytesReceived(); @Override long getBlobBytesReceived(); @Override NettyRequestContext getRestRequestContext(); }
NettyRequest implements RestRequest { @Override public void close() { if (channelOpen.compareAndSet(true, false)) { setAutoRead(true); contentLock.lock(); try { logger.trace("Closing NettyRequest {} with {} content chunks unread", getUri(), requestContents.size()); HttpContent content = requestContents.poll(); while (content != null) { ReferenceCountUtil.release(content); content = requestContents.poll(); } } finally { contentLock.unlock(); restRequestMetricsTracker.nioMetricsTracker.markRequestCompleted(); if (digestCalculationTimeInMs >= 0) { nettyMetrics.digestCalculationTimeInMs.update(digestCalculationTimeInMs); } if (callbackWrapper != null) { callbackWrapper.invokeCallback(channelException); } } } } NettyRequest(HttpRequest request, Channel channel, NettyMetrics nettyMetrics,
      Set<String> blacklistedQueryParams); @Override String getUri(); @Override String getPath(); @Override RestMethod getRestMethod(); @Override Map<String, Object> getArgs(); @Override Object setArg(String key, Object value); @Override SSLSession getSSLSession(); @Override void prepare(); @Override boolean isOpen(); @Override void close(); @Override RestRequestMetricsTracker getMetricsTracker(); @Override String toString(); @Override long getSize(); @Override Future<Long> readInto(AsyncWritableChannel asyncWritableChannel, Callback<Long> callback); @Override void setDigestAlgorithm(String digestAlgorithm); @Override byte[] getDigest(); @Override long getBytesReceived(); @Override long getBlobBytesReceived(); @Override NettyRequestContext getRestRequestContext();  }