Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
WebSocketEndpoint.java
Go to the documentation of this file.
1package dev.rafex.ether.websocket.core;
2
3/*-
4 * #%L
5 * ether-websocket-core
6 * %%
7 * Copyright (C) 2025 - 2026 Raúl Eduardo González Argote
8 * %%
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 * #L%
27 */
28
29import java.nio.ByteBuffer;
30import java.util.Set;
31
32/**
33 * Define el contrato de un punto final WebSocket. Las implementaciones reciben
34 * notificaciones del ciclo de vida de la conexión: apertura, mensajes de texto/binario,
35 * cierre y errores. Todos los métodos tienen una implementación vacía por defecto para
36 * que las subclases solo sobreescriban los eventos que necesiten.
37 */
38public interface WebSocketEndpoint {
39
40 /**
41 * Invocado cuando la conexión WebSocket se abre exitosamente.
42 *
43 * @param session sesión WebSocket activa
44 * @throws Exception si ocurre un error durante el procesamiento
45 */
46 default void onOpen(final WebSocketSession session) throws Exception {
47 }
48
49 /**
50 * Invocado cuando se recibe un mensaje de texto del cliente.
51 *
52 * @param session sesión WebSocket activa
53 * @param message contenido de texto recibido
54 * @throws Exception si ocurre un error durante el procesamiento
55 */
56 default void onText(final WebSocketSession session, final String message) throws Exception {
57 }
58
59 /**
60 * Invocado cuando se recibe un mensaje binario del cliente.
61 *
62 * @param session sesión WebSocket activa
63 * @param message contenido binario recibido
64 * @throws Exception si ocurre un error durante el procesamiento
65 */
66 default void onBinary(final WebSocketSession session, final ByteBuffer message) throws Exception {
67 }
68
69 /**
70 * Invocado cuando el cliente solicita cerrar la conexión.
71 *
72 * @param session sesión WebSocket activa
73 * @param closeStatus estado de cierre indicado por el cliente
74 * @throws Exception si ocurre un error durante el procesamiento
75 */
76 default void onClose(final WebSocketSession session, final WebSocketCloseStatus closeStatus) throws Exception {
77 }
78
79 /**
80 * Invocado cuando ocurre un error en la conexión WebSocket.
81 *
82 * @param session sesión WebSocket activa
83 * @param error excepción que causó el error
84 */
85 default void onError(final WebSocketSession session, final Throwable error) {
86 }
87
88 /**
89 * Devuelve el conjunto de subprotocolos WebSocket que este endpoint acepta.
90 * El servidor seleccionará un subprotocolo de esta lista durante el handshake.
91 *
92 * @return conjunto de nombres de subprotocolo soportados; vacío por defecto
93 */
94 default Set<String> subprotocols() {
95 return Set.of();
96 }
97}
Define el contrato de un punto final WebSocket.
default void onText(final WebSocketSession session, final String message)
Invocado cuando se recibe un mensaje de texto del cliente.
default void onOpen(final WebSocketSession session)
Invocado cuando la conexión WebSocket se abre exitosamente.
default Set< String > subprotocols()
Devuelve el conjunto de subprotocolos WebSocket que este endpoint acepta.
default void onBinary(final WebSocketSession session, final ByteBuffer message)
Invocado cuando se recibe un mensaje binario del cliente.
default void onClose(final WebSocketSession session, final WebSocketCloseStatus closeStatus)
Invocado cuando el cliente solicita cerrar la conexión.
default void onError(final WebSocketSession session, final Throwable error)
Invocado cuando ocurre un error en la conexión WebSocket.
Representa una sesión WebSocket activa.
record WebSocketCloseStatus(int code, String reason)
Representa un estado de cierre de una conexión WebSocket conforme a la especificación RFC 6455.