Last active
June 22, 2020 16:01
-
-
Save spericas/ad38c21e3b0b41347599620b1a7fb382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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