use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class FormPostRequestHandler method close.
@SuppressWarnings("try")
@Override
public void close(final CompletionHandler completionHandler) {
try (final ResourceReference ref = requestReference) {
final byte[] requestContentBytes = accumulatedRequestContent.toByteArray();
final String content = new String(requestContentBytes, contentCharset);
completionHandler.completed();
final Map<String, List<String>> parameterMap = parseFormParameters(content);
mergeParameters(parameterMap, request.parameters());
final ContentChannel contentChannel = delegateHandler.handleRequest(request, responseHandler);
if (contentChannel != null) {
if (!removeBody) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(requestContentBytes);
contentChannel.write(byteBuffer, NOOP_COMPLETION_HANDLER);
}
contentChannel.close(NOOP_COMPLETION_HANDLER);
}
}
}
use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class FilterTestCase method requireThatResponseFilterChainRetainsFilters.
@Test
public void requireThatResponseFilterChainRetainsFilters() {
final ResponseFilter responseFilter1 = mock(ResponseFilter.class);
final ResponseFilter responseFilter2 = mock(ResponseFilter.class);
verify(responseFilter1, never()).refer();
verify(responseFilter2, never()).refer();
final ResourceReference reference1 = mock(ResourceReference.class);
final ResourceReference reference2 = mock(ResourceReference.class);
when(responseFilter1.refer()).thenReturn(reference1);
when(responseFilter2.refer()).thenReturn(reference2);
final ResponseFilter chain = ResponseFilterChain.newInstance(responseFilter1, responseFilter2);
verify(responseFilter1, times(1)).refer();
verify(responseFilter2, times(1)).refer();
verify(reference1, never()).close();
verify(reference2, never()).close();
chain.release();
verify(reference1, times(1)).close();
verify(reference2, times(1)).close();
}
use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class ReferenceCountingRequestHandler method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler responseHandler) {
try (final ResourceReference requestReference = request.refer()) {
ContentChannel contentChannel;
final ReferenceCountingResponseHandler referenceCountingResponseHandler = new ReferenceCountingResponseHandler(request, new NullContentResponseHandler(responseHandler));
try {
contentChannel = delegate.handleRequest(request, referenceCountingResponseHandler);
Objects.requireNonNull(contentChannel, "contentChannel");
} catch (Throwable t) {
try {
// The response handler might never be invoked, due to the exception thrown from handleRequest().
referenceCountingResponseHandler.unrefer();
} catch (Throwable thrownFromUnrefer) {
log.log(Level.WARNING, "Unexpected problem", thrownFromUnrefer);
}
throw t;
}
return new ReferenceCountingContentChannel(request, contentChannel);
}
}
use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class ResourcePoolTestCase method requireThatResourcesAreReleasedOnDestroy.
@Test
public void requireThatResourcesAreReleasedOnDestroy() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ResourcePool pool = new ResourcePool(driver.newContainerBuilder());
MyResource foo = pool.add(new MyResource());
MyResource bar = pool.add(new MyResource());
MyResource baz = pool.add(new MyResource());
assertEquals(1, pool.retainCount());
assertEquals(1, foo.retainCount());
assertEquals(1, bar.retainCount());
assertEquals(1, baz.retainCount());
final ResourceReference secondPoolReference = pool.refer();
assertEquals(2, pool.retainCount());
assertEquals(1, foo.retainCount());
assertEquals(1, bar.retainCount());
assertEquals(1, baz.retainCount());
secondPoolReference.close();
assertEquals(1, pool.retainCount());
assertEquals(1, foo.retainCount());
assertEquals(1, bar.retainCount());
assertEquals(1, baz.retainCount());
pool.release();
assertEquals(0, pool.retainCount());
assertEquals(0, foo.retainCount());
assertEquals(0, bar.retainCount());
assertEquals(0, baz.retainCount());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.ResourceReference in project vespa by vespa-engine.
the class ClientTestDriver method newClientRequest.
public Request newClientRequest(Message msg) {
msg.setRoute(Route.parse(server.connectionSpec()));
if (msg.getTrace().getLevel() == 0) {
msg.getTrace().setLevel(9);
}
final Request parent = newServerRequest();
try (final ResourceReference ref = References.fromResource(parent)) {
return new MbusRequest(parent, URI.create("mbus://remotehost/"), msg);
}
}
Aggregations