Package one.nio.http

Class EventSourceResponse

java.lang.Object
one.nio.http.Response
one.nio.http.EventSourceResponse
All Implemented Interfaces:
Closeable, AutoCloseable, EventSource<String>

public class EventSourceResponse extends Response implements EventSource<String>
A Response, which can poll for server emitted events. Unlike regular Response this object must be close'd to prevent resource leak.

The usage flow is as follows:

  1. Call HttpClient.openEvents(Request, int)
  2. Inspect the result code, if it is not OK process the error
  3. Inspect the content-type, it must be text/event-stream; if it is not - process the response body - there will be no events
  4. while ( ( event = poll() ) != null ) process( event )
  5. call close()
  6. call HttpClient.reopenEvents(Request, String, int) with last processed EventSource.Event.id() and go to p.2
See Also: