Package com.oorian

Class OorianWebsocket

java.lang.Object
com.oorian.OorianWebsocket
All Implemented Interfaces:
WebsocketConnection

public class OorianWebsocket extends Object implements 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this WebSocket connection.
    void
    onClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason reason)
    Called when the WebSocket connection is closed.
    void
    onError(jakarta.websocket.Session session, Throwable error)
    Called when an error occurs on the WebSocket connection.
    void
    onMessage(jakarta.websocket.Session session, String msg)
    Called when a message is received from the client.
    void
    onOpen(jakarta.websocket.Session wsSession, jakarta.websocket.EndpointConfig conf, String pageId)
    Called when a new WebSocket connection is opened.
    void
    Sends a text message to the client through this WebSocket connection.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 session
      conf - the endpoint configuration
      pageId - the page ID from the URL path
    • onMessage

      public void onMessage(jakarta.websocket.Session session, String msg)
      Called when a message is received from the client.

      Delegates message handling to the associated HtmlPage.

      Parameters:
      session - the WebSocket session
      msg - the message received from the client
    • onError

      public void onError(jakarta.websocket.Session session, Throwable error)
      Called when an error occurs on the WebSocket connection.

      Logs the error and notifies the associated HtmlPage.

      Parameters:
      session - the WebSocket session
      error - 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 session
      reason - the reason for the closure
    • sendMessage

      public void sendMessage(String text)
      Sends a text message to the client through this WebSocket connection.

      This method is synchronized to prevent concurrent message sending.

      Specified by:
      sendMessage in interface WebsocketConnection
      Parameters:
      text - the message to send
    • close

      public void close()
      Closes this WebSocket connection.
      Specified by:
      close in interface WebsocketConnection