public abstract static class SseEventSource.Builder extends Object
SseEventSource builder class.
Event source builder provides methods that let you conveniently configure and subsequently build
a new EventSource instance. You can obtain a new event source builder instance using
a static EventSource.target(endpoint) factory method.
For example:
EventSource es = EventSource.target(endpoint).named("my source")
.reconnectingEvery(5, SECONDS)
.open();
| Modifier and Type | Field and Description |
|---|---|
static String |
JAXRS_DEFAULT_SSE_BUILDER_PROPERTY
Name of the property identifying the
SseEventSource.Builder implementation
to be returned from newBuilder(). |
| Modifier | Constructor and Description |
|---|---|
protected |
Builder()
Allows custom implementations to extend the SSE event source builder class.
|
| Modifier and Type | Method and Description |
|---|---|
abstract SseEventSource |
build()
Build new SSE event source pointing at a SSE streaming
web target. |
abstract SseEventSource.Builder |
named(String name)
Set a custom name for the event source.
|
abstract SseEventSource |
open()
Build new SSE event source pointing at a SSE streaming
web target. |
abstract SseEventSource.Builder |
reconnectingEvery(long delay,
TimeUnit unit)
Set the initial reconnect delay to be used by the event source.
|
abstract SseEventSource.Builder |
register(SseEventSource.Listener listener)
Register new
event listener to receive all streamed SSE events. |
abstract SseEventSource.Builder |
register(SseEventSource.Listener listener,
String eventName,
String... eventNames)
Add name-bound
event listener which will be called only for incoming SSE
events whose name is equal to the specified
name(s). |
protected abstract SseEventSource.Builder |
target(WebTarget endpoint) |
public static final String JAXRS_DEFAULT_SSE_BUILDER_PROPERTY
SseEventSource.Builder implementation
to be returned from newBuilder().protected Builder()
protected abstract SseEventSource.Builder target(WebTarget endpoint)
public abstract SseEventSource.Builder named(String name)
At present, custom event source name is mainly useful to be able to distinguish different event source event processing threads from one another. If not set, a default name will be generated using the SSE endpoint URI.
name - custom event source name.public abstract SseEventSource.Builder reconnectingEvery(long delay, TimeUnit unit)
Note that this value may be later overridden by the SSE endpoint using either a retry SSE event field
or HTTP 503 + "Retry-After" mechanism as described
in the SseEventSource javadoc.
delay - the default time to wait before attempting to recover from a connection loss.unit - time unit of the reconnect delay parameter.public abstract SseEventSource.Builder register(SseEventSource.Listener listener)
event listener to receive all streamed SSE events.listener - event listener to be registered with the event source.register(SseEventSource.Listener, String, String...)public abstract SseEventSource.Builder register(SseEventSource.Listener listener, String eventName, String... eventNames)
event listener which will be called only for incoming SSE
events whose name is equal to the specified
name(s).listener - event listener to register with this event source.eventName - inbound event name.eventNames - additional event names.register(SseEventSource.Listener)public abstract SseEventSource build()
web target.
The returned event source is ready, but not connected to the SSE endpoint.
It is expected that you will manually invoke its open() method once you are ready to start
receiving SSE events. In case you want to build an event source instance that is already connected
to the SSE endpoint, use the event source builder open() method instead.
Once the event source is open, the incoming events are processed by the event source in an
asynchronous task that runs in an internal single-threaded scheduled executor service.
open()public abstract SseEventSource open()
web target.
The returned event source is already connected to the SSE endpoint
and is processing any new incoming events. In case you want to build an event source instance
that is already ready, but not automatically connected to the SSE endpoint, use the event source
builder build() method instead.
The incoming events are processed by the event source in an asynchronous task that runs in an
internal single-threaded scheduled executor service.
build()Copyright © 1996-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.