Skip to content

Instantly share code, notes, and snippets.

@spericas
Last active June 22, 2020 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spericas/ad38c21e3b0b41347599620b1a7fb382 to your computer and use it in GitHub Desktop.
Save spericas/ad38c21e3b0b41347599620b1a7fb382 to your computer and use it in GitHub Desktop.
public class MessageBoardEndpoint extends Endpoint {
private final MessageQueue messageQueue = MessageQueue.instance();
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
session.addMessageHandler(new MessageHandler.Whole<String>() {
@Override
public void onMessage(String message) {
try {
if (message.equals("SEND")) {
while (!messageQueue.isEmpty()) {
session.getBasicRemote().sendObject(messageQueue.pop());
}
}
} catch (Exception e) {
// ...
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment