public final class RealEventSource extends java.lang.Object implements EventSource, ServerSentEventReader.Callback, Callback
EventSource.Factory
Modifier and Type | Field and Description |
---|---|
private Call |
call |
private EventSourceListener |
listener |
private Request |
request |
Constructor and Description |
---|
RealEventSource(Request request,
EventSourceListener listener) |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Immediately and violently release resources held by this event source.
|
void |
connect(OkHttpClient client) |
private static boolean |
isEventStream(MediaType contentType) |
void |
onEvent(java.lang.String id,
java.lang.String type,
java.lang.String data) |
void |
onFailure(Call call,
java.io.IOException e)
Called when the request could not be executed due to cancellation, a connectivity problem or
timeout.
|
void |
onResponse(Call call,
Response response)
Called when the HTTP response was successfully returned by the remote server.
|
void |
onRetryChange(long timeMs) |
void |
processResponse(Response response) |
Request |
request()
Returns the original request that initiated this event source.
|
private final Request request
private final EventSourceListener listener
@Nullable private Call call
public RealEventSource(Request request, EventSourceListener listener)
public void connect(OkHttpClient client)
public void onResponse(Call call, Response response)
Callback
Response.body
. The response is still live until
its response body is closed. The recipient of the callback may
consume the response body on another thread.
Note that transport-layer success (receiving a HTTP response code, headers and body) does
not necessarily indicate application-layer success: response
may still indicate an
unhappy HTTP response code like 404 or 500.
onResponse
in interface Callback
public void processResponse(Response response)
private static boolean isEventStream(@Nullable MediaType contentType)
public void onFailure(Call call, java.io.IOException e)
Callback
public Request request()
EventSource
request
in interface EventSource
public void cancel()
EventSource
cancel
in interface EventSource
public void onEvent(@Nullable java.lang.String id, @Nullable java.lang.String type, java.lang.String data)
onEvent
in interface ServerSentEventReader.Callback
public void onRetryChange(long timeMs)
onRetryChange
in interface ServerSentEventReader.Callback