Package com.oorian
Class OorianWebsocket
java.lang.Object
com.oorian.OorianWebsocket
- All Implemented Interfaces:
WebsocketConnection
WebSocket endpoint for real-time communication between Oorian pages and the client browser.
OorianWebsocket provides bidirectional communication for AJAX-style updates without polling. Each HtmlPage can have an associated WebSocket connection that allows the server to push updates to the client in real-time.
Key Features:
- Automatic association with HtmlPage instances via page ID
- HTTP session awareness for security and state management
- Keep-alive ping mechanism to prevent connection timeouts
- Thread-safe message sending
- Weak references to prevent memory leaks
The WebSocket URL pattern is /oorianws/{pageid} where pageid is the
unique identifier of the associated HtmlPage.
- Since:
- 2020
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this WebSocket connection.voidonClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason reason) Called when the WebSocket connection is closed.voidCalled when an error occurs on the WebSocket connection.voidCalled when a message is received from the client.voidCalled when a new WebSocket connection is opened.voidsendMessage(String text) Sends a text message to the client through this WebSocket connection.
-
Constructor Details
-
OorianWebsocket
public OorianWebsocket()
-
-
Method Details
-
onOpen
public void onOpen(jakarta.websocket.Session wsSession, jakarta.websocket.EndpointConfig conf, String pageId) Called when a new WebSocket connection is opened.Associates the WebSocket with its corresponding HtmlPage and registers the connection for periodic keep-alive pings.
- Parameters:
wsSession- the WebSocket sessionconf- the endpoint configurationpageId- the page ID from the URL path
-
onMessage
Called when a message is received from the client.Delegates message handling to the associated HtmlPage.
- Parameters:
session- the WebSocket sessionmsg- the message received from the client
-
onError
Called when an error occurs on the WebSocket connection.Logs the error and notifies the associated HtmlPage.
- Parameters:
session- the WebSocket sessionerror- the error that occurred
-
onClose
public void onClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason reason) Called when the WebSocket connection is closed.Notifies the associated HtmlPage of the closure.
- Parameters:
session- the WebSocket sessionreason- the reason for the closure
-
sendMessage
Sends a text message to the client through this WebSocket connection.This method is synchronized to prevent concurrent message sending.
- Specified by:
sendMessagein interfaceWebsocketConnection- Parameters:
text- the message to send
-
close
public void close()Closes this WebSocket connection.- Specified by:
closein interfaceWebsocketConnection
-