twitter4j
Class TwitterStream

java.lang.Object
  extended by twitter4j.TwitterBase
      extended by twitter4j.TwitterStream
All Implemented Interfaces:
java.io.Serializable

public class TwitterStream
extends TwitterBase
implements java.io.Serializable

A java reporesentation of the Twitter Streaming API
Note that this class is NOT compatible with Google App Engine as GAE is not capable of handling requests longer than 30 seconds.

Since:
Twitter4J 2.0.4
Author:
Yusuke Yamamoto - yusuke at mac.com
See Also:
Serialized Form

Nested Class Summary
(package private)  class TwitterStream.StreamHandlingThread
           
 
Field Summary
private  TwitterStream.StreamHandlingThread handler
           
private  HttpClientWrapper http
           
private static Logger logger
           
private  int retryPerMinutes
           
private static long serialVersionUID
           
private  StatusListener statusListener
           
 
Fields inherited from class twitter4j.TwitterBase
auth, conf
 
Constructor Summary
TwitterStream()
          Deprecated. use new TwitterStreamFactory.getInstance() instead.
TwitterStream(Configuration conf, Authorization auth, StatusListener listener)
           
TwitterStream(java.lang.String screenName, java.lang.String password)
          Deprecated. use new TwitterStreamFactory.getInstance() instead.
TwitterStream(java.lang.String screenName, java.lang.String password, StatusListener listener)
          Deprecated. use new TwitterStreamFactory.getInstance() instead.
 
Method Summary
 void cleanup()
           
 void filter(int count, int[] follow, java.lang.String[] track)
          See birddog above.
 void firehose(int count)
          Starts listening on all public statuses.
 StatusStream getFilterStream(int count, int[] follow, java.lang.String[] track)
          Returns stream of public statuses that match one or more filter predicates.
 StatusStream getFirehoseStream(int count)
          Returns a status stream of all public statuses.
 StatusStream getRetweetStream()
          Returns a stream of all retweets.
 StatusStream getSampleStream()
          Returns a stream of random sample of all public statuses.
 void retweet()
          Starts listening on all retweets.
 void sample()
          Starts listening on random sample of all public statuses.
 void setStatusListener(StatusListener statusListener)
           
private  void startHandler(TwitterStream.StreamHandlingThread handler)
           
private  java.lang.String toFollowString(int[] follows)
           
private  java.lang.String toTrackString(java.lang.String[] keywords)
           
 
Methods inherited from class twitter4j.TwitterBase
ensureAuthorizationEnabled, ensureBasicEnabled, ensureBasicNotEnabled, equals, getAuthorization, hashCode, isBasicAuthEnabled, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

http

private final HttpClientWrapper http

logger

private static final Logger logger

statusListener

private StatusListener statusListener

handler

private TwitterStream.StreamHandlingThread handler

retryPerMinutes

private int retryPerMinutes

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

TwitterStream

public TwitterStream()
Deprecated. use new TwitterStreamFactory.getInstance() instead.

Constructs a TwitterStream instance. UserID and password should be provided by either twitter4j.properties or system property. since Twitter4J 2.0.10


TwitterStream

public TwitterStream(java.lang.String screenName,
                     java.lang.String password)
Deprecated. use new TwitterStreamFactory.getInstance() instead.

Constructs a TwitterStream instance. UserID and password should be provided by either twitter4j.properties or system property. since Twitter4J 2.0.10

Parameters:
screenName - screen name
password - password

TwitterStream

public TwitterStream(java.lang.String screenName,
                     java.lang.String password,
                     StatusListener listener)
Deprecated. use new TwitterStreamFactory.getInstance() instead.

Constructs a TwitterStream instance. UserID and password should be provided by either twitter4j.properties or system property. since Twitter4J 2.0.10

Parameters:
screenName - screen name
password - password
listener - listener

TwitterStream

TwitterStream(Configuration conf,
              Authorization auth,
              StatusListener listener)
Method Detail

firehose

public void firehose(int count)
              throws TwitterException
Starts listening on all public statuses. Available only to approved parties and requires a signed agreement to access. Please do not contact us about access to the firehose. If your service warrants access to it, we'll contact you.

Parameters:
count - Indicates the number of previous statuses to stream before transitioning to the live stream.
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.4
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - firehose

getFirehoseStream

public StatusStream getFirehoseStream(int count)
                               throws TwitterException
Returns a status stream of all public statuses. Available only to approved parties and requires a signed agreement to access. Please do not contact us about access to the firehose. If your service warrants access to it, we'll contact you.

Parameters:
count - Indicates the number of previous statuses to stream before transitioning to the live stream.
Returns:
StatusStream
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.4
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - firehose

retweet

public void retweet()
             throws TwitterException
Starts listening on all retweets. The retweet stream is not a generally available resource. Few applications require this level of access. Creative use of a combination of other resources and various access levels can satisfy nearly every application use case. As of 9/11/2009, the site-wide retweet feature has not yet launched, so there are currently few, if any, retweets on this stream.

Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.10
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - retweet

getRetweetStream

public StatusStream getRetweetStream()
                              throws TwitterException
Returns a stream of all retweets. The retweet stream is not a generally available resource. Few applications require this level of access. Creative use of a combination of other resources and various access levels can satisfy nearly every application use case. As of 9/11/2009, the site-wide retweet feature has not yet launched, so there are currently few, if any, retweets on this stream.

Returns:
StatusStream
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.10
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - firehose

sample

public void sample()
            throws TwitterException
Starts listening on random sample of all public statuses. The default access level provides a small proportion of the Firehose. The "Gardenhose" access level provides a proportion more suitable for data mining and research applications that desire a larger proportion to be statistically significant sample.

Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.10
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - sample

getSampleStream

public StatusStream getSampleStream()
                             throws TwitterException
Returns a stream of random sample of all public statuses. The default access level provides a small proportion of the Firehose. The "Gardenhose" access level provides a proportion more suitable for data mining and research applications that desire a larger proportion to be statistically significant sample.

Returns:
StatusStream
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.10
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - Sampling

filter

public void filter(int count,
                   int[] follow,
                   java.lang.String[] track)
            throws TwitterException
See birddog above. Allows following up to 200 users. Publicly available.

Parameters:
count - Indicates the number of previous statuses to stream before transitioning to the live stream.
follow - Specifies the users, by ID, to receive public tweets from.
track - Specifies keywords to track.
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.10
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - filter

getFilterStream

public StatusStream getFilterStream(int count,
                                    int[] follow,
                                    java.lang.String[] track)
                             throws TwitterException
Returns stream of public statuses that match one or more filter predicates. At least one predicate parameter, track or follow, must be specified. Both parameters may be specified which allows most clients to use a single connection to the Streaming API.

Parameters:
follow - Specifies the users, by ID, to receive public tweets from.
Returns:
StatusStream
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.0.10
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - filter

toFollowString

private java.lang.String toFollowString(int[] follows)

toTrackString

private java.lang.String toTrackString(java.lang.String[] keywords)

startHandler

private void startHandler(TwitterStream.StreamHandlingThread handler)
                   throws TwitterException
Throws:
TwitterException

cleanup

public void cleanup()

setStatusListener

public void setStatusListener(StatusListener statusListener)