Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed receive() method to onMessage() in WsListener #6571

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static void grpcUpper(Strings.StringMessage request, StreamObserver<Stri
private static WsListener wsEcho() {
return new WsListener() {
@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
session.send(text, last);
System.out.println("websocket request " + text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void handle() {
while (true) {
try {
BufferData buffer = dataReader.readBuffer();
listener.receive(this, buffer, true);
listener.onMessage(this, buffer, true);
} catch (Exception e) {
listener.onError(this, e);
listener.onClose(this, WsCloseCodes.UNEXPECTED_CONDITION, e.getMessage());
Expand Down Expand Up @@ -112,12 +112,12 @@ class TyrusListener implements WsListener {
private Connection connection;

@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
// Should never be called!
}

@Override
public void receive(WsSession session, BufferData buffer, boolean last) {
public void onMessage(WsSession session, BufferData buffer, boolean last) {
byte[] b = new byte[buffer.available()];
buffer.read(b); // buffer copy!
writeToTyrus(session, ByteBuffer.wrap(b));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void onOpen(WsSession session) {
}

@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
this.message = text;
session.close(WsCloseCodes.NORMAL_CLOSE, "End");
}
Expand Down Expand Up @@ -140,7 +140,7 @@ private static class ServerSideListener implements WsListener {
String message;

@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
message = text;
session.send("ws", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onOpen(WsSession session) {
}

@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
session.send(text, last);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public void onClose(WsSession session, int status, String reason) {
}

@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
received.add(new WsAction(RCV, TEXT, text));
}

@Override
public void receive(WsSession session, BufferData buffer, boolean last) {
public void onMessage(WsSession session, BufferData buffer, boolean last) {
int n = buffer.available();
received.add(new WsAction(RCV, BINARY, buffer.readString(n, UTF_8)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public CompletionStage<?> onText(java.net.http.WebSocket webSocket,
private static WsListener single() {
return new WsListener() {
@Override
public void receive(WsSession session, String text, boolean last) {
public void onMessage(WsSession session, String text, boolean last) {
session.send(text.toUpperCase(Locale.ROOT), true);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ private boolean processFrame(ServerWsFrame frame) {
recvContinuation = ContinuationType.NONE;
}
switch (ct) {
case TEXT -> listener.receive(this, payload.readString(payload.available(), StandardCharsets.UTF_8), finalFrame);
case BINARY -> listener.receive(this, payload, finalFrame);
case TEXT -> listener.onMessage(this, payload.readString(payload.available(), StandardCharsets.UTF_8), finalFrame);
case BINARY -> listener.onMessage(this, payload, finalFrame);
default -> {
close(WsCloseCodes.PROTOCOL_ERROR, "Unexpected continuation received");
throw new WsClientException("Unexpected continuation received");
Expand All @@ -238,11 +238,11 @@ private boolean processFrame(ServerWsFrame frame) {
}
case TEXT -> {
recvContinuation = ContinuationType.TEXT;
listener.receive(this, payload.readString(payload.available(), StandardCharsets.UTF_8), frame.fin());
listener.onMessage(this, payload.readString(payload.available(), StandardCharsets.UTF_8), frame.fin());
}
case BINARY -> {
recvContinuation = ContinuationType.BINARY;
listener.receive(this, payload, frame.fin());
listener.onMessage(this, payload, frame.fin());
}
case CLOSE -> {
int status = payload.readInt16();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ private boolean processFrame(ClientWsFrame frame) {
recvContinuation = ContinuationType.NONE;
}
switch (ct) {
case TEXT -> listener.receive(this, payload.readString(payload.available(), StandardCharsets.UTF_8), finalFrame);
case BINARY -> listener.receive(this, payload, finalFrame);
case TEXT -> listener.onMessage(this, payload.readString(payload.available(), StandardCharsets.UTF_8), finalFrame);
case BINARY -> listener.onMessage(this, payload, finalFrame);
default -> {
close(WsCloseCodes.PROTOCOL_ERROR, "Unexpected continuation received");
throw new CloseConnectionException("Websocket unexpected continuation");
Expand All @@ -168,11 +168,11 @@ private boolean processFrame(ClientWsFrame frame) {
}
case TEXT -> {
recvContinuation = ContinuationType.TEXT;
listener.receive(this, payload.readString(payload.available(), StandardCharsets.UTF_8), frame.fin());
listener.onMessage(this, payload.readString(payload.available(), StandardCharsets.UTF_8), frame.fin());
}
case BINARY -> {
recvContinuation = ContinuationType.BINARY;
listener.receive(this, payload, frame.fin());
listener.onMessage(this, payload, frame.fin());
}
case CLOSE -> {
int status = payload.readInt16();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
*/
public interface WsListener {
/**
* Receive text fragment.
* Received text fragment.
*
* @param session WebSocket session
* @param text text received
* @param last is this last fragment
*/
default void receive(WsSession session, String text, boolean last) {
default void onMessage(WsSession session, String text, boolean last) {
}

/**
* Receive binary fragment.
* Received binary fragment.
*
* @param session WebSocket session
* @param buffer buffer with data
* @param last is this last fragment
*/
default void receive(WsSession session, BufferData buffer, boolean last) {
default void onMessage(WsSession session, BufferData buffer, boolean last) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onOpen(WsSession session) {
}

@Override
public void receive(WsSession session, String message, boolean last) {
public void onMessage(WsSession session, String message, boolean last) {
LOGGER.log(Level.INFO, "WS Receiving " + message);
if (message.contains("SEND")) {
session.send(message, false);
Expand Down