Archive for February, 2011

Atmosphere 0.7 released: WebSocket, GWT, Wicket, Redis, XMPP, Async I/O

February 25, 2011 4 comments

Atmosphere 0.7 is available! This release contains an impressive number of new functionality and bug fixes. The extensive list of fixed bugs for that release can be read here, and the new functionality are explained below

Native GWT support

Starting with 0.7, the Atmosphere-GWT project is now fully integrated into Atmosphere. That means you can add support for WebSocket/Comet to any GWT application. You can download demos from here.

Wicket Support

As described here, we do support the Wicket framework our of the box. As simple as:

public class PushPage extends WebPage
    implements AtmosphereResourceEventListener {

    private final AtomicBoolean scheduleStarted = new AtomicBoolean(false);

    public PushPage() {
        HttpServletRequest req = getWebRequestCycle()
        Meteor meteor =;
        if (!scheduleStarted.getAndSet(true)) {
            meteor.schedule(new Callable<String>() {
                public String call() {
                    String s = new Date().toString();
                    return s;
            }, 1); // One second

        // Depending on the connection
        String transport = req.getHeader("X-Atmosphere-Transport");
        meteor.suspend(-1, !(transport != null
              && transport.equalsIgnoreCase("long-polling")));

    public void onBroadcast(AtmosphereResourceEvent
           <HttpServletRequest, HttpServletResponse> event) {

        String transport = event.getResource()
        if (transport != null
              && transport.equalsIgnoreCase("long-polling")) {
            Meteor meteor = Meteor.lookup(event.getResource().getRequest());



you can download the demo here.

Native Redis Support

As described here, you can now use Redis for massively distribute server sides events amongst your Atmosphere application. This is as simple as configuring Atmosphere to use the RedisBroadcaster to broadcast server sides events. If you already have an Atmosphere application, you don’t need to change anything except configuring Atmosphere. You can switch from your in memory broadcaster, JMSBroadcaster, JGroupsBroadcaster by simply doing:

    // JSMBroadcaster || XMPPBroadcaster
    private @PathParam("topic") RedisBroadcaster topic;

    public SuspendResponse subscribe() {

        return new SuspendResponse.SuspendResponseBuilder()
                .addListener(new EventsLogger())

    public Broadcastable publish(@FormParam("message") String message) {
      return new Broadcastable(message, "", topic);

you can download the demo here.

Native XMPP Support

As described here, you can now use the XMPP protocol for massively distribute server sides events amongst your Atmosphere application. As with Redis and JMS, you just need to tell Atmosphere to use the XMPPBroadcaster. You can download the demo here.

Broadcasting Callable<T> now supported

As described here, you can now broadcast Callable, which gets executed just before the response is written back to the browser. This is quite useful when scheduled tasks are needed:

if (feed.getAtmosphereResources().size() == 0) {
    Future<?> future = feed.scheduleFixedBroadcast(new Callable<String>() {
        private final AtomicReference<String> refreshUrl
               = new AtomicReference<String>("");
           public String call() throws Exception {
              String query = null;
              if (!refreshUrl.get().isEmpty()) {
                  query = refreshUrl.get();
              } else {
                  query = "?q=" + tagid;
                  ""  + query)
                    .execute(new AsyncCompletionHandler <Integer>()) {
                          public Object onCompleted(Response response)
                               throws Exception {
                            String s = response.getResponseBody();
                            JSONObject json = new JSONObject(s);
                            return response.getStatusCode();
                    return "OK";
            }, 1, TimeUnit.SECONDS);
            futures.put(tagid, future);

you can download the demo here.

WebSocket Emulator Supported (like Flash)

The Atmosphere JQuery Plugin can now be configured to use an external WebSocket implementation. As an example, you can use the web-socket-js library, which adds support for Flash.

     <script type="text/javascript" src="web_socket.js"></script>

     <script type="text/javascript">
         /* transport can be : long-polling, streaming or websocket */
                $.atmosphere.request =
                    {transport: getElementByIdValue('transport'),
                     webSocketImpl: new WebSocket(uri) });

Asynchronous write I/O operation now supported

All the Broadcaster has been modified to support asynchronous I/O write operation using a dedicated ExecutorService. This will prevent slow clients to block the entire broadcast process. You can configure the thread pool strategy using the BroadcastConfig API:

Per Request BroadcastFilter

As described here, per request BroadcastFilter are now supported. That means you can transform an events based on some request’s headers, query string etc. This is quite useful when it is time to unify browser support, or take advantage of some browser native API. As simple as:

public class JavascriptClientFilter implements PerRequestBroadcastFilter {

    private final AtomicInteger uniqueScriptToken = new AtomicInteger();

    public BroadcastFilter.BroadcastAction filter
                   (HttpServletRequest request, Object message) {

        if (request.getHeader("User-Agent") != null) {
            String userAgent =
            if (userAgent != null && userAgent.indexOf("MSIE") != -1
                    && message instanceof String) {
                StringBuilder sb = new StringBuilder
                    ("<script id=\"atmosphere_")
                message = sb.toString();
        return new BroadcastFilter.BroadcastAction
            (BroadcastFilter.BroadcastAction.ACTION.CONTINUE, message);

Improved Dependency Injection Support for Spring and Guice

With 0.7 we have added new API to allow easier integration with Spring and Guice.  You can download the demo here.

New Broadcaster’s Lifecycle Policy Support

Broadcaster implementation like the JMSBroadcaster can hold open connections and before 0.7 it was difficult to decide what to do with those connections when no WebSocket/Comet connections where alive. We have added a new API that allow an application to configure Atmosphere and decide when a Broadcaster’s resource get garbage collected. As simple as:

Broadcaster.setBroadcasterLifeCyclePolicy( IDLE | IDLE_DESTROY | EMPTY | EMPTY_DESTROY | NEVER );

Improve compatibility with other JavaScript Framework

It is now easier to integrate the Atmosphere JQuery Plugin with other framework like Prototype.

Jersey’s @DefaultValue and @Singleton now supported

You can now use these two annotations with Atmosphere’s object like Broadcaster. As simple as:

More WebContainer supported

Atmosphere 0.7 now support all flavor of Jetty 7 and 8 Websocket implementation, as well a GlassFish v3.1 WebSocket API. Tomcat 7 Servlet 3.0 implementation works also perfectly well.

Broadcaster new API

The Broadcaster API has been heavily improved and you can now look up per request Broadcaster and also you can configure Atmosphere to broadcast value when a resume operation occurs, etc. All new features are available to all Broadcaster. See the API for more information

What’s next

The Atmosphere 0.8 release should happens before the summer and will include Socket.IO support, Google App Engine channel support, Cometd 2.2.x support, unified Atmosphere Client Javascript library and of course all the requests asked by the community.

For any questions or to download Atmosphere Client and Server Framework, go to our main site, use our Nabble forum, follow the team or myself and tweet your questions there! You can also checkout the code on Github.

Categories: Atmosphere, Comet, JQuery, Websocket