How to do it...

First, we build a REST endpoint to manage the server events we are going to use, and to use REST we should start by properly configuring it:

@ApplicationPath("webresources")public class ApplicationConfig extends Application {}

The following is quite a big chunk of code, but don't worry, we are going to split it up and understand each piece:

@Path("serverSentService")@RequestScopedpublic class ServerSentService {    private static final Map<Long, UserEvent> POOL =     new ConcurrentHashMap<>();    @Resource(name = "LocalManagedExecutorService")    private ManagedExecutorService executor;    @Path("start")    @POST    public Response start(@Context Sse sse) {        final UserEvent process = new UserEvent(sse);        POOL.put(process.getId(), process); executor.submit(process); ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.