Attachable
, java.io.Closeable
, java.lang.AutoCloseable
, java.nio.channels.Channel
public class ServerSentEventConnection extends java.lang.Object implements java.nio.channels.Channel, Attachable
Modifier and Type | Class | Description |
---|---|---|
static interface |
ServerSentEventConnection.EventCallback |
Constructor | Description |
---|---|
ServerSentEventConnection(HttpServerExchange exchange,
org.xnio.channels.StreamSinkChannel sink) |
Modifier and Type | Method | 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> java.util.List<T> |
getAttachmentList(AttachmentKey<? extends java.util.List<T>> key) |
Gets a list attachment value.
|
long |
getKeepAliveTime() |
|
java.lang.String |
getParameter(java.lang.String name) |
|
java.security.Principal |
getPrincipal() |
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties() |
|
java.util.Map<java.lang.String,java.util.Deque<java.lang.String>> |
getQueryParameters() |
|
java.lang.String |
getQueryString() |
|
HeaderMap |
getRequestHeaders() |
|
java.lang.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(java.lang.String data) |
Sends an event to the remote client
|
void |
send(java.lang.String data,
ServerSentEventConnection.EventCallback callback) |
Sends an event to the remote client
|
void |
send(java.lang.String data,
java.lang.String event,
java.lang.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(java.lang.String name,
java.lang.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 java.security.Principal getPrincipal()
public Account getAccount()
public HeaderMap getRequestHeaders()
public HeaderMap getResponseHeaders()
public java.lang.String getRequestURI()
public java.util.Map<java.lang.String,java.util.Deque<java.lang.String>> getQueryParameters()
public java.lang.String getQueryString()
public void send(java.lang.String data)
data
- The event datapublic void send(java.lang.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(java.lang.String data, java.lang.String event, java.lang.String id, ServerSentEventConnection.EventCallback callback)
data
- The event dataevent
- The event nameid
- The event IDcallback
- A callback that is notified on Success or failurepublic java.lang.String getParameter(java.lang.String name)
public void setParameter(java.lang.String name, java.lang.String value)
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
public long getKeepAliveTime()
public void setKeepAliveTime(long keepAliveTime)
keepAliveTime
- The time in milliseconds between keep alive messagedpublic void shutdown()
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
close
in interface java.io.Closeable
java.io.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> java.util.List<T> getAttachmentList(AttachmentKey<? extends java.util.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 © 2018. All rights reserved.