Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Last active February 13, 2017 16:14
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 abhirockzz/87adecdc748ef390a3b96bd088ecbe45 to your computer and use it in GitHub Desktop.
Save abhirockzz/87adecdc748ef390a3b96bd088ecbe45 to your computer and use it in GitHub Desktop.
WebSocket endpoint as a Singleton EJB
@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