org.atmosphere.samples.twitter
Class TwitterResource

java.lang.Object
  extended by org.atmosphere.samples.twitter.TwitterResource

@Singleton
public class TwitterResource
extends Object

Twitter like Comet application. This rest based web application implements 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 Singleton demonstrate how multiple Broadcaster can be used to easily isolate suspended connection and to only push messages to a subset of those suspended connection using the Suspend annotation. 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, Paul Sandoz

Constructor Summary
TwitterResource()
           
 
Method Summary
 org.atmosphere.jersey.Broadcastable onFollow(TwitterBroadcaster userBc, String name, String followee)
          Add a follower, using the user's associated Broadcaster
 org.atmosphere.jersey.Broadcastable onLogin(TwitterBroadcaster bc, String name)
          Store the user information and broadcast a welcome message using the already suspended connection done onStart(java.lang.String)
 org.atmosphere.jersey.Broadcastable onPush(TwitterBroadcaster bc, String message, String callback)
          Push tweet to the user and its followers.
 String onStart(String callback)
          When the page loads, suspend the response and set the Suspend scope to REQUEST, which means every suspended connection by default have their own instance of Broadcaster
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwitterResource

public TwitterResource()
Method Detail

onStart

@Suspend(scope=REQUEST)
public String onStart(String callback)
When the page loads, suspend the response and set the Suspend scope to REQUEST, which means every suspended connection by default have their own instance of Broadcaster


onLogin

public org.atmosphere.jersey.Broadcastable onLogin(@Context
                                                   TwitterBroadcaster bc,
                                                   String name)
Store the user information and broadcast a welcome message using the already suspended connection done onStart(java.lang.String)


onFollow

public org.atmosphere.jersey.Broadcastable onFollow(@Context
                                                    TwitterBroadcaster userBc,
                                                    String name,
                                                    String followee)
Add a follower, using the user's associated Broadcaster

Parameters:
name -
followee -
Returns:

onPush

public org.atmosphere.jersey.Broadcastable onPush(@Context
                                                  TwitterBroadcaster bc,
                                                  String message,
                                                  String callback)
Push tweet to the user and its followers.

Parameters:
bc - The Broadcaster
message - The message to broadcast
callback - The calback
Returns:
a Broadcastable


Copyright © 2010 SUN Microsystems. All Rights Reserved.