public class ServerSentEventConnection extends Object implements Channel, Attachable
Modifier and Type | Class and Description |
---|---|
static interface | ServerSentEventConnection.EventCallback |
Constructor and Description |
---|
ServerSentEventConnection(HttpServerExchange exchange, org.xnio.channels.StreamSinkChannel sink) |
Modifier and Type | Method and Description |
---|---|
void | addCloseTask(org.xnio.ChannelListener<ServerSentEventConnection> listener) Adds a listener that will be invoked when the channel is closed |
<T> void | addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value) Add a value to a list-typed attachment key. |
void | close() |
Account | getAccount() |
<T> T | getAttachment(AttachmentKey<T> key) Get an attachment value. |
<T> List<T> | getAttachmentList(AttachmentKey<? extends List<T>> key) Gets a list attachment value. |
long | getKeepAliveTime() |
String | getParameter(String name) |
Principal | getPrincipal() |
Map<String,Object> | getProperties() |
Map<String,Deque<String>> | getQueryParameters() |
String | getQueryString() |
HeaderMap | getRequestHeaders() |
String | getRequestURI() |
HeaderMap | getResponseHeaders() |
boolean | isOpen() |
<T> T | putAttachment(AttachmentKey<T> key, T value) Set an attachment value. |
<T> T | removeAttachment(AttachmentKey<T> key) Remove an attachment, returning its previous value. |
void | send(String data) Sends an event to the remote client |
void | send(String data, ServerSentEventConnection.EventCallback callback) Sends an event to the remote client |
void | send(String data, String event, String id, ServerSentEventConnection.EventCallback callback) Sends an event to the remote client |
void | sendRetry(long retry) Sends the 'retry' message to the client, instructing it how long to wait before attempting a reconnect. |
void | sendRetry(long retry, ServerSentEventConnection.EventCallback callback) Sends the 'retry' message to the client, instructing it how long to wait before attempting a reconnect. |
void | setKeepAliveTime(long keepAliveTime) Sets the keep alive time in milliseconds. |
void | setParameter(String name, String value) |
void | shutdown() execute a graceful shutdown once all data has been sent |
public ServerSentEventConnection(HttpServerExchange exchange, org.xnio.channels.StreamSinkChannel sink)
public void addCloseTask(org.xnio.ChannelListener<ServerSentEventConnection> listener)
listener
- The listener to invokepublic Principal getPrincipal()
public Account getAccount()
public HeaderMap getRequestHeaders()
public HeaderMap getResponseHeaders()
public String getRequestURI()
public Map<String,Deque<String>> getQueryParameters()
public String getQueryString()
public void send(String data)
data
- The event datapublic void send(String data, ServerSentEventConnection.EventCallback callback)
data
- The event datacallback
- A callback that is notified on Success or failurepublic void sendRetry(long retry)
retry
- The retry time in millisecondspublic void sendRetry(long retry, ServerSentEventConnection.EventCallback callback)
retry
- The retry time in millisecondscallback
- The callback that is notified on success or failurepublic void send(String data, String event, String id, ServerSentEventConnection.EventCallback callback)
data
- The event dataevent
- The event nameid
- The event IDcallback
- A callback that is notified on Success or failurepublic long getKeepAliveTime()
public void setKeepAliveTime(long keepAliveTime)
keepAliveTime
- The time in milliseconds between keep alive messagedpublic void shutdown()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
public <T> T getAttachment(AttachmentKey<T> key)
Attachable
null
is returned.getAttachment
in interface Attachable
T
- the value typekey
- the attachment keynull
if there is nonepublic <T> List<T> getAttachmentList(AttachmentKey<? extends List<T>> key)
Attachable
getAttachmentList
in interface Attachable
T
- the value typekey
- the attachment keypublic <T> T putAttachment(AttachmentKey<T> key, T value)
Attachable
null
, the attachment key is removed.putAttachment
in interface Attachable
T
- the value typekey
- the attachment keyvalue
- the new valuenull
if there was nonepublic <T> T removeAttachment(AttachmentKey<T> key)
Attachable
removeAttachment
in interface Attachable
T
- the value typekey
- the attachment keynull
if there was nonepublic <T> void addToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value)
Attachable
addToAttachmentList
in interface Attachable
T
- the list value typekey
- the attachment keyvalue
- the value to addCopyright © 2020 JBoss by Red Hat. All rights reserved.