org.atmosphere.samples.twitter
Class TwitterAtmosphereHandler

java.lang.Object
  extended by org.atmosphere.handler.AbstractReflectorAtmosphereHandler
      extended by org.atmosphere.samples.twitter.TwitterAtmosphereHandler
All Implemented Interfaces:
AtmosphereHandler<HttpServletRequest,HttpServletResponse>

public class TwitterAtmosphereHandler
extends AbstractReflectorAtmosphereHandler

Twitter like Comet application. This AtmosphereHandler implement the logic needed to support micro blogging a la Twitter.com. Users can blog about what they are doing and can also follow their friends. When an update is made by one user, all its follower gets updated automatically. The updated words can be moved on the screen and all follower will see the move. This Servlet demonstrate how multiple Broadcaster can be used to easily isolate suspended connection and to only push messages to a subset of those suspended connection. It also demonstrate how to push messages to a single AtmosphereResourceEvent There is one AtmosphereResourceEvent per user. AtmosphereResourceEvent associated with the user suspended connection are added to their Broadcaster and added to the Broadcaster of the users they are following.

Author:
Jeanfrancois Arcand

Constructor Summary
TwitterAtmosphereHandler()
           
 
Method Summary
 void onRequest(AtmosphereResource<HttpServletRequest,HttpServletResponse> event)
          Based on the ServletRequest.getParameter(java.lang.String) action value, decide if the connection needs to be suspended (when the user logs in) or if the Broadcaster needs to be updated (by the user or by its follower.
 
Methods inherited from class org.atmosphere.handler.AbstractReflectorAtmosphereHandler
onStateChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwitterAtmosphereHandler

public TwitterAtmosphereHandler()
Method Detail

onRequest

public void onRequest(AtmosphereResource<HttpServletRequest,HttpServletResponse> event)
               throws IOException
Based on the ServletRequest.getParameter(java.lang.String) action value, decide if the connection needs to be suspended (when the user logs in) or if the Broadcaster needs to be updated (by the user or by its follower. There is one Broadcaster per suspended connection, representing the user account. When one user B request to follow user A, the AtmosphereResourceEvent associated with user B's Broadcaster is also added to user A Broadcaster. Hence when user A push message (Broadcaster.broadcast() all AtmosphereResourceEvent gets the CometEvent, which means user B will be updated when user A update its micro blog. The suspended connection on the client side is multiplexed, e.g. messages sent by the server are not only for a single component, but shared amongs several components. The client side include a message board that is updated by notifying the owner of the Broadcaster. This is achieved by calling Broadcaster.broadcast(CometEvent,AtmosphereResourceEvent)

Parameters:
event - An AtmosphereResourceEvent
Throws:
IOException


Copyright © 2009 SUN Microsystems. All Rights Reserved.