Package com.linecorp.armeria.common
Interface HttpResponseDuplicator
- All Superinterfaces:
AutoCloseable
,SafeCloseable
,StreamMessageDuplicator<HttpObject>
A duplicator that duplicates a
HttpResponse
into one or more HttpResponse
s,
which publish the same elements.
HttpResponse res = ...
try (HttpResponseDuplicator duplicator = res.toDuplicator()) {
// res.subscribe(...) will throw an exception. You cannot subscribe to res anymore.
// Duplicate the response as many as you want to subscribe.
HttpResponse duplicatedResponse1 = duplicator.duplicate();
HttpResponse duplicatedResponse2 = duplicator.duplicate();
duplicatedResponse1.subscribe(...);
duplicatedResponse2.subscribe(...);
}
Use the try-with-resources
block or call StreamMessageDuplicator.close()
manually to clean up the resources
after all subscriptions are done. If you want to stop publishing and clean up the resources immediately,
call StreamMessageDuplicator.abort()
. If you do none of these, memory leak might happen.
If you subscribe to the duplicated http response with the
SubscriptionOption.WITH_POOLED_OBJECTS
, the published elements can be shared across
Subscriber
s. So do not manipulate the data unless you copy them.
-
Method Summary
Modifier and TypeMethodDescriptionReturns a newHttpResponse
that publishes the sameResponseHeaders
,HttpData
s and trailers as theHttpResponse
that this duplicator is created from.Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessageDuplicator
abort, abort, close
-
Method Details
-
duplicate
Returns a newHttpResponse
that publishes the sameResponseHeaders
,HttpData
s and trailers as theHttpResponse
that this duplicator is created from.- Specified by:
duplicate
in interfaceStreamMessageDuplicator<HttpObject>
-