public interface ServerSentEmitter
sse("/pattern", sse -> {
sse.send("Hello Server-Sent events");
})
Modifier and Type | Interface and Description |
---|---|
static interface |
ServerSentEmitter.Handler
Server-Sent event handler.
|
static class |
ServerSentEmitter.KeepAlive
Keep-alive task.
|
Modifier and Type | Method and Description |
---|---|
default <T> T |
attribute(String key)
Get an attribute by his key.
|
default ServerSentEmitter |
attribute(String key,
Object value)
Set an application attribute.
|
void |
close()
Close the ServerSent and fir the close event.
|
default Map<String,Object> |
getAttributes()
Context attributes (a.k.a request attributes).
|
Context |
getContext()
Originating HTTP context.
|
String |
getId()
Server-Sent ID.
|
default String |
getLastEventId()
Read the
Last-Event-ID header and retrieve it. |
boolean |
isOpen()
True if connection is open.
|
ServerSentEmitter |
keepAlive(long timeInMillis)
Send a comment message to the client.
|
default ServerSentEmitter |
keepAlive(long time,
TimeUnit unit)
Send a comment message to the client.
|
default <T> T |
lastEventId(Class<T> type)
Read the
Last-Event-ID header and retrieve it. |
void |
onClose(SneakyThrows.Runnable task)
Generated when client close the connection or when explicit calls to
close() . |
default ServerSentEmitter |
send(byte[] data)
Send a text message to client.
|
default ServerSentEmitter |
send(Object data)
Send a text message to client.
|
ServerSentEmitter |
send(ServerSentMessage data)
Send a message to the client.
|
default ServerSentEmitter |
send(String data)
Send a text message to client.
|
default ServerSentEmitter |
send(String event,
Object data)
Send a message to the client and set the event type attribute.
|
ServerSentEmitter |
setId(String id)
Set Server-Sent ID.
|
void onClose(SneakyThrows.Runnable task)
close()
.task
- Cleanup task.@Nonnull Context getContext()
@Nonnull default Map<String,Object> getAttributes()
@Nonnull default <T> T attribute(@Nonnull String key)
getAttributes()
.
This method look first in current context and fallback to application attributes.T
- Attribute type.key
- Attribute key.@Nonnull default ServerSentEmitter attribute(@Nonnull String key, Object value)
key
- Attribute key.value
- Attribute value.@Nonnull default ServerSentEmitter send(@Nonnull String data)
data
- Text Message.@Nonnull default ServerSentEmitter send(@Nonnull byte[] data)
data
- Text Message.@Nonnull default ServerSentEmitter send(@Nonnull Object data)
data
- Text Message.@Nonnull default ServerSentEmitter send(@Nonnull String event, @Nonnull Object data)
event
- Event type.data
- Message.@Nonnull ServerSentEmitter send(@Nonnull ServerSentMessage data)
data
- Message.@Nonnull default ServerSentEmitter keepAlive(long time, @Nonnull TimeUnit unit)
time
- Period of time.unit
- Time unit.@Nonnull ServerSentEmitter keepAlive(long timeInMillis)
timeInMillis
- Period of time in millis.@Nullable default String getLastEventId()
Last-Event-ID
header and retrieve it. Might be null.null
.@Nullable default <T> T lastEventId(Class<T> type)
Last-Event-ID
header and retrieve it. Might be null.T
- Type to convert.type
- Type to convert.null
.@Nonnull String getId()
@Nonnull ServerSentEmitter setId(@Nonnull String id)
id
- Set Server-Sent ID.boolean isOpen()
void close()
Copyright © 2020. All rights reserved.