Package net.carcdr.yhocuspocus.websocket
Class WebSocketServer
java.lang.Object
net.carcdr.yhocuspocus.websocket.WebSocketServer
- All Implemented Interfaces:
AutoCloseable
WebSocket server for YHocuspocus collaborative editing.
This class provides a complete WebSocket server implementation using Jetty, configured for hosting YHocuspocus instances. It handles:
- HTTP server setup and lifecycle
- WebSocket upgrade and routing
- Connection management
- Graceful shutdown
Example usage:
YHocuspocus hocuspocus = YHocuspocus.builder()
.extension(new InMemoryDatabaseExtension())
.build();
WebSocketServer server = WebSocketServer.builder()
.server(hocuspocus)
.port(1234)
.path("/collaboration")
.build();
server.start();
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for WebSocketServer. -
Method Summary
Modifier and TypeMethodDescriptionstatic WebSocketServer.Builderbuilder()Creates a new builder for WebSocketServer.voidclose()net.carcdr.yhocuspocus.core.YHocuspocusGets the YHocuspocus server instance.getPath()Gets the WebSocket path.intgetPort()Gets the port the server is listening on.booleanChecks if the server is currently running.voidstart()Starts the WebSocket server.voidstop()Stops the WebSocket server gracefully.
-
Method Details
-
start
Starts the WebSocket server.This method blocks until the server is fully started and ready to accept connections.
- Throws:
Exception- if the server fails to startIllegalStateException- if the server is already started
-
stop
-
isStarted
public boolean isStarted()Checks if the server is currently running.- Returns:
- true if started, false otherwise
-
getPort
public int getPort()Gets the port the server is listening on.If the server was configured with port 0 (random port), this method returns the actual port assigned by the OS after the server starts.
- Returns:
- port number (actual listening port if started, configured port otherwise)
-
getPath
-
getHocuspocus
public net.carcdr.yhocuspocus.core.YHocuspocus getHocuspocus()Gets the YHocuspocus server instance.- Returns:
- the hocuspocus server
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
builder
Creates a new builder for WebSocketServer.- Returns:
- builder instance
-