Java EE 8 specifications

As with every platform release, Java EE 8 comprises of new specifications as well as enhancements to many of the existing components. The sample application in the blog demonstrates the following features in the below mentioned specifications

Context and Dependency Injection (CDI) 2.0 — asynchronous events producer and consumer

(CDI) 2.0 — asynchronous events producer and consumer JAX-RS 2.1 — Server Sent Events feature to be specific

— Server Sent Events feature to be specific JSON-B 1.0 (JSON Binding) integration with JAX-RS

Sample application

Here is a high level flow

overview of the solution

The service consists of a timer component which emits events at regular intervals.

This is consumed by another component which makes the events available over Server Sent Events (SSE) — any (SSE) client (including your browser or a JavaScript app) can hook up to receive these

the project is available on Github for you to grok further

Let’s look at some of the implementation details

What’s going on ?

Here is a summary of the Java EE 8 specs and their respective components

Scheduled (event producer) component

An @ApplicationScoped CDI bean produces asynchronous CDI events (new in CDI 2.0 with Java EE 8) — this is done using Event.fireAsync()

CDI bean produces CDI events (new in CDI 2.0 with Java EE 8) — this is done using The ManagedExecutorService (from the Java EE Concurrency utilities spec) thread pool is used to execute the timer/scheduler

(from the Java EE Concurrency utilities spec) thread pool is used to execute the timer/scheduler These CDI events are qualified (using a custom @Qualifier )

Server Sent Events component

Exposes an endpoint for clients to register/subscribe to events

Broadcasting component