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 ChannelThis is the channel associated with the client connection.private AtomicBooleanThis flag determines whether the connection was closed.private AtomicBooleanThis is used to determine if the response has committed.private ControllerThis is the controller used to initiate a new request.private AtomicBooleanThis flag determines whether the was a response error.private TimerThis represents a time stamp that records the finish time.private TraceThis is the trace used to observe the state of the stream. -
Constructor Summary
ConstructorsConstructorDescriptionResponseObserver(Controller controller, Entity entity) Constructor for theResponseObserverobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose(ByteWriter writer) This is used to close the underlying transport.voidcommit(ByteWriter writer) This is used to notify the observer that the HTTP response is committed and that the header can no longer be changed.voiderror(ByteWriter writer) This is used when there is an error sending the response.private voidfail(ByteWriter writer) This is used to purge the writer so that it closes the socket ensuring there is no connection leak on shutdown.longgetTime()This represents the time at which the response was either ready, closed or in error.booleanisClosed()This is used to determine if the response has completed or if there has been an error.booleanThis can be used to determine whether the response has been committed.booleanisError()This is used to determine if the response was in error.voidready(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 theResponseObserverobject. 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:
closein 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:
errorin 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:
readyin 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:
commitin 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:
isCommittedin 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:
isClosedin 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:
isErrorin 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:
getTimein interfaceBodyObserver- Returns:
- the time when the response completed or failed
-