twitter4j

## Interface TwitterStream

All Superinterfaces:
  OAuthSupport, TwitterBase

    public interface TwitterStream
    extends OAuthSupport, TwitterBase

Since:
  Twitter4J 2.2.0
Author:
  Yusuke Yamamoto - yusuke at mac.com

### Method Summary

All Methods Instance Methods Abstract Methods Deprecated Methods
`TwitterStream` `addConnectionLifeCycleListener(ConnectionLifeCycleListener listener)` Adds a ConnectionLifeCycleListener
`TwitterStream` `addListener(StreamListener listener)`
`TwitterStream` `cleanUp()` shutdown internal stream consuming thread
`TwitterStream` `clearListeners()` clear status listeners
`TwitterStream` `filter(FilterQuery query)` Start consuming public statuses that match one or more filter predicates.
`TwitterStream` `filter(java.lang.String... track)` Start consuming public statuses that match the filter predicate.
`TwitterStream` `firehose(int count)` Starts listening on all public statuses.
`TwitterStream` `links(int count)` Starts listening on all public statuses containing links.
`TwitterStream` `onException(Consumer<java.lang.Exception> action)`
`TwitterStream` `onStatus(Consumer<Status> action)`
`TwitterStream` `removeListener(StreamListener listener)`
`TwitterStream` `replaceListener(StreamListener toBeRemoved, StreamListener toBeAdded)` replace existing listener
`TwitterStream` `retweet()` Starts listening on all retweets.
`TwitterStream` `sample()` Starts listening on random sample of all public statuses.
`TwitterStream` `sample(java.lang.String language)` Starts listening on random sample of all public statuses.
`TwitterStream` `shutdown()` Shuts down internal dispatcher thread shared by all TwitterStream instances.
`StreamController` `site(boolean withFollowings, long... follow)` Deprecated. Since Twitter4J 4.0.7
`TwitterStream` `user()` Deprecated. Since Twitter4J 4.0.7
`TwitterStream` `user(java.lang.String... track)` Deprecated. Since Twitter4J 4.0.7

### Methods inherited from interface twitter4j.auth.OAuthSupport

`getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthRequestToken, getOAuthRequestToken, getOAuthRequestToken, getOAuthRequestToken, setOAuthAccessToken, setOAuthConsumer`

### Methods inherited from interface twitter4j.TwitterBase

`addRateLimitStatusListener, getAuthorization, getConfiguration, getId, getScreenName, onRateLimitReached, onRateLimitStatus`

### Method Detail

#### addConnectionLifeCycleListener

    TwitterStream addConnectionLifeCycleListener(ConnectionLifeCycleListener listener)

Adds a ConnectionLifeCycleListener

Parameters:
  `listener` - listener to be added
Since:
  Twitter4J 2.1.7

#### addListener

    TwitterStream addListener(StreamListener listener)

Parameters:
  `listener` - listener to add
Since:
  Twitter4J 2.1.8

#### onStatus

    TwitterStream onStatus(Consumer<Status> action)

Parameters:
  `action` - action when receiving Status
Returns:
  this instance
Since:
  Twitter4J 4.0.4

#### onException

    TwitterStream onException(Consumer<java.lang.Exception> action)

Parameters:
  `action` - action when receiving TwitterException
Returns:
  this instance
Since:
  Twitter4J 4.0.4

#### removeListener

    TwitterStream removeListener(StreamListener listener)

Parameters:
  `listener` - listener to remove
Since:
  Twitter4J 4.0.0

#### clearListeners

    TwitterStream clearListeners()

clear status listeners

Since:
  Twitter4J 4.0.0

#### replaceListener

    TwitterStream replaceListener(StreamListener toBeRemoved,
                                  StreamListener toBeAdded)

replace existing listener

Parameters:
  `toBeRemoved` - listener to be removed
  `toBeAdded` - listener to be added
Since:
  Twitter4J 4.0.0

#### firehose

    TwitterStream 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`, Streaming API Methods statuses/firehose

#### links

    TwitterStream 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`, Streaming API Methods statuses/links

#### retweet

    TwitterStream 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`, Streaming API Methods statuses/retweet

#### sample

    TwitterStream 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`, Streaming API: Methods statuses/sample

#### sample

    TwitterStream sample(java.lang.String language)

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.

Only samples Tweets written in the given language.

Parameters:
  `language` - language to be sampled
Since:
  Twitter4J 2.0.10
See Also:
  `StatusStream`, Streaming API: Methods statuses/sample

#### user

    TwitterStream user()

Deprecated. Since Twitter4J 4.0.7
User Streams provides real-time updates of all data needed to update a desktop application display. Applications can request startup back-fill from the REST API and then transition to Streaming for nearly all subsequent reads. Rate limits and latency are practically eliminated. Desktop developers can stop managing rate limits and use this new data to create an entirely new user experience. On our end, we hope to reduce costs and increase site reliability.

Throws:
  `java.lang.IllegalStateException` - when non-UserStreamListener is set, or no listener is set
See Also:
  User Streams

#### user

    TwitterStream user(java.lang.String... track)

Deprecated. Since Twitter4J 4.0.7
User Streams provides real-time updates of all data needed to update a desktop application display. Applications can request startup back-fill from the REST API and then transition to Streaming for nearly all subsequent reads. Rate limits and latency are practically eliminated. Desktop developers can stop managing rate limits and use this new data to create an entirely new user experience. On our end, we hope to reduce costs and increase site reliability.

Parameters:
  `track` - keywords to track
Throws:
  `java.lang.IllegalStateException` - when non-UserStreamListener is set, or no listener is set
Since:
  Twitter4J 2.1.9
See Also:
  User Streams

#### site

    StreamController site(boolean withFollowings,
                          long... follow)

Deprecated. Since Twitter4J 4.0.7
Site Streams, a new feature on the Streaming API, is now available for beta testing. Site Streams allows services, such as web sites or mobile push services, to receive real-time updates for a large number of users without any of the hassles of managing REST API rate limits. The initial version delivers events created by, or directed to, users that have shared their OAuth token with your application. The following events are streamed immediately, and without rate limits: Home Timelines, Mentions Timelines, User Timelines, Direct Messages, Mentions, Follows, Favorites, Tweets, Retweets, Profile changes, and List changes. The following limitations must be respected during the beta period. These limitations may be changed with little advance notice. We intend to increase or remove these various limitations as we move from beta test into full production:
Limit the follow count to 100 users per stream. Clients must occasionally compact users onto a smaller number of connections to minimize the total number of connections outstanding.
Open no more than 25 new connections per second and exponentially back-off on errors.

Parameters:
  `withFollowings` - whether to receive status updates from people following
  `follow` - an array of users to include in the stream
Returns:
  controller to control the site stream
Since:
  Twitter4J 2.1.8
See Also:
  Site Streams | Twitter Developers

#### filter

    TwitterStream filter(FilterQuery query)

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
Since:
  Twitter4J 2.1.2
See Also:
  `StatusStream`, Streaming API Methods statuses/filter

#### filter

    TwitterStream filter(java.lang.String... track)

Start consuming public statuses that match the filter predicate. 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.

Parameters:
  `track` - words to be filtered
Since:
  Twitter4J 4.0.4

#### cleanUp

    TwitterStream cleanUp()

shutdown internal stream consuming thread

Since:
  Twitter4J 2.1.7

#### shutdown

    TwitterStream shutdown()

Shuts down internal dispatcher thread shared by all TwitterStream instances.

Since:
  Twitter4J 2.1.9