Last active
February 13, 2017 16:14
-
-
Save abhirockzz/87adecdc748ef390a3b96bd088ecbe45 to your computer and use it in GitHub Desktop.
WebSocket endpoint as a Singleton EJB
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
@Singleton | |
@ServerEndpoint("/singleton/") | |
public class SingletonEndpoint { | |
@OnOpen | |
public void onopen(Session s) throws IOException { | |
s.getBasicRemote().sendText(String.valueOf(hashCode())); | |
} | |
@PreDestroy | |
public void onDestroy() { | |
System.out.println("Singleton bean " + hashCode() + " will be destroyed"); | |
} | |
@OnClose | |
public void onClose(Session session, CloseReason closeReason) { | |
System.out.println("Closed " + session.getId() + " due to " + closeReason.getCloseCode()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment