Package one.nio.http
Class EventSourceResponse
java.lang.Object
one.nio.http.Response
one.nio.http.EventSourceResponse
- All Implemented Interfaces:
Closeable,AutoCloseable,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:
- Call
HttpClient.openEvents(Request, int) - Inspect the result code, if it is not OK process the error
- Inspect the content-type, it must be text/event-stream; if it is not - process the response body - there will be no events
- while ( ( event = poll() ) != null ) process( event )
- call
close() - call
HttpClient.reopenEvents(Request, String, int)with last processedEventSource.Event.id()and go to p.2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface one.nio.http.EventSource
EventSource.Event<D> -
Field Summary
FieldsFields inherited from class one.nio.http.Response
ACCEPTED, BAD_GATEWAY, BAD_REQUEST, CONFLICT, CONTINUE, CREATED, EMPTY, EXPECTATION_FAILED, FORBIDDEN, FOUND, GATEWAY_TIMEOUT, GONE, HTTP_VERSION_NOT_SUPPORTED, INTERNAL_ERROR, LENGTH_REQUIRED, METHOD_NOT_ALLOWED, MOVED_PERMANENTLY, MULTIPLE_CHOICES, NO_CONTENT, NON_AUTHORITATIVE_INFORMATION, NOT_ACCEPTABLE, NOT_FOUND, NOT_IMPLEMENTED, NOT_MODIFIED, OK, PARTIAL_CONTENT, PAYMENT_REQUIRED, PRECONDITION_FAILED, PROXY_AUTHENTICATION_REQUIRED, REQUEST_ENTITY_TOO_LARGE, REQUEST_TIMEOUT, REQUEST_URI_TOO_LONG, REQUESTED_RANGE_NOT_SATISFIABLE, RESET_CONTENT, SEE_OTHER, SERVICE_UNAVAILABLE, SWITCHING_PROTOCOLS, TEMPORARY_REDIRECT, UNAUTHORIZED, UNSUPPORTED_MEDIA_TYPE, USE_PROXY -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class one.nio.http.Response
addHeader, getBody, getBodyUtf8, getHeader, getHeaderCount, getHeaders, getStatus, json, ok, ok, redirect, setBody, toBytes, toString
-
Field Details
-
eventSource
-
-
Constructor Details
-
EventSourceResponse
-
-
Method Details
-
poll
Description copied from interface:EventSourceWaits for the next SSE and returns an event. The method can block for a long time ( determined by server ). It is essential to check for null andEventSource.Event.isEmpty()before processing- Specified by:
pollin interfaceEventSource<String>- Returns:
- the next event from the stream or null, if stream was closed by either party
- Throws:
IOException- an I/O exception occurredHttpException- an incorrect HTTP request received
-
setEventSource
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-