twitter4j
Class TwitterStream

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

public final class TwitterStream
extends TwitterBase
implements java.io.Serializable

A java representation 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  twitter4j.internal.http.HttpClientWrapper http
           
private static int HTTP_ERROR_INITIAL_WAIT
           
private static int HTTP_ERROR_WAIT_CAP
           
private static twitter4j.internal.logging.Logger logger
           
private static long serialVersionUID
           
private  StatusListener statusListener
           
private static int TCP_ERROR_INITIAL_WAIT
           
private static int TCP_ERROR_WAIT_CAP
           
 
Fields inherited from class twitter4j.TwitterBase
auth, conf
 
Constructor Summary
TwitterStream()
          Deprecated. use TwitterStreamFactory.getInstance() instead.
TwitterStream(Configuration conf, Authorization auth, StatusListener listener)
           
TwitterStream(java.lang.String screenName, java.lang.String password)
          Deprecated. use TwitterStreamFactory.getInstance() instead.
TwitterStream(java.lang.String screenName, java.lang.String password, StatusListener listener)
          Deprecated. use TwitterStreamFactory.getInstance() instead.
 
Method Summary
 void cleanup()
           
 void filter(FilterQuery query)
          Start consuming public statuses that match one or more filter predicates.
 void filter(int count, int[] follow, java.lang.String[] track)
          Deprecated. use filter(FilterQuery) instead
 void firehose(int count)
          Starts listening on all public statuses.
 StatusStream getFilterStream(FilterQuery query)
          Returns public statuses that match one or more filter predicates.
 StatusStream getFilterStream(int count, int[] follow, java.lang.String[] track)
          Deprecated. use getFilterStream(FilterQuery) instead
 StatusStream getFirehoseStream(int count)
          Returns a status stream of all public statuses.
 StatusStream getLinksStream(int count)
          Returns a status stream of all public statuses containing links.
 StatusStream getRetweetStream()
          Returns a stream of all retweets.
 StatusStream getSampleStream()
          Returns a stream of random sample of all public statuses.
 void links(int count)
          Starts listening on all public statuses containing links.
 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)
           
 
Methods inherited from class twitter4j.TwitterBase
ensureAuthorizationEnabled, ensureBasicEnabled, 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 twitter4j.internal.http.HttpClientWrapper http

logger

private static final twitter4j.internal.logging.Logger logger

statusListener

private StatusListener statusListener

handler

private TwitterStream.StreamHandlingThread handler

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

TCP_ERROR_INITIAL_WAIT

private static final int TCP_ERROR_INITIAL_WAIT
See Also:
Constant Field Values

TCP_ERROR_WAIT_CAP

private static final int TCP_ERROR_WAIT_CAP
See Also:
Constant Field Values

HTTP_ERROR_INITIAL_WAIT

private static final int HTTP_ERROR_INITIAL_WAIT
See Also:
Constant Field Values

HTTP_ERROR_WAIT_CAP

private static final int HTTP_ERROR_WAIT_CAP
See Also:
Constant Field Values
Constructor Detail

TwitterStream

public TwitterStream()
Deprecated. use 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 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 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)
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.
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

links

public void links(int count)
Starts listening on all public statuses containing links. Available only to approved parties and requires a signed agreement to access. Please do not contact us about access to the links stream. 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.
Since:
Twitter4J 2.1.1
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - links

getLinksStream

public StatusStream getLinksStream(int count)
                            throws TwitterException
Returns a status stream of all public statuses containing links. Available only to approved parties and requires a signed agreement to access. Please do not contact us about access to the links stream. 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.1.1
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - links

retweet

public void retweet()
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.

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 - retweet

sample

public void sample()
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.

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(FilterQuery query)
            throws TwitterException
Start consuming public statuses that match one or more filter predicates. At least one predicate parameter, follow, locations, or track must be specified. Multiple parameters may be specified which allows most clients to use a single connection to the Streaming API. Placing long parameters in the URL may cause the request to be rejected for excessive URL length.
The default access level allows up to 200 track keywords, 400 follow userids and 10 1-degree location boxes. Increased access levels allow 80,000 follow userids ("shadow" role), 400,000 follow userids ("birddog" role), 10,000 track keywords ("restricted track" role), 200,000 track keywords ("partner track" role), and 200 10-degree location boxes ("locRestricted" role). Increased track access levels also pass a higher proportion of statuses before limiting the stream.

Parameters:
query - Filter query
Throws:
TwitterException
Since:
Twitter4J 2.1.2
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - filter

getFilterStream

public StatusStream getFilterStream(FilterQuery query)
                             throws TwitterException
Returns public statuses that match one or more filter predicates. At least one predicate parameter, follow, locations, or track must be specified. Multiple parameters may be specified which allows most clients to use a single connection to the Streaming API. Placing long parameters in the URL may cause the request to be rejected for excessive URL length.
The default access level allows up to 200 track keywords, 400 follow userids and 10 1-degree location boxes. Increased access levels allow 80,000 follow userids ("shadow" role), 400,000 follow userids ("birddog" role), 10,000 track keywords ("restricted track" role), 200,000 track keywords ("partner track" role), and 200 10-degree location boxes ("locRestricted" role). Increased track access levels also pass a higher proportion of statuses before limiting the stream.

Parameters:
query - Filter query
Returns:
StatusStream
Throws:
TwitterException - when Twitter service or network is unavailable
Since:
Twitter4J 2.1.2
See Also:
StatusStream, Twitter API Wiki / Streaming API Documentation - filter

filter

public void filter(int count,
                   int[] follow,
                   java.lang.String[] track)
Deprecated. use filter(FilterQuery) instead

Start consuming public statuses that match one or more filter predicates. At least one predicate parameter, follow, locations, or track must be specified. Multiple parameters may be specified which allows most clients to use a single connection to the Streaming API. Placing long parameters in the URL may cause the request to be rejected for excessive URL length.
The default access level allows up to 200 track keywords, 400 follow userids and 10 1-degree location boxes. Increased access levels allow 80,000 follow userids ("shadow" role), 400,000 follow userids ("birddog" role), 10,000 track keywords ("restricted track" role), 200,000 track keywords ("partner track" role), and 200 10-degree location boxes ("locRestricted" role). Increased track access levels also pass a higher proportion of statuses before limiting the stream.

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.
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
Deprecated. use getFilterStream(FilterQuery) instead

Returns public statuses that match one or more filter predicates. At least one predicate parameter, follow, locations, or track must be specified. Multiple parameters may be specified which allows most clients to use a single connection to the Streaming API. Placing long parameters in the URL may cause the request to be rejected for excessive URL length.
The default access level allows up to 200 track keywords, 400 follow userids and 10 1-degree location boxes. Increased access levels allow 80,000 follow userids ("shadow" role), 400,000 follow userids ("birddog" role), 10,000 track keywords ("restricted track" role), 200,000 track keywords ("partner track" role), and 200 10-degree location boxes ("locRestricted" role). Increased track access levels also pass a higher proportion of statuses before limiting the stream.

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

startHandler

private void startHandler(TwitterStream.StreamHandlingThread handler)

cleanup

public void cleanup()

setStatusListener

public void setStatusListener(StatusListener statusListener)