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); ...