Fixes #11213 - Improve programming guide WebSocket JPMS documentation

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2024-01-02 22:51:43 +01:00
parent 0740b6d1b2
commit 4fca6781ce
1 changed files with 25 additions and 1 deletions

View File

@ -151,7 +151,31 @@ include::{doc_code}/org/eclipse/jetty/docs/programming/WebSocketDocs.java[tags=s
===== Annotated Endpoints
A WebSocket endpoint may annotate methods with `+org.eclipse.jetty.websocket.api.annotations.*+` annotations to receive WebSocket events.
Each annotated method may take an optional `Session` argument as its first parameter:
Jetty uses ``MethodHandle``s to instantiate WebSocket endpoints and invoke WebSocket event methods, so WebSocket endpoint classes and WebSocket event methods must be `public`.
When using JPMS, you must ensure that the Jetty JPMS module `org.eclipse.jetty.websocket.common` can _read_ (in JPMS terms) the WebSocket endpoint classes in your JPMS module.
For example, your application may use the Jetty WebSocket client so that the JPMS module that contains your WebSocket endpoint classes looks like this:
[source,java]
.module-info.java
----
module com.acme.websocket
{
// The Jetty WebSocket client dependency.
requires org.eclipse.jetty.websocket.client;
}
----
To ensure that Jetty _reads_ your JPMS module, you must start the JVM with the following option:
[source]
----
$ java --add-reads org.eclipse.jetty.websocket.common=com.acme.websocket ...
----
Each annotated event method may take an optional `Session` argument as its first parameter:
[source,java,indent=0]
----