diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BinaryMessageCodec.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BinaryMessageCodec.java index 2755e92239ed3..f6abc3b42b173 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BinaryMessageCodec.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/BinaryMessageCodec.java @@ -6,8 +6,27 @@ /** * Used to encode and decode binary messages. * + *

Special types of messages

+ * + * Some types of messages bypass the encoding/decoding process: + * + * The encoding/decoding details are described in {@link OnBinaryMessage}. + * + *

CDI beans

+ * Implementation classes must be CDI beans. Qualifiers are ignored. {@link jakarta.enterprise.context.Dependent} beans are + * reused during encoding/decoding. + * + *

Lifecycle and concurrency

+ * Codecs are shared accross all WebSocket connections. Therefore, implementations should be either stateless or thread-safe. + * * @param - * @see BinaryMessage + * @see OnBinaryMessage */ @Experimental("This API is experimental and may change in the future") public interface BinaryMessageCodec extends MessageCodec { diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/MessageCodec.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/MessageCodec.java index eaf84d311e8c4..4d99833c0f57a 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/MessageCodec.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/MessageCodec.java @@ -7,26 +7,10 @@ /** * Used to encode and decode messages. * - *

Special types of messages

- * Some types of messages bypass the encoding/decoding process: - *
    - *
  • {@code java.lang.Buffer},
  • - *
  • {@code byte[]},
  • - *
  • {@code java.lang.String},
  • - *
  • {@code io.vertx.core.json.JsonObject}.
  • - *
  • {@code io.vertx.core.json.JsonArray}.
  • - *
- * The encoding/decoding details are described in {@link BinaryMessage} and {@link TextMessage}. - * - *

CDI beans

- * Implementation classes must be CDI beans. Qualifiers are ignored. {@link jakarta.enterprise.context.Dependent} beans are - * reused during encoding/decoding. - * - *

Lifecycle and concurrency

- * Codecs are shared accross all WebSocket connections. Therefore, implementations should be either stateless or thread-safe. - * * @param * @param + * @see TextMessageCodec + * @see BinaryMessageCodec */ @Experimental("This API is experimental and may change in the future") public interface MessageCodec { diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnBinaryMessage.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnBinaryMessage.java index 2eb5f62221ce4..33300b621bbfe 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnBinaryMessage.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnBinaryMessage.java @@ -9,13 +9,37 @@ import io.smallrye.common.annotation.Experimental; /** - * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation consume binary messages. + * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation consume binary messages. An + * endpoint may declare at most one method annotated with this annotation. + * + *

Execution model

+ * + *
    + *
  • Methods annotated with {@link io.smallrye.common.annotation.RunOnVirtualThread} are considered blocking and should be + * executed on a virtual thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.Blocking} are considered blocking and should be executed on a + * worker thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.NonBlocking} are considered non-blocking and should be + * executed on an event loop thread.
  • + *
+ * + * Execution model for methods which don't declare any of the annotation listed above is derived from the return type: *

+ *

    + *
  • Methods returning {@code void} are considered blocking and should be executed on a worker thread.
  • + *
  • Methods returning {@link io.smallrye.mutiny.Uni} or {@link io.smallrye.mutiny.Multi} are considered non-blocking and + * should be executed on an event loop thread.
  • + *
  • Methods returning any other type are considered blocking and should be executed on a worker thread.
  • + *
+ * + *

Method parameters

+ * * The method must accept exactly one message parameter. A binary message is always represented as a * {@link io.vertx.core.buffer.Buffer}. Therefore, the following conversion rules * apply. The types listed below are handled specifically. For all other types a {@link BinaryMessageCodec} is used to encode * and decode input and output messages. By default, the first input codec that supports the message type is used; codecs with * higher priority go first. However, a specific codec can be selected with {@link #codec()} and {@link #outputCodec()}. + *

*

    *
  • {@code java.lang.Buffer} is used as is,
  • *
  • {@code byte[]} is encoded with {@link io.vertx.core.buffer.Buffer#buffer(byte[])} and decoded with @@ -34,8 +58,6 @@ *
  • {@link HandshakeRequest}
  • *
  • {@link String} parameters annotated with {@link PathParam}
  • *
- *

- * An endpoint may declare at most one method annotated with this annotation. */ @Retention(RUNTIME) @Target(METHOD) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnClose.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnClose.java index 39ed396ec24ba..c5e1014acad0a 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnClose.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnClose.java @@ -10,9 +10,30 @@ /** * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation are invoked when a connection - * is closed. + * is closed. An endpoint may declare at most one method annotated with this annotation. The method must return {@code void} or + * {@code io.smallrye.mutiny.Uni}. + * + *

Execution model

+ * + *
    + *
  • Methods annotated with {@link io.smallrye.common.annotation.RunOnVirtualThread} are considered blocking and should be + * executed on a virtual thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.Blocking} are considered blocking and should be executed on a + * worker thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.NonBlocking} are considered non-blocking and should be + * executed on an event loop thread.
  • + *
+ * + * Execution model for methods which don't declare any of the annotation listed above is derived from the return type: *

- * The method must return {@code void} or {@code io.smallrye.mutiny.Uni}. + *

    + *
  • Methods returning {@code void} are considered blocking and should be executed on a worker thread.
  • + *
  • Methods returning {@code io.smallrye.mutiny.Uni} are considered non-blocking and should be executed on an event + * loop thread.
  • + *
+ * + *

Method parameters

+ * * The method may accept the following parameters: *
    *
  • {@link WebSocketConnection}/{@link WebSocketClientConnection}; depending on the endpoint type
  • @@ -21,8 +42,6 @@ *
* Note that it's not possible to send a message to the current connection as the socket is already closed when the method * invoked. However, it is possible to send messages to other open connections. - *

- * An endpoint may declare at most one method annotated with this annotation. */ @Retention(RUNTIME) @Target(METHOD) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnError.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnError.java index ee277a3373b71..4e2464ba2d485 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnError.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnError.java @@ -13,8 +13,32 @@ * occurs. *

* It is used when an endpoint callback throws a runtime error, or when a conversion errors occurs, or when a returned - * {@link io.smallrye.mutiny.Uni} receives a failure. + * {@link io.smallrye.mutiny.Uni} receives a failure. An endpoint may declare multiple methods annotated with this annotation. + * However, each method must declare a different error + * parameter. The method that declares a most-specific supertype of the actual exception is selected. + * + *

Execution model

+ * + *
    + *
  • Methods annotated with {@link io.smallrye.common.annotation.RunOnVirtualThread} are considered blocking and should be + * executed on a virtual thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.Blocking} are considered blocking and should be executed on a + * worker thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.NonBlocking} are considered non-blocking and should be + * executed on an event loop thread.
  • + *
+ * + * Execution model for methods which don't declare any of the annotation listed above is derived from the return type: *

+ *

    + *
  • Methods returning {@code void} are considered blocking and should be executed on a worker thread.
  • + *
  • Methods returning {@link io.smallrye.mutiny.Uni} or {@link io.smallrye.mutiny.Multi} are considered non-blocking and + * should be executed on an event loop thread.
  • + *
  • Methods returning any other type are considered blocking and should be executed on a worker thread.
  • + *
+ * + *

Method parameters

+ * * The method must accept exactly one "error" parameter, i.e. a parameter that is assignable from {@link java.lang.Throwable}. * The method may also accept the following parameters: *
    @@ -23,9 +47,9 @@ *
  • {@link String} parameters annotated with {@link PathParam}
  • *
*

- * An endpoint may declare multiple methods annotated with this annotation. However, each method must declare a different error - * parameter. The method that declares a most-specific supertype of the actual exception is selected. - *

+ * + *

Global error handlers

+ * * This annotation can be also used to declare a global error handler, i.e. a method that is not declared on a * {@link WebSocket}/{@link WebSocketClient} endpoint. Such a method may not accept {@link PathParam} paremeters. If a global * error handler accepts {@link WebSocketConnection} then it's only applied to server-side errors. If a global error diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnOpen.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnOpen.java index 7489fb35c89ce..1ac5bd5afd274 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnOpen.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnOpen.java @@ -10,16 +10,36 @@ /** * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation are invoked when a new - * connection is opened. + * connection is opened. An endpoint may declare at most one method annotated with this annotation. + * + *

Execution model

+ * + *
    + *
  • Methods annotated with {@link io.smallrye.common.annotation.RunOnVirtualThread} are considered blocking and should be + * executed on a virtual thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.Blocking} are considered blocking and should be executed on a + * worker thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.NonBlocking} are considered non-blocking and should be + * executed on an event loop thread.
  • + *
+ * + * Execution model for methods which don't declare any of the annotation listed above is derived from the return type: *

+ *

    + *
  • Methods returning {@code void} are considered blocking and should be executed on a worker thread.
  • + *
  • Methods returning {@link io.smallrye.mutiny.Uni} or {@link io.smallrye.mutiny.Multi} are considered non-blocking and + * should be executed on an event loop thread.
  • + *
  • Methods returning any other type are considered blocking and should be executed on a worker thread.
  • + *
+ * + *

Method parameters

+ * * The method may accept the following parameters: *
    *
  • {@link WebSocketConnection}/{@link WebSocketClientConnection}; depending on the endpoint type
  • *
  • {@link HandshakeRequest}
  • *
  • {@link String} parameters annotated with {@link PathParam}
  • *
- *

- * An endpoint may declare at most one method annotated with this annotation. */ @Retention(RUNTIME) @Target(METHOD) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnPongMessage.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnPongMessage.java index a1b077704fb94..4491ba0150a75 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnPongMessage.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnPongMessage.java @@ -9,7 +9,30 @@ import io.smallrye.common.annotation.Experimental; /** - * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation consume pong messages. + * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation consume pong messages. An + * endpoint may declare at most one method annotated with this annotation. + * + *

Execution model

+ * + *
    + *
  • Methods annotated with {@link io.smallrye.common.annotation.RunOnVirtualThread} are considered blocking and should be + * executed on a virtual thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.Blocking} are considered blocking and should be executed on a + * worker thread.
  • + *
  • Methods annotated with {@link io.smallrye.common.annotation.NonBlocking} are considered non-blocking and should be + * executed on an event loop thread.
  • + *
+ * + * Execution model for methods which don't declare any of the annotation listed above is derived from the return type: + *

+ *

    + *
  • Methods returning {@code void} are considered blocking and should be executed on a worker thread.
  • + *
  • Methods returning {@link io.smallrye.mutiny.Uni} or {@link io.smallrye.mutiny.Multi} are considered non-blocking and + * should be executed on an event loop thread.
  • + *
  • Methods returning any other type are considered blocking and should be executed on a worker thread.
  • + *
+ * + *

Method parameters

* * The method must accept exactly one pong message parameter represented as a {@link io.vertx.core.buffer.Buffer}. The method * may also accept the following parameters: @@ -19,7 +42,7 @@ *
  • {@link String} parameters annotated with {@link PathParam}
  • * *

    - * An endpoint may declare at most one method annotated with this annotation. + * */ @Retention(RUNTIME) @Target(METHOD) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnTextMessage.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnTextMessage.java index ac7cd56b27a42..8eab65d7977d9 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnTextMessage.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/OnTextMessage.java @@ -9,13 +9,37 @@ import io.smallrye.common.annotation.Experimental; /** - * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation consume text messages. + * {@link WebSocket} and {@link WebSocketClient} endpoint methods annotated with this annotation consume text messages. An + * endpoint may declare at most one method annotated with this annotation. + * + *

    Execution model

    + * + *
      + *
    • Methods annotated with {@link io.smallrye.common.annotation.RunOnVirtualThread} are considered blocking and should be + * executed on a virtual thread.
    • + *
    • Methods annotated with {@link io.smallrye.common.annotation.Blocking} are considered blocking and should be executed on a + * worker thread.
    • + *
    • Methods annotated with {@link io.smallrye.common.annotation.NonBlocking} are considered non-blocking and should be + * executed on an event loop thread.
    • + *
    + * + * Execution model for methods which don't declare any of the annotation listed above is derived from the return type: *

    + *

      + *
    • Methods returning {@code void} are considered blocking and should be executed on a worker thread.
    • + *
    • Methods returning {@link io.smallrye.mutiny.Uni} or {@link io.smallrye.mutiny.Multi} are considered non-blocking and + * should be executed on an event loop thread.
    • + *
    • Methods returning any other type are considered blocking and should be executed on a worker thread.
    • + *
    + * + *

    Method parameters

    + * * The method must accept exactly one message parameter. A text message is always represented as a {@link String}. Therefore, - * the following conversion rules apply. The types listed - * below are handled specifically. For all other types a {@link TextMessageCodec} is used to encode and decode input and - * output messages. By default, the first input codec that supports the message type is used; codecs with higher priority go - * first. However, a specific codec can be selected with {@link #codec()} and {@link #outputCodec()}. + * the following conversion rules apply. The types listed below are handled specifically. For all other types a + * {@link TextMessageCodec} is used to encode and decode input and output messages. By default, the first input codec that + * supports the message type is used; codecs with higher priority go first. However, a specific codec can be selected with + * {@link #codec()} and {@link #outputCodec()}. + *

    *

      *
    • {@code java.lang.String} is used as is,
    • *
    • {@code io.vertx.core.json.JsonObject} is encoded with {@link io.vertx.core.json.JsonObject#encode()} and decoded with @@ -26,15 +50,13 @@ * {@link io.vertx.core.buffer.Buffer#buffer(String)},
    • *
    • {@code byte[]} is first converted to {@link io.vertx.core.buffer.Buffer} and then converted as defined above.
    • *
    - *

    + * * The method may also accept the following parameters: *

      *
    • {@link WebSocketConnection}/{@link WebSocketClientConnection}; depending on the endpoint type
    • *
    • {@link HandshakeRequest}
    • *
    • {@link String} parameters annotated with {@link PathParam}
    • *
    - *

    - * An endpoint may declare at most one method annotated with this annotation. */ @Retention(RUNTIME) @Target(METHOD) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/PathParam.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/PathParam.java index 353e965e194bf..f49419909989e 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/PathParam.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/PathParam.java @@ -14,6 +14,8 @@ * * @see WebSocketConnection#pathParam(String) * @see WebSocket + * @see WebSocketClientConnection#pathParam(String) + * @see WebSocketClient */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/TextMessageCodec.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/TextMessageCodec.java index 1146f686c3553..2ca9b73c2f44b 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/TextMessageCodec.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/TextMessageCodec.java @@ -5,8 +5,27 @@ /** * Used to encode and decode text messages. * + *

    Special types of messages

    + * + * Some types of messages bypass the encoding/decoding process: + *
      + *
    • {@code java.lang.Buffer},
    • + *
    • {@code byte[]},
    • + *
    • {@code java.lang.String},
    • + *
    • {@code io.vertx.core.json.JsonObject}.
    • + *
    • {@code io.vertx.core.json.JsonArray}.
    • + *
    + * The encoding/decoding details are described in {@link OnTextMessage}. + * + *

    CDI beans

    + * Implementation classes must be CDI beans. Qualifiers are ignored. {@link jakarta.enterprise.context.Dependent} beans are + * reused during encoding/decoding. + * + *

    Lifecycle and concurrency

    + * Codecs are shared accross all WebSocket connections. Therefore, implementations should be either stateless or thread-safe. + * * @param - * @see TextMessage + * @see OnTextMessage */ @Experimental("This API is experimental and may change in the future") public interface TextMessageCodec extends MessageCodec { diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocket.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocket.java index 819bce0cd4064..ccb13c958003c 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocket.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/WebSocket.java @@ -12,7 +12,7 @@ import io.smallrye.common.annotation.Experimental; /** - * Denotes a WebSocket endpoint. + * Denotes a WebSocket server endpoint. *

    * An endpoint must declare a method annotated with {@link OnTextMessage}, {@link OnBinaryMessage}, {@link OnPongMessage} or * {@link OnOpen}. An endpoint may declare a method annotated with {@link OnClose}.