public static void main(String[] args) throws Exception {
ExecutorService webThread = newSingleThreadExecutor();
final Pusher pusher = new Pusher();
WebServer webServer = createWebServer(webThread, 9876)
.add("/events", new EventSourceHandler() {
@Override
public void onOpen(EventSourceConnection connection) throws Exception {
pusher.addConnection(connection);
}
@Override
public void onClose(EventSourceConnection connection) throws Exception {
pusher.removeConnection(connection);
}
})
.add(new EmbeddedResourceHandler("samples/eventsource/content"))
.start()
.get();
System.out.println("EventSource demo running on: " + webServer.getUri());
pusher.pushPeriodicallyOn(webThread);
}