Package org.simpleframework.http.core
Class ResponseObserver
java.lang.Object
org.simpleframework.http.core.ResponseObserver
- All Implemented Interfaces:
BodyObserver
The
ResponseObserver
is used to observe the response
streams. If there is an error or a close requested this will
close the underlying transport. If however there is a successful
response then this will flush the transport and hand the channel
for the pipeline back to the server kernel. This ensures that
the next HTTP request can be consumed from the transport.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Channel
This is the channel associated with the client connection.private AtomicBoolean
This flag determines whether the connection was closed.private AtomicBoolean
This is used to determine if the response has committed.private Controller
This is the controller used to initiate a new request.private AtomicBoolean
This flag determines whether the was a response error.private Timer
This represents a time stamp that records the finish time.private Trace
This is the trace used to observe the state of the stream. -
Constructor Summary
ConstructorsConstructorDescriptionResponseObserver
(Controller controller, Entity entity) Constructor for theResponseObserver
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(ByteWriter writer) This is used to close the underlying transport.void
commit
(ByteWriter writer) This is used to notify the observer that the HTTP response is committed and that the header can no longer be changed.void
error
(ByteWriter writer) This is used when there is an error sending the response.private void
fail
(ByteWriter writer) This is used to purge the writer so that it closes the socket ensuring there is no connection leak on shutdown.long
getTime()
This represents the time at which the response was either ready, closed or in error.boolean
isClosed()
This is used to determine if the response has completed or if there has been an error.boolean
This can be used to determine whether the response has been committed.boolean
isError()
This is used to determine if the response was in error.void
ready
(ByteWriter writer) This is used when the response has been sent correctly and the connection supports persisted HTTP.
-
Field Details
-
committed
This is used to determine if the response has committed. -
closed
This flag determines whether the connection was closed. -
error
This flag determines whether the was a response error. -
controller
This is the controller used to initiate a new request. -
channel
This is the channel associated with the client connection. -
trace
This is the trace used to observe the state of the stream. -
timer
This represents a time stamp that records the finish time.
-
-
Constructor Details
-
ResponseObserver
Constructor for theResponseObserver
object. This is used to create an observer using a HTTP request entity and an initiator which is used to reprocess a channel if there was a successful deliver of a response.- Parameters:
controller
- the controller used to process channelsentity
- this is the entity associated with the channel
-
-
Method Details
-
close
This is used to close the underlying transport. A closure is typically done when the response is to a HTTP/1.0 client that does not require a keep alive connection. Also, if the container requests an explicit closure this is used when all of the content for the response has been sent.- Specified by:
close
in interfaceBodyObserver
- Parameters:
writer
- this is the writer used to send the response
-
error
This is used when there is an error sending the response. On error RFC 2616 suggests a connection closure is the best means to handle the condition, and the one clients should be expecting and support. All errors result in closure of the underlying transport and no more requests are processed.- Specified by:
error
in interfaceBodyObserver
- Parameters:
writer
- this is the writer used to send the response
-
ready
This is used when the response has been sent correctly and the connection supports persisted HTTP. When ready the channel is handed back in to the server kernel where the next request on the pipeline is read and used to compose the next entity.- Specified by:
ready
in interfaceBodyObserver
- Parameters:
writer
- this is the writer used to send the response
-
fail
This is used to purge the writer so that it closes the socket ensuring there is no connection leak on shutdown. This is used when there is an exception signalling the state of the writer.- Parameters:
writer
- this is the writer that is to be purged
-
commit
This is used to notify the observer that the HTTP response is committed and that the header can no longer be changed. It is also used to indicate whether the response can be reset.- Specified by:
commit
in interfaceBodyObserver
- Parameters:
writer
- this is the writer used to send the response
-
isCommitted
public boolean isCommitted()This can be used to determine whether the response has been committed. If the response is committed then the header can no longer be manipulated and the response has been partially send to the client.- Specified by:
isCommitted
in interfaceBodyObserver
- Returns:
- true if the response headers have been committed
-
isClosed
public boolean isClosed()This is used to determine if the response has completed or if there has been an error. This basically allows the writer of the response to take action on certain I/O events.- Specified by:
isClosed
in interfaceBodyObserver
- Returns:
- this returns true if there was an error or close
-
isError
public boolean isError()This is used to determine if the response was in error. If the response was in error this allows the writer to throw an exception indicating that there was a problem responding.- Specified by:
isError
in interfaceBodyObserver
- Returns:
- this returns true if there was a response error
-
getTime
public long getTime()This represents the time at which the response was either ready, closed or in error. Providing a time here is useful as it allows the time taken to generate a response to be determined even if the response is written asynchronously.- Specified by:
getTime
in interfaceBodyObserver
- Returns:
- the time when the response completed or failed
-