Package com.linecorp.armeria.common
Class HttpResponseDuplicator
- java.lang.Object
-
- com.linecorp.armeria.common.stream.AbstractStreamMessageDuplicator<HttpObject,HttpResponse>
-
- com.linecorp.armeria.common.HttpResponseDuplicator
-
- All Implemented Interfaces:
SafeCloseable
,AutoCloseable
public class HttpResponseDuplicator extends AbstractStreamMessageDuplicator<HttpObject,HttpResponse>
Allows subscribing to anHttpResponse
multiple times by duplicating the stream.> final HttpResponse originalRes = ... > final HttpResponseDuplicator resDuplicator = new HttpResponseDuplicator(originalRes); > > final HttpResponse dupRes1 = resDuplicator.duplicateStream(); > final HttpResponse dupRes2 = resDuplicator.duplicateStream(true); // the last stream > > dupRes1.subscribe(new FooHeaderSubscriber() { > @Override > public void onNext(Object o) { > ... > // Do something according to the header's status. > } > }); > > dupRes2.aggregate().handle((aRes, cause) -> { > // Do something with the message. > });
-
-
Constructor Summary
Constructors Constructor Description HttpResponseDuplicator(HttpResponse res)
Creates a new instance wrapping anHttpResponse
and publishing to multiple subscribers.HttpResponseDuplicator(HttpResponse res, long maxSignalLength)
Creates a new instance wrapping anHttpResponse
and publishing to multiple subscribers.HttpResponseDuplicator(HttpResponse res, long maxSignalLength, EventExecutor executor)
Creates a new instance wrapping anHttpResponse
and publishing to multiple subscribers.
-
Method Summary
Modifier and Type Method Description HttpResponse
duplicateStream()
Creates a newStreamMessage
that duplicates the upstreamStreamMessage
specified when creating this duplicator.HttpResponse
duplicateStream(boolean lastStream)
Creates a newStreamMessage
that duplicates the upstreamStreamMessage
specified when creating this duplicator.-
Methods inherited from class com.linecorp.armeria.common.stream.AbstractStreamMessageDuplicator
abort, abort, close, duplicatorExecutor
-
-
-
-
Constructor Detail
-
HttpResponseDuplicator
public HttpResponseDuplicator(HttpResponse res)
Creates a new instance wrapping anHttpResponse
and publishing to multiple subscribers. The length of response is limited by default with the client-side parameter which isFlags.defaultMaxResponseLength()
. If you are at server-side, you need to useHttpResponseDuplicator(HttpResponse, long)
and thelong
value should be greater than the length of response or0
which disables the limit.- Parameters:
res
- the response that will publish data to subscribers
-
HttpResponseDuplicator
public HttpResponseDuplicator(HttpResponse res, long maxSignalLength)
Creates a new instance wrapping anHttpResponse
and publishing to multiple subscribers.- Parameters:
res
- the response that will publish data to subscribersmaxSignalLength
- the maximum length of signals.0
disables the length limit
-
HttpResponseDuplicator
public HttpResponseDuplicator(HttpResponse res, long maxSignalLength, @Nullable EventExecutor executor)
Creates a new instance wrapping anHttpResponse
and publishing to multiple subscribers.- Parameters:
res
- the response that will publish data to subscribersmaxSignalLength
- the maximum length of signals.0
disables the length limitexecutor
- the executor to use for upstream signals.
-
-
Method Detail
-
duplicateStream
public HttpResponse duplicateStream()
Description copied from class:AbstractStreamMessageDuplicator
Creates a newStreamMessage
that duplicates the upstreamStreamMessage
specified when creating this duplicator.- Overrides:
duplicateStream
in classAbstractStreamMessageDuplicator<HttpObject,HttpResponse>
-
duplicateStream
public HttpResponse duplicateStream(boolean lastStream)
Description copied from class:AbstractStreamMessageDuplicator
Creates a newStreamMessage
that duplicates the upstreamStreamMessage
specified when creating this duplicator.- Overrides:
duplicateStream
in classAbstractStreamMessageDuplicator<HttpObject,HttpResponse>
- Parameters:
lastStream
- whether to prevent further duplication
-
-