Trying to broadcast to all sessions on a WebSocket but it is a bit hit
and miss. the WebSocket is got by
DefaultServerEndpointConfigurator dsec = new
DefaultServerEndpointConfigurator();
NewsWebSocket nws = dsec.getEndpointInstance(NewsWebSocket.class);
nws.broadcast(myString);
and in the WebSocket I am trying to broadcast on looks like this
@ServerEndpoint(value = "/websockets/admin/news")
public class NewsWebSocket {
private static final Set<Session> sessions =
Collections.synchronizedSet(new HashSet<Session>());
// ... @OnOpen, @OnMessage, @OnClose, @OnError
public void broadcast(String string) {
synchronized (sessions) {
for (Session session : sessions) {
try {
session.getBasicRemote().sendText(string);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
}
I also tried adding an "@Observes @MyEvent MyEvent blah" and firing an
"Event<MyEvent>" but the breakpoint is never reached