Package com.linecorp.armeria.common
Interface HttpRequestDuplicator
- All Superinterfaces:
AutoCloseable
,SafeCloseable
,StreamMessageDuplicator<HttpObject>
A duplicator that duplicates a
HttpRequest
into one or more HttpRequest
s,
which publish the same elements.
HttpRequest req = ...
try (HttpRequestDuplicator duplicator = req.toDuplicator()) {
// req.subscribe(...) will throw an exception. You cannot subscribe to req anymore.
// Duplicate the request as many as you want to subscribe.
HttpRequest duplicatedRequest = duplicator.duplicate();
HttpRequest duplicatedRequest = duplicator.duplicate();
duplicatedRequest.subscribe(...);
duplicatedRequest.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 request 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 newHttpRequest
that publishes the sameHttpData
s and trailers as theHttpRequest
that this duplicator is created from.duplicate(RequestHeaders newHeaders)
Returns a newHttpRequest
with the specifiedRequestHeaders
that publishes the sameHttpData
s and trailers as theHttpRequest
that this duplicator is created from.headers()
Returns theRequestHeaders
.Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessageDuplicator
abort, abort, close
-
Method Details
-
headers
RequestHeaders headers()Returns theRequestHeaders
. -
duplicate
Returns a newHttpRequest
that publishes the sameHttpData
s and trailers as theHttpRequest
that this duplicator is created from.- Specified by:
duplicate
in interfaceStreamMessageDuplicator<HttpObject>
-
duplicate
Returns a newHttpRequest
with the specifiedRequestHeaders
that publishes the sameHttpData
s and trailers as theHttpRequest
that this duplicator is created from.
-