org.atmosphere.samples.twitter
Class TwitterAtmosphereHandler
java.lang.Object
org.atmosphere.handler.AbstractReflectorAtmosphereHandler
org.atmosphere.samples.twitter.TwitterAtmosphereHandler
- All Implemented Interfaces:
- AtmosphereHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.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
|
Method Summary |
void |
onRequest(AtmosphereResource<javax.servlet.http.HttpServletRequest,javax.servlet.http.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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TwitterAtmosphereHandler
public TwitterAtmosphereHandler()
onRequest
public void onRequest(AtmosphereResource<javax.servlet.http.HttpServletRequest,javax.servlet.http.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 AtmosphereResource
associated with user B's Broadcaster is also added to user A
Broadcaster. Hence when user A push message (Broadcaster.broadcast(Object)
all AtmosphereResource gets the AtmosphereResourceEvent, 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(Object)
- Parameters:
event - An AtmosphereResourceEvent
- Throws:
IOException
Copyright © 2010 SUN Microsystems. All Rights Reserved.