|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectwinterwell.jtwitter.AStream
public abstract class AStream
Internal base class for UserStream and TwitterStream.
Warning from Twitter: Consuming applications must tolerate duplicate statuses, out-of-order statuses (upto 3 seconds of scrambling) and non-status messages.
| Nested Class Summary | |
|---|---|
static interface |
AStream.IListen
Use these for push-notification of incoming tweets and stream activity. |
static class |
AStream.Outage
|
| Field Summary | |
|---|---|
static int |
MAX_BUFFER
Start dropping messages after this. |
| Constructor Summary | |
|---|---|
AStream(Twitter jtwit)
|
|
| Method Summary | |
|---|---|
void |
addListener(AStream.IListen listener)
Add a listener to the front of the queue. |
void |
addOutage(AStream.Outage outage)
The stream will track outages during use (provided setAutoReconnect(boolean) is true). |
void |
clear()
Forget the past. |
void |
close()
A closed stream can be restarted. |
void |
connect()
Connect to Twitter. |
void |
fillInOutages()
Use the REST API to fill in outages when possible. |
protected void |
finalize()
|
java.util.List<TwitterEvent> |
getEvents()
|
int |
getForgotten()
|
java.util.List<AStream.Outage> |
getOutages()
|
java.util.List<java.lang.Object[]> |
getSystemEvents()
|
java.util.List<Twitter.ITweet> |
getTweets()
|
boolean |
isAlive()
|
boolean |
isConnected()
Many users will want to use isAlive() instead, which takes into
account auto-reconnect behaviour. |
java.util.List<TwitterEvent> |
popEvents()
|
java.util.List<java.lang.Object[]> |
popSystemEvents()
|
java.util.List<Twitter.ITweet> |
popTweets()
|
boolean |
removeListener(AStream.IListen listener)
|
void |
setAutoReconnect(boolean yes)
|
void |
setPreviousCount(int previousCount)
Deprecated. Twitter need to fix this :( |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static int MAX_BUFFER
| Constructor Detail |
|---|
public AStream(Twitter jtwit)
| Method Detail |
|---|
public void addListener(AStream.IListen listener)
AStream.IListen)
listener - public void addOutage(AStream.Outage outage)
setAutoReconnect(boolean) is true). This method allows you to
manually add outages (which can then be filled in using
fillInOutages()) -- e.g. to cover restarting Java.
outage - public void clear()
public void close()
close in interface java.io.Closeable
public void connect()
throws TwitterException
Do nothing if we already have a good connection. Bad or partly formed connections will be closed.
Auto-reconnect is ignored here: if there's an exception it will be thrown and a reconnect will not be attempted. This gives a fast-return.
TwitterExceptionreconnect()
public final void fillInOutages()
throws java.lang.UnsupportedOperationException
In accordance with best-practice, this method will skip over very recent
outages (which will be picked up by subsequent calls to
fillInOutages()).
From dev.twitter.com:
Do not resume REST API polling immediately after a stream failure. Wait
at least a minute or two after the initial failure before you begin REST
API polling. This delay is crucial to prevent dog-piling the REST API in
the event of a minor hiccup on the streaming API.
java.lang.UnsupportedOperationException
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic final java.util.List<TwitterEvent> getEvents()
public final int getForgotten()
Best practice is to NOT rely on this for memory management. You
should call popEvents(), popSystemEvents() and
popTweets() regularly to clear the buffers.
public final java.util.List<AStream.Outage> getOutages()
This is the actual list used. You can remove items from this list
to quietly forget about them. Use addOutage(Outage) to
add items in the correct order. The list size is capped to avoid
memory leakage.
public final java.util.List<java.lang.Object[]> getSystemEvents()
public final java.util.List<Twitter.ITweet> getTweets()
public final boolean isAlive()
public final boolean isConnected()
isAlive() instead, which takes into
account auto-reconnect behaviour.
isAlive()public final java.util.List<TwitterEvent> popEvents()
public final java.util.List<java.lang.Object[]> popSystemEvents()
This also lists reconnect events, with the number of seconds taken to reconnect.
public final java.util.List<Twitter.ITweet> popTweets()
public boolean removeListener(AStream.IListen listener)
public void setAutoReconnect(boolean yes)
yes - If true, attempt to connect if disconnected. true by default.@Deprecated public void setPreviousCount(int previousCount)
previousCount - Up to 150,000 but subject to change.
Negative values are allowed -- they mean the stream will
terminate when it reaches the end of the historical messages.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||