Skip to content

Commit

Permalink
WebSockets Next: merge BlockingSender and Sender interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Nov 13, 2024
1 parent 173e489 commit acb1078
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 77 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see WebSocketConnection
* @see WebSocketClientConnection
*/
public interface Connection extends BlockingSender {
public interface Connection extends Sender {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.vertx.core.buffer.Buffer;

/**
* Sends messages to the connected WebSocket client.
* Sends messages to the connected WebSocket client/server.
*/
@Experimental("This API is experimental and may change in the future")
public interface Sender {
Expand All @@ -20,16 +20,45 @@ public interface Sender {
@CheckReturnValue
Uni<Void> sendText(String message);

/**
* Sends a text message and waits for the completion.
* <p>
* This method should never be called on an event loop thread.
*
* @param message
*/
default void sendTextAndAwait(String message) {
sendText(message).await().indefinitely();
}

/**
* Send a text message.
* <p>
* A {@link TextMessageCodec} is used to encode the message.
*
* @param <M>
* @param message
* @return a new {@link Uni} with a {@code null} item
* @see TextMessageCodec
*/
@CheckReturnValue
<M> Uni<Void> sendText(M message);

/**
* Sends a text message and waits for the completion.
* <p>
* A {@link TextMessageCodec} is used to encode the message.
* <p>
* This method should never be called on an event loop thread.
*
* @param <M>
* @param message
* @see TextMessageCodec
*/
default <M> void sendTextAndAwait(M message) {
sendText(message).await().indefinitely();
}

/**
* Send a binary message.
*
Expand All @@ -39,6 +68,17 @@ public interface Sender {
@CheckReturnValue
Uni<Void> sendBinary(Buffer message);

/**
* Sends a binary message and waits for the completion.
* <p>
* This method should never be called on an event loop thread.
*
* @param message
*/
default void sendBinaryAndAwait(Buffer message) {
sendBinary(message).await().indefinitely();
}

/**
* Send a binary message.
*
Expand All @@ -50,6 +90,17 @@ default Uni<Void> sendBinary(byte[] message) {
return sendBinary(Buffer.buffer(message));
}

/**
* Sends a binary message and waits for the completion.
* <p>
* This method should never be called on an event loop thread.
*
* @param message
*/
default void sendBinaryAndAwait(byte[] message) {
sendBinary(message).await().indefinitely();
}

/**
* Send a ping message.
*
Expand All @@ -59,6 +110,17 @@ default Uni<Void> sendBinary(byte[] message) {
@CheckReturnValue
Uni<Void> sendPing(Buffer data);

/**
* Send a ping message and waits for the completion.
* <p>
* This method should never be called on an event loop thread.
*
* @param data May be at most 125 bytes
*/
default void sendPingAndAwait(Buffer data) {
sendPing(data).await().indefinitely();
}

/**
* Send an unsolicited pong message.
* <p>
Expand All @@ -72,4 +134,19 @@ default Uni<Void> sendBinary(byte[] message) {
@CheckReturnValue
Uni<Void> sendPong(Buffer data);

/**
* Send an unsolicited pong message and waits for the completion.
* <p>
* This method should never be called on an event loop thread.
* <p>
* Note that the server automatically responds to a ping message sent from the client. However, the RFC 6455
* <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">section 5.5.3</a> states that unsolicited pong may serve as a
* unidirectional heartbeat.
*
* @param data May be at most 125 bytes
*/
default void sendPongAndAwait(Buffer data) {
sendPong(data).await().indefinitely();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
* endpoint and used to interact with the connected client, or all clients connected to the endpoint respectively
* (broadcasting).
* <p>
* Specifically, it is possible to send messages using blocking and non-blocking methods, declared on
* {@link BlockingSender} and {@link Sender} respectively.
* Specifically, it is possible to send messages using blocking and non-blocking methods declared on {@link Sender}.
*/
@Experimental("This API is experimental and may change in the future")
public interface WebSocketConnection extends Connection {
Expand Down Expand Up @@ -51,7 +50,7 @@ public interface WebSocketConnection extends Connection {
*
* @see WebSocketConnection#getOpenConnections()
*/
interface BroadcastSender extends BlockingSender {
interface BroadcastSender extends Sender {

/**
*
Expand Down

0 comments on commit acb1078

Please sign in to comment.