class TwitterStreamImpl extends TwitterBaseImpl implements TwitterStream
Modifier and Type | Class and Description |
---|---|
(package private) static class |
TwitterStreamImpl.Mode |
(package private) class |
TwitterStreamImpl.TwitterStreamConsumer |
Modifier and Type | Field and Description |
---|---|
private static int |
count |
private static Dispatcher |
dispatcher |
private TwitterStreamImpl.TwitterStreamConsumer |
handler |
private HttpClient |
http |
private static int |
HTTP_ERROR_INITIAL_WAIT |
private static int |
HTTP_ERROR_WAIT_CAP |
private java.util.List<ConnectionLifeCycleListener> |
lifeCycleListeners |
private static Logger |
logger |
private static int |
NO_WAIT |
private static int |
numberOfHandlers |
private static long |
serialVersionUID |
private java.lang.String |
stallWarningsGetParam |
private HttpParameter |
stallWarningsParam |
private java.util.ArrayList<StreamListener> |
streamListeners |
private static int |
TCP_ERROR_INITIAL_WAIT |
private static int |
TCP_ERROR_WAIT_CAP |
auth, conf, factory
Constructor and Description |
---|
TwitterStreamImpl(Configuration conf,
Authorization auth) |
Modifier and Type | Method and Description |
---|---|
TwitterStream |
addConnectionLifeCycleListener(ConnectionLifeCycleListener listener)
Adds a ConnectionLifeCycleListener
|
TwitterStream |
addListener(StreamListener listener) |
TwitterStream |
cleanUp()
shutdown internal stream consuming thread
|
TwitterStream |
clearListeners()
clear status listeners
|
private void |
ensureSiteStreamsListenerIsSet() |
private void |
ensureStatusStreamListenerIsSet()
check if any listener is set.
|
boolean |
equals(java.lang.Object o) |
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.
|
private StatusStream |
getCountStream(java.lang.String relativeUrl,
int count) |
private Dispatcher |
getDispatcher() |
(package private) StatusStream |
getFilterStream(FilterQuery query)
Returns public statuses that match one or more filter predicates.
|
(package private) StatusStream |
getFirehoseStream(int count)
Returns a status stream of all public statuses.
|
(package private) StatusStream |
getLinksStream(int count)
Returns a status stream of all public statuses containing links.
|
private RawStreamListener[] |
getRawStreamListeners() |
(package private) StatusStream |
getRetweetStream()
Returns a stream of all retweets.
|
(package private) StatusStream |
getSampleStream()
Returns a stream of random sample of all public statuses.
|
(package private) StatusStream |
getSampleStream(java.lang.String language)
Returns a stream of random sample of all public statuses.
|
(package private) java.io.InputStream |
getSiteStream(boolean withFollowings,
long[] follow) |
private SiteStreamsListener[] |
getSiteStreamsListeners() |
private StatusListener[] |
getStatusListeners() |
(package private) UserStream |
getUserStream(java.lang.String[] track)
User Streams provides real-time updates of all data needed to update a desktop application display.
|
int |
hashCode() |
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)
Site Streams, a new feature on the Streaming API, is now available for beta testing.
|
private void |
startHandler(TwitterStreamImpl.TwitterStreamConsumer handler) |
java.lang.String |
toString() |
private void |
updateListeners() |
TwitterStream |
user()
User Streams provides real-time updates of all data needed to update a desktop application display.
|
TwitterStream |
user(java.lang.String[] track)
User Streams provides real-time updates of all data needed to update a desktop application display.
|
addRateLimitStatusListener, ensureAuthorizationEnabled, ensureOAuthEnabled, fillInIDAndScreenName, fillInIDAndScreenName, getAuthorization, getConfiguration, getId, getOAuth2Token, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthRequestToken, getOAuthRequestToken, getOAuthRequestToken, getOAuthRequestToken, getScreenName, httpResponseReceived, invalidateOAuth2Token, onRateLimitReached, onRateLimitStatus, setFactory, setOAuth2Token, setOAuthAccessToken, setOAuthConsumer
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthAccessToken, getOAuthRequestToken, getOAuthRequestToken, getOAuthRequestToken, getOAuthRequestToken, setOAuthAccessToken, setOAuthConsumer
addRateLimitStatusListener, getAuthorization, getConfiguration, getId, getScreenName, onRateLimitReached, onRateLimitStatus
private static final long serialVersionUID
private final HttpClient http
private static final Logger logger
private final java.util.List<ConnectionLifeCycleListener> lifeCycleListeners
private TwitterStreamImpl.TwitterStreamConsumer handler
private final java.lang.String stallWarningsGetParam
private final HttpParameter stallWarningsParam
private static transient volatile Dispatcher dispatcher
private static int numberOfHandlers
private final java.util.ArrayList<StreamListener> streamListeners
private static final int TCP_ERROR_INITIAL_WAIT
private static final int TCP_ERROR_WAIT_CAP
private static final int HTTP_ERROR_INITIAL_WAIT
private static final int HTTP_ERROR_WAIT_CAP
private static final int NO_WAIT
private static int count
TwitterStreamImpl(Configuration conf, Authorization auth)
public TwitterStream firehose(int count)
TwitterStream
firehose
in interface TwitterStream
count
- Indicates the number of previous statuses to stream before transitioning to the live stream.StatusStream
,
Streaming API Methods statuses/firehoseStatusStream getFirehoseStream(int count) throws TwitterException
count
- Indicates the number of previous statuses to stream before transitioning to the live stream.TwitterException
- when Twitter service or network is unavailableStatusStream
,
Streaming API Methods statuses/firehosepublic TwitterStream links(int count)
TwitterStream
links
in interface TwitterStream
count
- Indicates the number of previous statuses to stream before transitioning to the live stream.StatusStream
,
Streaming API Methods statuses/linksStatusStream getLinksStream(int count) throws TwitterException
count
- Indicates the number of previous statuses to stream before transitioning to the live stream.TwitterException
- when Twitter service or network is unavailableStatusStream
,
Streaming API Methods statuses/linksprivate StatusStream getCountStream(java.lang.String relativeUrl, int count) throws TwitterException
TwitterException
public TwitterStream retweet()
TwitterStream
retweet
in interface TwitterStream
StatusStream
,
Streaming API Methods statuses/retweetStatusStream getRetweetStream() throws TwitterException
TwitterException
- when Twitter service or network is unavailableStatusStream
,
Streaming API: Methods statuses/retweetpublic TwitterStream sample()
TwitterStream
sample
in interface TwitterStream
StatusStream
,
Streaming API: Methods statuses/samplepublic TwitterStream sample(java.lang.String language)
TwitterStream
Only samples Tweets written in the given language.
sample
in interface TwitterStream
language
- language to be sampledStatusStream
,
Streaming API: Methods statuses/sampleStatusStream getSampleStream() throws TwitterException
TwitterException
- when Twitter service or network is unavailableStatusStream
,
Streaming API: Methods statuses/sampleStatusStream getSampleStream(java.lang.String language) throws TwitterException
Only returns tweets in the given languages
TwitterException
- when Twitter service or network is unavailableStatusStream
,
Streaming API: Methods statuses/samplepublic TwitterStream user()
TwitterStream
user
in interface TwitterStream
public TwitterStream user(java.lang.String[] track)
TwitterStream
user
in interface TwitterStream
track
- keywords to trackUserStream getUserStream(java.lang.String[] track) throws TwitterException
track
- keywords to trackTwitterException
- when Twitter service or network is unavailablepublic StreamController site(boolean withFollowings, long[] follow)
TwitterStream
site
in interface TwitterStream
withFollowings
- whether to receive status updates from people followingfollow
- an array of users to include in the streamprivate Dispatcher getDispatcher()
java.io.InputStream getSiteStream(boolean withFollowings, long[] follow) throws TwitterException
TwitterException
public TwitterStream filter(FilterQuery query)
TwitterStream
filter
in interface TwitterStream
query
- Filter queryStatusStream
,
Streaming API Methods statuses/filterpublic TwitterStream filter(java.lang.String... track)
TwitterStream
filter
in interface TwitterStream
track
- words to be filteredStatusStream getFilterStream(FilterQuery query) throws TwitterException
query
- Filter queryTwitterException
- when Twitter service or network is unavailableStatusStream
,
Streaming API Methods | Twitter Developersprivate void ensureStatusStreamListenerIsSet()
java.lang.IllegalStateException
- when no listener is set.private void ensureSiteStreamsListenerIsSet()
private void startHandler(TwitterStreamImpl.TwitterStreamConsumer handler)
public TwitterStream cleanUp()
TwitterStream
cleanUp
in interface TwitterStream
public TwitterStream shutdown()
TwitterStream
shutdown
in interface TwitterStream
public TwitterStream addConnectionLifeCycleListener(ConnectionLifeCycleListener listener)
TwitterStream
addConnectionLifeCycleListener
in interface TwitterStream
listener
- listener to be addedpublic TwitterStream addListener(StreamListener listener)
addListener
in interface TwitterStream
listener
- listener to addpublic TwitterStream onStatus(Consumer<Status> action)
onStatus
in interface TwitterStream
action
- action when receiving Statuspublic TwitterStream onException(Consumer<java.lang.Exception> action)
onException
in interface TwitterStream
action
- action when receiving TwitterExceptionpublic TwitterStream removeListener(StreamListener listener)
removeListener
in interface TwitterStream
listener
- listener to removepublic TwitterStream clearListeners()
TwitterStream
clearListeners
in interface TwitterStream
public TwitterStream replaceListener(StreamListener toBeRemoved, StreamListener toBeAdded)
TwitterStream
replaceListener
in interface TwitterStream
toBeRemoved
- listener to be removedtoBeAdded
- listener to be addedprivate void updateListeners()
private RawStreamListener[] getRawStreamListeners()
private SiteStreamsListener[] getSiteStreamsListeners()
private StatusListener[] getStatusListeners()
public boolean equals(java.lang.Object o)
equals
in class TwitterBaseImpl
public int hashCode()
hashCode
in class TwitterBaseImpl
public java.lang.String toString()
toString
in class TwitterBaseImpl