I have created a very simple library that can be integrated within plain Java Servlets in Asynchronous mode, so no extra server threads are required for each client: https://github.com/mariomac/jeasse
It integrates the SseDispatcher (for point-to-point SSEs) and SseBroadcaster (for event broadcasting). An example of use:
public class TestServlet extends HttpServlet {
SseBroadcaster broadcaster = new SseBroadcaster();
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Scanner scanner = new Scanner(req.getInputStream());
StringBuilder sb = new StringBuilder();
while(scanner.hasNextLine()) {
sb.append(scanner.nextLine());
}
System.out.println("sb = " + sb);
broadcaster.broadcast("message",sb.toString());
}
//http://cjihrig.com/blog/the-server-side-of-server-sent-events/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
broadcaster.addListener(req);
}
}