Class ResponseObserver

java.lang.Object
org.simpleframework.http.core.ResponseObserver
All Implemented Interfaces:
BodyObserver

class ResponseObserver extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    private Channel
    This is the channel associated with the client connection.
    This flag determines whether the connection was closed.
    This is used to determine if the response has committed.
    private Controller
    This is the controller used to initiate a new request.
    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

    Constructors
    Constructor
    Description
    ResponseObserver(Controller controller, Entity entity)
    Constructor for the ResponseObserver object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close(ByteWriter writer)
    This is used to close the underlying transport.
    void
    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
    This represents the time at which the response was either ready, closed or in error.
    boolean
    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
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • committed

      private AtomicBoolean committed
      This is used to determine if the response has committed.
    • closed

      private AtomicBoolean closed
      This flag determines whether the connection was closed.
    • error

      private AtomicBoolean error
      This flag determines whether the was a response error.
    • controller

      private Controller controller
      This is the controller used to initiate a new request.
    • channel

      private Channel channel
      This is the channel associated with the client connection.
    • trace

      private Trace trace
      This is the trace used to observe the state of the stream.
    • timer

      private Timer timer
      This represents a time stamp that records the finish time.
  • Constructor Details

    • ResponseObserver

      public ResponseObserver(Controller controller, Entity entity)
      Constructor for the ResponseObserver 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 channels
      entity - this is the entity associated with the channel
  • Method Details

    • close

      public void close(ByteWriter writer)
      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 interface BodyObserver
      Parameters:
      writer - this is the writer used to send the response
    • error

      public void error(ByteWriter writer)
      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 interface BodyObserver
      Parameters:
      writer - this is the writer used to send the response
    • ready

      public void ready(ByteWriter writer)
      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 interface BodyObserver
      Parameters:
      writer - this is the writer used to send the response
    • fail

      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. 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

      public 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. It is also used to indicate whether the response can be reset.
      Specified by:
      commit in interface BodyObserver
      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 interface BodyObserver
      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 interface BodyObserver
      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 interface BodyObserver
      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 interface BodyObserver
      Returns:
      the time when the response completed or failed