Skip to content

Commit

Permalink
TFJ-651 support stall_warnings event
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Jul 17, 2012
1 parent c0660ad commit 3f4ded9
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public interface Configuration extends HttpClientConfiguration

boolean isUserStreamRepliesAllEnabled();

boolean isStallWarningsEnabled();

String getMediaProvider();

String getMediaProviderAPIKey();
Expand Down
149 changes: 82 additions & 67 deletions twitter4j-core/src/main/java/twitter4j/conf/ConfigurationBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ConfigurationBase implements Configuration, java.io.Serializable {

private boolean userStreamRepliesAllEnabled;

private boolean stallWarningsEnabled;

private String mediaProvider;

private String mediaProviderAPIKey;
Expand Down Expand Up @@ -181,6 +183,7 @@ protected ConfigurationBase() {
setDispatcherImpl("twitter4j.internal.async.DispatcherImpl");

setUserStreamRepliesAllEnabled(false);
setStallWarningsEnabled(true);
String isDalvik;
try {
isDalvik = System.getProperty(DALVIK, dalvikDetected);
Expand Down Expand Up @@ -657,6 +660,15 @@ protected final void setUserStreamRepliesAllEnabled(boolean enabled) {
this.userStreamRepliesAllEnabled = enabled;
}

@Override
public boolean isStallWarningsEnabled() {
return stallWarningsEnabled;
}

protected final void setStallWarningsEnabled(boolean stallWarningsEnabled) {
this.stallWarningsEnabled = stallWarningsEnabled;
}

@Override
public String getMediaProvider() {
return this.mediaProvider;
Expand Down Expand Up @@ -700,63 +712,15 @@ static String fixURL(boolean useSSL, String url) {
}
}

@Override
public int hashCode() {
int result = (debug ? 1 : 0);
result = 31 * result + (userAgent != null ? userAgent.hashCode() : 0);
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (useSSL ? 1 : 0);
result = 31 * result + (prettyDebug ? 1 : 0);
result = 31 * result + (gzipEnabled ? 1 : 0);
result = 31 * result + (httpProxyHost != null ? httpProxyHost.hashCode() : 0);
result = 31 * result + (httpProxyUser != null ? httpProxyUser.hashCode() : 0);
result = 31 * result + (httpProxyPassword != null ? httpProxyPassword.hashCode() : 0);
result = 31 * result + httpProxyPort;
result = 31 * result + httpConnectionTimeout;
result = 31 * result + httpReadTimeout;
result = 31 * result + httpStreamingReadTimeout;
result = 31 * result + httpRetryCount;
result = 31 * result + httpRetryIntervalSeconds;
result = 31 * result + maxTotalConnections;
result = 31 * result + defaultMaxPerRoute;
result = 31 * result + (oAuthConsumerKey != null ? oAuthConsumerKey.hashCode() : 0);
result = 31 * result + (oAuthConsumerSecret != null ? oAuthConsumerSecret.hashCode() : 0);
result = 31 * result + (oAuthAccessToken != null ? oAuthAccessToken.hashCode() : 0);
result = 31 * result + (oAuthAccessTokenSecret != null ? oAuthAccessTokenSecret.hashCode() : 0);
result = 31 * result + (oAuthRequestTokenURL != null ? oAuthRequestTokenURL.hashCode() : 0);
result = 31 * result + (oAuthAuthorizationURL != null ? oAuthAuthorizationURL.hashCode() : 0);
result = 31 * result + (oAuthAccessTokenURL != null ? oAuthAccessTokenURL.hashCode() : 0);
result = 31 * result + (oAuthAuthenticationURL != null ? oAuthAuthenticationURL.hashCode() : 0);
result = 31 * result + (restBaseURL != null ? restBaseURL.hashCode() : 0);
result = 31 * result + (searchBaseURL != null ? searchBaseURL.hashCode() : 0);
result = 31 * result + (streamBaseURL != null ? streamBaseURL.hashCode() : 0);
result = 31 * result + (userStreamBaseURL != null ? userStreamBaseURL.hashCode() : 0);
result = 31 * result + (siteStreamBaseURL != null ? siteStreamBaseURL.hashCode() : 0);
result = 31 * result + (uploadBaseURL != null ? uploadBaseURL.hashCode() : 0);
result = 31 * result + (dispatcherImpl != null ? dispatcherImpl.hashCode() : 0);
result = 31 * result + asyncNumThreads;
result = 31 * result + (jsonStoreEnabled ? 1 : 0);
result = 31 * result + (mbeanEnabled ? 1 : 0);
result = 31 * result + (userStreamRepliesAllEnabled ? 1 : 0);
result = 31 * result + (mediaProvider != null ? mediaProvider.hashCode() : 0);
result = 31 * result + (mediaProviderAPIKey != null ? mediaProviderAPIKey.hashCode() : 0);
result = 31 * result + (mediaProviderParameters != null ? mediaProviderParameters.hashCode() : 0);
result = 31 * result + (clientVersion != null ? clientVersion.hashCode() : 0);
result = 31 * result + (clientURL != null ? clientURL.hashCode() : 0);
result = 31 * result + (IS_DALVIK ? 1 : 0);
result = 31 * result + (IS_GAE ? 1 : 0);
result = 31 * result + (requestHeaders != null ? requestHeaders.hashCode() : 0);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ConfigurationBase)) return false;
if (o == null || getClass() != o.getClass()) return false;

ConfigurationBase that = (ConfigurationBase) o;

if (IS_DALVIK != that.IS_DALVIK) return false;
if (IS_GAE != that.IS_GAE) return false;
if (asyncNumThreads != that.asyncNumThreads) return false;
if (debug != that.debug) return false;
if (defaultMaxPerRoute != that.defaultMaxPerRoute) return false;
Expand All @@ -765,19 +729,18 @@ public boolean equals(Object o) {
if (httpProxyPort != that.httpProxyPort) return false;
if (httpReadTimeout != that.httpReadTimeout) return false;
if (httpRetryCount != that.httpRetryCount) return false;
if (httpRetryIntervalSeconds != that.httpRetryIntervalSeconds)
return false;
if (httpStreamingReadTimeout != that.httpStreamingReadTimeout)
return false;
if (httpRetryIntervalSeconds != that.httpRetryIntervalSeconds) return false;
if (httpStreamingReadTimeout != that.httpStreamingReadTimeout) return false;
if (includeEntitiesEnabled != that.includeEntitiesEnabled) return false;
if (includeRTsEnabled != that.includeRTsEnabled) return false;
if (jsonStoreEnabled != that.jsonStoreEnabled) return false;
if (maxTotalConnections != that.maxTotalConnections) return false;
if (mbeanEnabled != that.mbeanEnabled) return false;
if (prettyDebug != that.prettyDebug) return false;
if (stallWarningsEnabled != that.stallWarningsEnabled) return false;
if (useSSL != that.useSSL) return false;
if (userStreamRepliesAllEnabled != that.userStreamRepliesAllEnabled)
return false;
if (clientURL != null ? !clientURL.equals(that.clientURL) : that.clientURL != null)
return false;
if (userStreamRepliesAllEnabled != that.userStreamRepliesAllEnabled) return false;
if (clientURL != null ? !clientURL.equals(that.clientURL) : that.clientURL != null) return false;
if (clientVersion != null ? !clientVersion.equals(that.clientVersion) : that.clientVersion != null)
return false;
if (dispatcherImpl != null ? !dispatcherImpl.equals(that.dispatcherImpl) : that.dispatcherImpl != null)
Expand Down Expand Up @@ -810,12 +773,10 @@ public boolean equals(Object o) {
return false;
if (oAuthRequestTokenURL != null ? !oAuthRequestTokenURL.equals(that.oAuthRequestTokenURL) : that.oAuthRequestTokenURL != null)
return false;
if (password != null ? !password.equals(that.password) : that.password != null)
return false;
if (password != null ? !password.equals(that.password) : that.password != null) return false;
if (requestHeaders != null ? !requestHeaders.equals(that.requestHeaders) : that.requestHeaders != null)
return false;
if (restBaseURL != null ? !restBaseURL.equals(that.restBaseURL) : that.restBaseURL != null)
return false;
if (restBaseURL != null ? !restBaseURL.equals(that.restBaseURL) : that.restBaseURL != null) return false;
if (searchBaseURL != null ? !searchBaseURL.equals(that.searchBaseURL) : that.searchBaseURL != null)
return false;
if (siteStreamBaseURL != null ? !siteStreamBaseURL.equals(that.siteStreamBaseURL) : that.siteStreamBaseURL != null)
Expand All @@ -824,16 +785,67 @@ public boolean equals(Object o) {
return false;
if (uploadBaseURL != null ? !uploadBaseURL.equals(that.uploadBaseURL) : that.uploadBaseURL != null)
return false;
if (user != null ? !user.equals(that.user) : that.user != null)
return false;
if (userAgent != null ? !userAgent.equals(that.userAgent) : that.userAgent != null)
return false;
if (user != null ? !user.equals(that.user) : that.user != null) return false;
if (userAgent != null ? !userAgent.equals(that.userAgent) : that.userAgent != null) return false;
if (userStreamBaseURL != null ? !userStreamBaseURL.equals(that.userStreamBaseURL) : that.userStreamBaseURL != null)
return false;

return true;
}

@Override
public int hashCode() {
int result = (debug ? 1 : 0);
result = 31 * result + (userAgent != null ? userAgent.hashCode() : 0);
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (useSSL ? 1 : 0);
result = 31 * result + (prettyDebug ? 1 : 0);
result = 31 * result + (gzipEnabled ? 1 : 0);
result = 31 * result + (httpProxyHost != null ? httpProxyHost.hashCode() : 0);
result = 31 * result + (httpProxyUser != null ? httpProxyUser.hashCode() : 0);
result = 31 * result + (httpProxyPassword != null ? httpProxyPassword.hashCode() : 0);
result = 31 * result + httpProxyPort;
result = 31 * result + httpConnectionTimeout;
result = 31 * result + httpReadTimeout;
result = 31 * result + httpStreamingReadTimeout;
result = 31 * result + httpRetryCount;
result = 31 * result + httpRetryIntervalSeconds;
result = 31 * result + maxTotalConnections;
result = 31 * result + defaultMaxPerRoute;
result = 31 * result + (oAuthConsumerKey != null ? oAuthConsumerKey.hashCode() : 0);
result = 31 * result + (oAuthConsumerSecret != null ? oAuthConsumerSecret.hashCode() : 0);
result = 31 * result + (oAuthAccessToken != null ? oAuthAccessToken.hashCode() : 0);
result = 31 * result + (oAuthAccessTokenSecret != null ? oAuthAccessTokenSecret.hashCode() : 0);
result = 31 * result + (oAuthRequestTokenURL != null ? oAuthRequestTokenURL.hashCode() : 0);
result = 31 * result + (oAuthAuthorizationURL != null ? oAuthAuthorizationURL.hashCode() : 0);
result = 31 * result + (oAuthAccessTokenURL != null ? oAuthAccessTokenURL.hashCode() : 0);
result = 31 * result + (oAuthAuthenticationURL != null ? oAuthAuthenticationURL.hashCode() : 0);
result = 31 * result + (restBaseURL != null ? restBaseURL.hashCode() : 0);
result = 31 * result + (searchBaseURL != null ? searchBaseURL.hashCode() : 0);
result = 31 * result + (streamBaseURL != null ? streamBaseURL.hashCode() : 0);
result = 31 * result + (userStreamBaseURL != null ? userStreamBaseURL.hashCode() : 0);
result = 31 * result + (siteStreamBaseURL != null ? siteStreamBaseURL.hashCode() : 0);
result = 31 * result + (uploadBaseURL != null ? uploadBaseURL.hashCode() : 0);
result = 31 * result + (dispatcherImpl != null ? dispatcherImpl.hashCode() : 0);
result = 31 * result + asyncNumThreads;
result = 31 * result + (includeRTsEnabled ? 1 : 0);
result = 31 * result + (includeEntitiesEnabled ? 1 : 0);
result = 31 * result + (jsonStoreEnabled ? 1 : 0);
result = 31 * result + (mbeanEnabled ? 1 : 0);
result = 31 * result + (userStreamRepliesAllEnabled ? 1 : 0);
result = 31 * result + (stallWarningsEnabled ? 1 : 0);
result = 31 * result + (mediaProvider != null ? mediaProvider.hashCode() : 0);
result = 31 * result + (mediaProviderAPIKey != null ? mediaProviderAPIKey.hashCode() : 0);
result = 31 * result + (mediaProviderParameters != null ? mediaProviderParameters.hashCode() : 0);
result = 31 * result + (clientVersion != null ? clientVersion.hashCode() : 0);
result = 31 * result + (clientURL != null ? clientURL.hashCode() : 0);
result = 31 * result + (IS_DALVIK ? 1 : 0);
result = 31 * result + (IS_GAE ? 1 : 0);
result = 31 * result + (requestHeaders != null ? requestHeaders.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "ConfigurationBase{" +
Expand Down Expand Up @@ -871,9 +883,12 @@ public String toString() {
", uploadBaseURL='" + uploadBaseURL + '\'' +
", dispatcherImpl='" + dispatcherImpl + '\'' +
", asyncNumThreads=" + asyncNumThreads +
", includeRTsEnabled=" + includeRTsEnabled +
", includeEntitiesEnabled=" + includeEntitiesEnabled +
", jsonStoreEnabled=" + jsonStoreEnabled +
", mbeanEnabled=" + mbeanEnabled +
", userStreamRepliesAllEnabled=" + userStreamRepliesAllEnabled +
", stallWarningsEnabled=" + stallWarningsEnabled +
", mediaProvider='" + mediaProvider + '\'' +
", mediaProviderAPIKey='" + mediaProviderAPIKey + '\'' +
", mediaProviderParameters=" + mediaProviderParameters +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public final class PropertyConfiguration extends ConfigurationBase implements ja
public static final String JSON_STORE_ENABLED = "jsonStoreEnabled";
public static final String MBEAN_ENABLED = "mbeanEnabled";
public static final String STREAM_USER_REPLIES_ALL = "stream.user.repliesAll";
public static final String STREAM_STALL_WARNINGS_ENABLED = "stream.enableStallWarnings";

public static final String MEDIA_PROVIDER = "media.provider";
public static final String MEDIA_PROVIDER_API_KEY = "media.providerAPIKey";
Expand Down Expand Up @@ -354,6 +355,9 @@ private void setFieldsWithPrefix(Properties props, String prefix) {
if (notNull(props, prefix, STREAM_USER_REPLIES_ALL)) {
setUserStreamRepliesAllEnabled(getBoolean(props, prefix, STREAM_USER_REPLIES_ALL));
}
if (notNull(props, prefix, STREAM_STALL_WARNINGS_ENABLED)) {
setStallWarningsEnabled(getBoolean(props, prefix, STREAM_STALL_WARNINGS_ENABLED));
}
if (notNull(props, prefix, MEDIA_PROVIDER)) {
setMediaProvider(getString(props, prefix, MEDIA_PROVIDER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class JSONObjectType implements java.io.Serializable {
public static final JSONObjectType DIRECT_MESSAGE = new JSONObjectType("DIRECT_MESSAGE");
public static final JSONObjectType DELETE = new JSONObjectType("DELETE");
public static final JSONObjectType LIMIT = new JSONObjectType("LIMIT");
public static final JSONObjectType STALL_WARNING = new JSONObjectType("STALL_WARNING");
public static final JSONObjectType SCRUB_GEO = new JSONObjectType("SCRUB_GEO");
public static final JSONObjectType FRIENDS = new JSONObjectType("FRIENDS");
public static final JSONObjectType FAVORITE = new JSONObjectType("FAVORITE");
Expand Down Expand Up @@ -89,6 +90,8 @@ public static JSONObjectType determine(JSONObject json) {
return DELETE;
} else if (!json.isNull("limit")) {
return LIMIT;
} else if (!json.isNull("warning")) {
return STALL_WARNING;
} else if (!json.isNull("scrub_geo")) {
return SCRUB_GEO;
} else if (!json.isNull("friends")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,31 @@ public static void main(String[] args) throws TwitterException {
}

StatusListener listener = new StatusListener() {
@Override
public void onStatus(Status status) {
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}

@Override
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}

@Override
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}

@Override
public void onStallWarning(StallWarning warning) {
System.out.println("Got stall warning:" + warning);
}

public void onException(Exception ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,32 @@ public class PrintFirehoseStream {
public static void main(String[] args) throws TwitterException {
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
StatusListener listener = new StatusListener() {
@Override
public void onStatus(Status status) {
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}

@Override
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}

@Override
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}

@Override
public void onStallWarning(StallWarning warning) {
System.out.println("Got stall warning:" + warning);
}

@Override
public void onException(Exception ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,31 @@ public class PrintLinksStream extends StatusAdapter {
public static void main(String[] args) throws TwitterException {
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
StatusListener listener = new StatusListener() {
@Override
public void onStatus(Status status) {
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}

@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}

@Override
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}

@Override
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}

@Override
public void onStallWarning(StallWarning warning) {
System.out.println("Got stall warning:" + warning);
}

public void onException(Exception ex) {
ex.printStackTrace();
}
Expand Down
Loading

0 comments on commit 3f4ded9

Please sign in to comment.