Atmosphere 1.0: Asynchronous Communication For Java/JavaScript

| by Kostis Kapelonis on Oct 31, 2012. Estimated reading time: 3 minutes |

Atmosphere 1.0 is a new Java/Scala/Groovy framework that attempts to abstract asynchronous communication between the web browser and the application server. It transparently supports Web Sockets, HTML5 Server Side events and other application server specific solutions when available, with long polling as a fallback.

Originally web applications were built on the client/server model where the client always initiates the connection to the server. For certain types of applications, for example dashboards, tickers, and online chat that require real time communication features the traditional HTTP request/response cycle is not enough. In those cases the server must be able to push data to the client (web browser) in an asynchronous manner (when an event is available). 

This requirement became especially evident with the advent AJAX-based rich internet applications. These abandoned the full page refresh for a more dynamic approach, where only some parts of the page are updated when new data is available from the application server. The most basic solution is to use polling, where the client continuously asks the server for updates (possibly with an interval). This simple approach needs no special support but can be problematic in terms of bandwidth. A server can easily become overwhelmed by multiple clients even when no new data is actually available.

Another approach for asynchronous communication is HTTP Streaming (also known as Comet). This solution forces the browser to connect to the server, and then keeps the connection open for a specified amount of time (that can also be infinite). When the server has an event that needs to be pushed back to the browser, it uses this persistent connection (which is already open). This solution has several limitations as well. Persistent connections are resource intensive, proxies and firewalls can shut them down unexpectedly and browsers have limits on the number of connections per application server.

All these solutions are also non-standard. Comet is essentially a broad term for several implementations that follow the concept described above. Efforts for a standard have appeared in the form of WebSockets. WebSockets are a new network protocol designed from the beginning targeting asynchronous communication. However this protocol needs explicit support from both the Web browser and the application server. Once they both agree on WebSocket support they can "upgrade" an HTTP connection to a web socket. Programming for WebSockets has also its own issues since at the moment each application server has its own API resulting easily in a vendor lock-in.

Atmosphere is a Java framework (Groovy and Scala are also supported) that works as an abstraction over all these solutions allowing the developer to focus on the actual business logic instead of dealing with low level communication details. Developers write against a unified Atmosphere API that supports behind the scenes:

At the same time Atmosphere also offers a JavaScript module (supporting jQuery) that sits in the client side and abstracts the capabilities of the web browser in terms of asynchronous support. Controlling both ends of the connection is a key concept in the abstraction that is offered by Atmosphere. There is detailed documentation on supported application servers and browsers.

The major feature of Atmosphere is the fact that it will automatically use the most efficient solution if it is available (e.g. WebSockets) also supporting a fall back solution (e.g. long polling). It is also possible to detect in advance what is supported between the client and the server. Notice that Atmosphere can run in a non-servlet container using Nettosphere.

Apart from the basic API, Atmosphere has also plugins/extensions that integrate it with:

  • REST/Jersey
  • GWT/Vaadin
  • Spring
  • Guice
  • Wicket
  • PrimeFaces/RichFaces

For more information, visit the Wiki, Samples, FAQ and Javadocs.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread