use of io.servicetalk.concurrent.api.internal.ConnectableBufferOutputStream in project servicetalk by apple.
the class DefaultContainerResponseWriter method writeResponseStatusAndHeaders.
@Nullable
@Override
public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse responseContext) throws ContainerException {
if (!stateUpdater.compareAndSet(this, STATE_REQUEST_HANDLING, STATE_RESPONSE_WRITING)) {
// Request has been cancelled so we do not send a response and return no OutputStream for Jersey to write to
return null;
}
final Publisher<Buffer> content = getResponseBufferPublisher(request);
// contentLength is >= 0 if the entity content length in bytes is known to Jersey, otherwise -1
if (content != null) {
sendResponse(UNKNOWN_RESPONSE_LENGTH, content, responseContext);
return null;
} else if (contentLength == 0 || isHeadRequest()) {
sendResponse(contentLength, null, responseContext);
return null;
} else if (contentLength > 0) {
// Jersey has buffered the full response body: bypass streaming response and use an optimized path instead
return new BufferedResponseOutputStream(serviceCtx.executionContext().bufferAllocator(), buf -> sendResponse(contentLength, Publisher.from(buf), responseContext));
}
// OIO adapted streaming response of unknown length
final ConnectableBufferOutputStream os = new ConnectableBufferOutputStream(serviceCtx.executionContext().bufferAllocator());
sendResponse(contentLength, os.connect(), responseContext);
return new CopyingOutputStream(os);
}
use of io.servicetalk.concurrent.api.internal.ConnectableBufferOutputStream in project servicetalk by apple.
the class ConnectableBufferOutputStreamBenchmark method setup.
@Setup(Level.Iteration)
public void setup() {
data = new byte[dataSize];
cbos = new ConnectableBufferOutputStream(PREFER_HEAP_ALLOCATOR);
publisher = cbos.connect();
// Don't remove this, JMH somehow provides a default which break everything
subscription = null;
}
Aggregations