Class SsePushConnection
java.lang.Object
com.vaadin.flow.server.communication.SsePushConnection
- All Implemented Interfaces:
PushConnection,Serializable
A
PushConnection implementation using Server-Sent Events (SSE)
without the Atmosphere framework.
SSE is used for server-to-client communication while XHR is used for client-to-server messages (similar to the WEBSOCKET_XHR transport pattern).
For internal use only. May be renamed or removed in a future release.
- Since:
- 24.7
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumConnection states for SSE push. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(jakarta.servlet.AsyncContext asyncContext) Associates thisSsePushConnectionwith the givenAsyncContextrepresenting an established SSE connection.voidCalled when the connection to the client has been lost.voidCloses the connection.protected jakarta.servlet.AsyncContextGets the AsyncContext associated with this connection.protected SsePushConnection.StategetState()Returns the state of this connection.protected UIgetUI()Gets the UI associated with this connection.booleanReturns whether this connection is currently open.voidpush()Pushes pending state changes and client RPC calls to the client.voidpush(boolean async) Pushes pending state changes and client RPC calls to the client.protected voidsendMessage(String message) Sends the given message to the current client using SSE format.
-
Constructor Details
-
SsePushConnection
Creates an instance connected to the given UI.- Parameters:
ui- the UI to which this connection belongs
-
-
Method Details
-
push
public void push()Description copied from interface:PushConnectionPushes pending state changes and client RPC calls to the client. Can be called even ifPushConnection.isConnected()is false; the push will be deferred until a connection is available. It is NOT safe to invoke this method if not holding the session lock.This is internal API; please use
UI.push()instead.- Specified by:
pushin interfacePushConnection
-
push
public void push(boolean async) Pushes pending state changes and client RPC calls to the client. IfisConnected()is false, defers the push until a connection is established.- Parameters:
async- True if this push asynchronously originates from the server, false if it is a response to a client request.
-
sendMessage
Sends the given message to the current client using SSE format. Cannot be called ifisConnected()returns false.- Parameters:
message- The message to send
-
isConnected
public boolean isConnected()Description copied from interface:PushConnectionReturns whether this connection is currently open.- Specified by:
isConnectedin interfacePushConnection- Returns:
- true if the connection is open, false otherwise
-
connect
Associates thisSsePushConnectionwith the givenAsyncContextrepresenting an established SSE connection. If already connected, callsdisconnect()first. If there is a deferred push, carries it out via the new connection.- Parameters:
asyncContext- the async context to associate this connection with- Throws:
IOException- if setting up the SSE connection fails
-
getUI
Gets the UI associated with this connection.- Returns:
- the UI associated with this connection.
-
getAsyncContext
protected jakarta.servlet.AsyncContext getAsyncContext()Gets the AsyncContext associated with this connection.- Returns:
- The AsyncContext associated with this connection or null if connection not open.
-
disconnect
public void disconnect()Description copied from interface:PushConnectionCloses the connection. Cannot be called ifPushConnection.isConnected()is false.- Specified by:
disconnectin interfacePushConnection
-
connectionLost
public void connectionLost()Called when the connection to the client has been lost. -
getState
Returns the state of this connection.- Returns:
- the state of this connection
-