private static class ApplicationHandler.FutureResponseWriter extends com.google.common.util.concurrent.AbstractFuture<ContainerResponse> implements ContainerResponseWriter
ContainerResponseWriter.TimeoutHandler
Modifier and Type | Field and Description |
---|---|
private java.io.OutputStream |
outputStream |
private java.lang.String |
requestMethodName |
private JerseyRequestTimeoutHandler |
requestTimeoutHandler |
private ContainerResponse |
response |
Modifier | Constructor and Description |
---|---|
private |
FutureResponseWriter(java.lang.String requestMethodName,
java.io.OutputStream outputStream,
java.util.concurrent.ScheduledExecutorService backgroundScheduler) |
Modifier and Type | Method and Description |
---|---|
void |
commit()
Commit the response & close the container response writer.
|
boolean |
enableResponseBuffering()
Return
true if the entity buffering should be enabled in Jersey. |
void |
failure(java.lang.Throwable error)
Propagate an unhandled error to the I/O container.
|
protected void |
interruptTask() |
void |
setSuspendTimeout(long time,
java.util.concurrent.TimeUnit unit)
Set the suspend timeout.
|
boolean |
suspend(long time,
java.util.concurrent.TimeUnit unit,
ContainerResponseWriter.TimeoutHandler handler)
Suspend the request/response processing.
|
java.io.OutputStream |
writeResponseStatusAndHeaders(long contentLength,
ContainerResponse response)
Write the status and headers of the response and return an output stream
for the web application to write the entity of the response.
|
private ContainerResponse response
private final java.lang.String requestMethodName
private final java.io.OutputStream outputStream
private final JerseyRequestTimeoutHandler requestTimeoutHandler
private FutureResponseWriter(java.lang.String requestMethodName, java.io.OutputStream outputStream, java.util.concurrent.ScheduledExecutorService backgroundScheduler)
public java.io.OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse response)
ContainerResponseWriter
If the response content length is declared to be greater or equal to 0, it
means that the content length in bytes of the entity to be written is known,
otherwise -1. I/O containers may use this value to determine whether the
"Content-Length"
header can be set or utilize chunked transfer encoding.
writeResponseStatusAndHeaders
in interface ContainerResponseWriter
contentLength
- greater or equal to 0 if the content length in bytes
of the entity to be written is known, otherwise -1. Containers
may use this value to determine whether the "Content-Length"
header can be set or utilize chunked transfer encoding.response
- the JAX-RS response to be written. The status and headers
are obtained from the response.public boolean suspend(long time, java.util.concurrent.TimeUnit unit, ContainerResponseWriter.TimeoutHandler handler)
ContainerResponseWriter
true
to indicate the response writer was suspended successfully.
In case the provider has already been suspended earlier, the method returns false
.
I/O container must not automatically commit
the response writer
when the processing on the I/O container thread is finished and the thread is
released. Instead, the Jersey runtime will make sure to manually close
the container response writer instance by explicitly calling the ContainerResponseWriter.commit()
or ContainerResponseWriter.failure(Throwable)
method at some later point in time.
Once suspended, the specified suspend timeout can be further updated using
ContainerResponseWriter.setSuspendTimeout(long, java.util.concurrent.TimeUnit)
method.
suspend
in interface ContainerResponseWriter
time
- time-out value. Value less or equal to 0, indicates that
the processing is suspended indefinitely.unit
- time-out time unit.handler
- time-out handler to process a time-out event if it
occurs.true
if the suspend operation completed successfully, false
otherwise.ContainerResponseWriter.setSuspendTimeout(long, TimeUnit)
,
ContainerResponseWriter.commit()
public void setSuspendTimeout(long time, java.util.concurrent.TimeUnit unit)
ContainerResponseWriter
setSuspendTimeout
in interface ContainerResponseWriter
time
- time-out value. Value less or equal to 0, indicates that
the processing is suspended indefinitely.unit
- time-out time unit.public void commit()
ContainerResponseWriter
commit
in interface ContainerResponseWriter
ContainerResponseWriter.suspend(long, TimeUnit, TimeoutHandler)
,
ContainerResponseWriter.failure(Throwable)
public void failure(java.lang.Throwable error)
ContainerResponseWriter
failure
in interface ContainerResponseWriter
error
- unhandled request processing error.ContainerResponseWriter.suspend(long, TimeUnit, TimeoutHandler)
,
ContainerResponseWriter.commit()
public boolean enableResponseBuffering()
ContainerResponseWriter
true
if the entity buffering should be enabled in Jersey.
If enabled, the outbound entity is buffered by Jersey runtime up to a configured amount of bytes
prior to being written to the output stream to determine its size that may be used to set the value
of HTTP "Content-Length" header.
Containers that provide it's own solution for determining the message payload size may decide to
return false
to prevent Jersey from buffering message entities unnecessarily.
enableResponseBuffering
in interface ContainerResponseWriter
true
to enable entity buffering to be done by Jersey runtime, false
otherwise.protected void interruptTask()
interruptTask
in class com.google.common.util.concurrent.AbstractFuture<ContainerResponse>