Package io.undertow.server.handlers.sse
Class ServerSentEventConnection
java.lang.Object
io.undertow.server.handlers.sse.ServerSentEventConnection
- All Implemented Interfaces:
Attachable,Closeable,AutoCloseable,Channel
Represents the server side of a Server Sent Events connection.
The class implements Attachable, which provides access to the underlying exchanges attachments.
- Author:
- Stuart Douglas
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionServerSentEventConnection(HttpServerExchange exchange, org.xnio.channels.StreamSinkChannel sink) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCloseTask(org.xnio.ChannelListener<ServerSentEventConnection> listener) Adds a listener that will be invoked when the channel is closed<T> voidaddToAttachmentList(AttachmentKey<AttachmentList<T>> key, T value) Add a value to a list-typed attachment key.voidclose()<T> TgetAttachment(AttachmentKey<T> key) Get an attachment value.<T> List<T>getAttachmentList(AttachmentKey<? extends List<T>> key) Gets a list attachment value.longgetParameter(String name) booleanisOpen()<T> TputAttachment(AttachmentKey<T> key, T value) Set an attachment value.<T> TremoveAttachment(AttachmentKey<T> key) Remove an attachment, returning its previous value.voidSends an event to the remote clientvoidsend(String data, ServerSentEventConnection.EventCallback callback) Sends an event to the remote clientvoidsend(String data, String event, String id, ServerSentEventConnection.EventCallback callback) Sends an event to the remote clientvoidsendRetry(long retry) Sends the 'retry' message to the client, instructing it how long to wait before attempting a reconnect.voidsendRetry(long retry, ServerSentEventConnection.EventCallback callback) Sends the 'retry' message to the client, instructing it how long to wait before attempting a reconnect.voidsetKeepAliveTime(long keepAliveTime) Sets the keep alive time in milliseconds.voidsetParameter(String name, String value) voidshutdown()execute a graceful shutdown once all data has been sent
-
Constructor Details
-
ServerSentEventConnection
public ServerSentEventConnection(HttpServerExchange exchange, org.xnio.channels.StreamSinkChannel sink)
-
-
Method Details
-
addCloseTask
Adds a listener that will be invoked when the channel is closed- Parameters:
listener- The listener to invoke
-
getPrincipal
- Returns:
- The principal that was associated with the SSE request
-
getAccount
- Returns:
- The account that was associated with the SSE request
-
getRequestHeaders
- Returns:
- The request headers from the initial request that opened this connection
-
getResponseHeaders
- Returns:
- The response headers from the initial request that opened this connection
-
getRequestURI
- Returns:
- The request URI from the initial request that opened this connection
-
getQueryParameters
- Returns:
- the query parameters
-
getQueryString
- Returns:
- the query string
-
send
Sends an event to the remote client- Parameters:
data- The event data
-
send
Sends an event to the remote client- Parameters:
data- The event datacallback- A callback that is notified on Success or failure
-
sendRetry
public void sendRetry(long retry) Sends the 'retry' message to the client, instructing it how long to wait before attempting a reconnect.- Parameters:
retry- The retry time in milliseconds
-
sendRetry
Sends the 'retry' message to the client, instructing it how long to wait before attempting a reconnect.- Parameters:
retry- The retry time in millisecondscallback- The callback that is notified on success or failure
-
send
public void send(String data, String event, String id, ServerSentEventConnection.EventCallback callback) Sends an event to the remote client- Parameters:
data- The event dataevent- The event nameid- The event IDcallback- A callback that is notified on Success or failure
-
getParameter
-
setParameter
-
getProperties
-
getKeepAliveTime
public long getKeepAliveTime()- Returns:
- The keep alive time
-
setKeepAliveTime
public void setKeepAliveTime(long keepAliveTime) Sets the keep alive time in milliseconds. If this is larger than zero a ':' message will be sent this often (assuming there is no activity) to keep the connection alive. The spec recommends a value of 15000 (15 seconds).- Parameters:
keepAliveTime- The time in milliseconds between keep alive messaged
-
shutdown
public void shutdown()execute a graceful shutdown once all data has been sent -
isOpen
public boolean isOpen() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getAttachment
Description copied from interface:AttachableGet an attachment value. If no attachment exists for this key,nullis returned.- Specified by:
getAttachmentin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment key- Returns:
- the value, or
nullif there is none
-
getAttachmentList
Description copied from interface:AttachableGets a list attachment value. If not attachment exists for this key an empty list is returned- Specified by:
getAttachmentListin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment key- Returns:
- the value, or an empty list if there is none
-
putAttachment
Description copied from interface:AttachableSet an attachment value. If an attachment for this key was already set, return the original value. If the value being set isnull, the attachment key is removed.- Specified by:
putAttachmentin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment keyvalue- the new value- Returns:
- the old value, or
nullif there was none
-
removeAttachment
Description copied from interface:AttachableRemove an attachment, returning its previous value.- Specified by:
removeAttachmentin interfaceAttachable- Type Parameters:
T- the value type- Parameters:
key- the attachment key- Returns:
- the old value, or
nullif there was none
-
addToAttachmentList
Description copied from interface:AttachableAdd a value to a list-typed attachment key. If the key is not mapped, add such a mapping.- Specified by:
addToAttachmentListin interfaceAttachable- Type Parameters:
T- the list value type- Parameters:
key- the attachment keyvalue- the value to add
-