Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
TFJ-58 aggregate codes that read system properties
Browse files Browse the repository at this point in the history
git-svn-id: http://yusuke.homeip.net/svn/twitter4j/trunk@299 117b7e0d-5933-0410-9d29-ab41bb01d86b
  • Loading branch information
yusuke committed May 20, 2009
1 parent 08bad56 commit 400d30b
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 75 deletions.
3 changes: 1 addition & 2 deletions jdk142test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home
$JAVA_HOME/bin/java -version
$JAVA_HOME/bin/java -Dtwitter4j.debug=true -cp lib/junit.jar:target/classes:target/test-classes/ junit.textui.TestRunner twitter4j.TwitterTestUnit
$JAVA_HOME/bin/java -Dtwitter4j.debug=true -cp lib/junit.jar:target/classes:target/test-classes/ junit.textui.TestRunner twitter4j.AsyncTwitterTest
$JAVA_HOME/bin/java -Dtwitter4j.debug=true -cp lib/junit.jar:target/classes:target/test-classes/ junit.textui.TestRunner twitter4j.Twitter4JTestSuite

19 changes: 18 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@
<target>jsr14</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
<manifest>
<addDefaultSpecificationEntries>true
</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true
</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -102,7 +118,8 @@
<goal>jar</goal>
</goals>
<configuration>
<excludePackageNames>twitter4j.org.json</excludePackageNames>
<excludePackageNames>twitter4j.org.json
</excludePackageNames>
</configuration>
</execution>
</executions>
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/twitter4j/AsyncTwitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2511,13 +2511,7 @@ private Dispatcher getDispatcher(){
throw new IllegalStateException("Already shut down");
}
if (null == dispatcher) {
int numThreads = 1;
try {
numThreads = Integer.parseInt(System.getProperty("twitter4j.async.numThreads"));
} catch (NumberFormatException nfe) {

}
dispatcher = new Dispatcher("Twitter4J Async Dispatcher", numThreads);
dispatcher = new Dispatcher("Twitter4J Async Dispatcher", Configuration.getNumberOfAsyncThreads());
}
return dispatcher;
}
Expand Down
215 changes: 215 additions & 0 deletions src/main/java/twitter4j/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
Copyright (c) 2007-2009, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package twitter4j;

import java.util.Properties;
import java.io.IOException;

/**
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public class Configuration {
private static Properties defaultProperty = new Properties();
static{
try {
defaultProperty.load(Configuration.class.getResourceAsStream("/META-INF/twitter4j.properties"));
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
}
defaultProperty.setProperty("twitter4j.clientVersion", Version.getVersion());
}

public static String getCilentVersion(){
return getProperty("twitter4j.clientVersion");
}
public static String getCilentVersion(String clientVersion){
return getProperty("twitter4j.clientVersion", clientVersion);
}
public static String getSource(){
return getProperty("twitter4j.source");
}
public static String getSource(String source){
return getProperty("twitter4j.source", source);
}
public static String getProxyHost(){
return getProperty("twitter4j.http.proxyHost");
}
public static String getProxyHost(String proxyHost){
return getProperty("twitter4j.http.proxyHost", proxyHost);
}
public static String getProxyUser(){
return getProperty("twitter4j.http.proxyUser");
}
public static String getProxyUser(String user){
return getProperty("twitter4j.http.proxyUser", user);
}
public static String getClientURL(){
return getProperty("twitter4j.clientURL");
}
public static String getClientURL(String clientURL){
return getProperty("twitter4j.clientURL", clientURL);
}

public static String getProxyPassword(){
return getProperty("twitter4j.http.proxyPassword");
}
public static String getProxyPassword(String password){
return getProperty("twitter4j.http.proxyPassword", password);
}
public static int getProxyPort(){
return getIntProperty("twitter4j.http.proxyPort");
}
public static int getProxyPort(int port){
return getIntProperty("twitter4j.http.proxyPort", port);
}
public static int getConnectionTimeout(){
return getIntProperty("twitter4j.http.connectionTimeout");
}
public static int getConnectionTimeout(int connectionTimeout){
return getIntProperty("twitter4j.http.connectionTimeout", connectionTimeout);
}
public static int getReadTimeout(){
return getIntProperty("twitter4j.http.readTimeout");
}
public static int getReadTimeout(int readTimeout){
return getIntProperty("twitter4j.http.readTimeout", readTimeout);
}

public static String getUser() {
return getProperty("twitter4j.user");
}
public static String getUser(String userId) {
return getProperty("twitter4j.user", userId);
}

public static String getPassword() {
return getProperty("twitter4j.password");
}
public static String getPassword(String password) {
return getProperty("twitter4j.password", password);
}

public static String getUserAgent() {
return getProperty("twitter4j.http.userAgent");
}
public static String getUserAgent(String userAgent) {
return getProperty("twitter4j.http.userAgent", userAgent);
}

public static String getOAuthConsumerKey() {
return getProperty("twitter4j.oauth.consumerKey");
}
public static String getOAuthConsumerKey(String consumerKey) {
return getProperty("twitter4j.oauth.consumerKey", consumerKey);
}

public static String getOAuthConsumerSecret() {
return getProperty("twitter4j.oauth.consumerSecret");
}
public static String getOAuthConsumerSecret(String consumerSecret) {
return getProperty("twitter4j.oauth.consumerSecret", consumerSecret);
}

public static boolean getBoolean(String name) {
String value = getProperty(name);
return Boolean.valueOf(value);
}

public static int getIntProperty(String name) {
String value = getProperty(name);
try{
return Integer.parseInt(value);
}catch(NumberFormatException nfe){
return -1;
}
}
public static int getIntProperty(String name, int fallbackValue) {
String value = getProperty(name, String.valueOf(fallbackValue));
try{
return Integer.parseInt(value);
}catch(NumberFormatException nfe){
return -1;
}
}
public static long getLongProperty(String name) {
String value = getProperty(name);
try{
return Long.parseLong(value);
}catch(NumberFormatException nfe){
return -1;
}
}

public static String getProperty(String name) {
return getProperty(name, null);
}
public static String getProperty(String name, String fallbackValue) {
String value = System.getProperty(name, fallbackValue);
if(null == value){
value = defaultProperty.getProperty(name);
}
if(null == value){
String fallback = defaultProperty.getProperty(name + ".fallback");
if(null != fallback){
value = System.getProperty(fallback);
}
}
return replace(value);
}
private static String replace(String value){
if(null == value){
return value;
}
String newValue = value;
int openBrace = 0;
if(-1 != (openBrace = value.indexOf("{", openBrace))){
int closeBrace = value.indexOf("}", openBrace);
if(closeBrace > (openBrace+1)){
String name = value.substring(openBrace + 1, closeBrace);
if(name.length() > 0){
newValue = value.substring(0,openBrace) + getProperty(name)
+ value.substring(closeBrace + 1);

}
}
}
if (newValue.equals(value)) {
return value;
} else {
return replace(newValue);
}
}

public static int getNumberOfAsyncThreads() {
return getIntProperty("twitter4j.async.numThreads");
}

public static boolean getDebug() {
return getBoolean("twitter4j.debug");

}
}
2 changes: 1 addition & 1 deletion src/main/java/twitter4j/Twitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* A java reporesentation of the <a href="http://apiwiki.twitter.com/">Twitter API</a>
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public class Twitter extends TwitterSupport {
public class Twitter extends TwitterSupport implements java.io.Serializable {
private String baseURL = "http://twitter.com/";
private String searchBaseURL = "http://search.twitter.com/";
private static final long serialVersionUID = -1486360080128882436L;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/twitter4j/TwitterResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
* @see twitter4j.DirectMessage
* @see twitter4j.Status
* @see twitter4j.User
* @see twitter4j.ExtendedUser
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public class TwitterResponse implements java.io.Serializable {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/twitter4j/TwitterStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@
import java.util.List;

/**
* A java reporesentation of the <a href="http://apiwiki.twitter.com/Streaming-API-Documentation">Twitter Streamin API</a>
* A java reporesentation of the <a href="http://apiwiki.twitter.com/Streaming-API-Documentation">Twitter Streaming API</a>
*
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.0.4
*/
public class TwitterStream extends TwitterSupport {
private final static boolean DEBUG = Boolean.getBoolean("twitter4j.debug");
private final static boolean DEBUG = Configuration.getDebug();

private static final String STREAM_BASE_URL = "http://stream.twitter.com/";
private StatusListener statusListener;
private StreamHandlingThread handler = null;
private static final long serialVersionUID = -8469998455124896484L;
private int retryPerMinutes = 1;

public TwitterStream(String userId, String password) {
Expand All @@ -56,7 +55,7 @@ public TwitterStream(String userId, String password, StatusListener listener) {
this.statusListener = listener;
}

/* Streamin API */
/* Streaming API */
/**
* 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.
*
Expand Down Expand Up @@ -293,6 +292,9 @@ private String toFollowString(int[] follows) {

private synchronized void startHandler(StreamHandlingThread handler) throws TwitterException {
cleanup();
if(null == statusListener){
throw new IllegalStateException("StatusListener is not set.");
}
this.handler = handler;
this.handler.start();
}
Expand Down

0 comments on commit 400d30b

Please sign in to comment.