By David Delabassee-Oracle on May 28, 2014
- the Servlet API
- the WebSocket API
- or even having a dedicated SSE API, and thus a dedicated JSR too!
As you know, HTTP is a stateless protocol. For most use cases in the enterprise, the statelessness of HTTP is a huge boon for scalability - a benefit that is also extended to REST. However, there is a certain class of arguably emerging use cases for which the stateless nature of HTTP is actually a scalability challenge. These use cases require the bidirectional, full-duplex, asynchronous characteristics of stateful protocols such as TCP. Examples include chat-like online collaboration, stock-ticker like command-control/monitoring, online gaming and the like. WebSocket (and the Java API for WebSocket newly included in Java EE 7 :-)) is ideal for these cases. Between the seemingly diametric opposites of plain HTTP and WebSocket, there's also Server Sent Events (SSE). SSE is aimed at yet another scenario - a steam of events generated by the server and consumed passively by the client. Although not standardized in JAX-RS 2/Java EE 7, Jersey/GlassFish includes support for SSE.
In an very detailed blog post, Rahman Usta of the Istanbul JUG explains SSE and demonstrates a non-trivial use of the Jersey/GlassFish support for SSE.
The blog posts include example source code that can be deployed to recent (trunk) builds of GlassFish Server. Bhakti uses SSE and CDI to build an application that tracks a twitter search, while Jitu discusses how GlassFish adds a bit more abstraction for the developer and references a video player sample application available in the GlassFish trunk.