camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1233162 - in /camel/trunk/components/camel-twitter/src: main/java/org/apache/camel/component/twitter/ main/java/org/apache/camel/component/twitter/consumer/streaming/ test/resources/
Date Thu, 19 Jan 2012 04:38:42 GMT
Author: davsclaus
Date: Thu Jan 19 04:38:41 2012
New Revision: 1233162

URL: http://svn.apache.org/viewvc?rev=1233162&view=rev
Log:
CAMEL-4908: Fixes for camel-twitter. Thanks to Bilgin for the patch. Fixed CS.

Modified:
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/FilterConsumer.java
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/StreamingConsumer.java
    camel/trunk/components/camel-twitter/src/test/resources/test-options.properties

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java?rev=1233162&r1=1233161&r2=1233162&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java
Thu Jan 19 04:38:41 2012
@@ -30,6 +30,7 @@ public class TwitterConfiguration {
     private int delay = 60;
     private String type;
     private String locations;
+    private String userIds;
 
     public void checkComplete() {
         if (consumerKey.isEmpty() || consumerSecret.isEmpty() || accessToken.isEmpty()
@@ -118,4 +119,12 @@ public class TwitterConfiguration {
     public void setLocations(String locations) {
         this.locations = locations;
     }
+
+    public String getUserIds() {
+        return userIds;
+    }
+
+    public void setUserIds(String userIds) {
+        this.userIds = userIds;
+    }
 }

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/FilterConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/FilterConsumer.java?rev=1233162&r1=1233161&r2=1233162&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/FilterConsumer.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/FilterConsumer.java
Thu Jan 19 04:38:41 2012
@@ -30,22 +30,46 @@ public class FilterConsumer extends Stre
 
     public FilterConsumer(TwitterEndpoint te) {
         super(te);
-
         TwitterStream twitterStream = new TwitterStreamFactory(te.getProperties().getConfiguration()).getInstance();
         twitterStream.addListener(this);
+        FilterQuery filterQuery = createFilter(te);
+        twitterStream.filter(filterQuery);
+    }
 
+    private FilterQuery createFilter(TwitterEndpoint te) {
+        FilterQuery filterQuery = new FilterQuery();
         String allLocationsString = te.getProperties().getLocations();
-        String[] locationStrings = allLocationsString.split(";");
-        double[][] locations = new double[locationStrings.length][2];
-        for (int i = 0; i < locationStrings.length; i++) {
-            String[] coords = locationStrings[i].split(",");
-            locations[i][0] = Double.valueOf(coords[0]);
-            locations[i][1] = Double.valueOf(coords[1]);
+        if (allLocationsString != null) {
+            String[] locationStrings = allLocationsString.split(";");
+            double[][] locations = new double[locationStrings.length][2];
+            for (int i = 0; i < locationStrings.length; i++) {
+                String[] coords = locationStrings[i].split(",");
+                locations[i][0] = Double.valueOf(coords[0]);
+                locations[i][1] = Double.valueOf(coords[1]);
+            }
+            filterQuery.locations(locations);
         }
 
-        FilterQuery fq = new FilterQuery();
-        fq.locations(locations);
+        String keywords = te.getProperties().getKeywords();
+        if (keywords != null && keywords.length() > 0) {
+            filterQuery.track(keywords.split(","));
+        }
+        
+        String userIds = te.getProperties().getUserIds();
+        if (userIds != null) {
+            String[] stringUserIds = userIds.split(",");
+            long[] longUserIds = new long[stringUserIds.length];
+            for (int i = 0; i < stringUserIds.length; i++) {
+                longUserIds[i] = Long.valueOf(stringUserIds[i]);
+            }
+            filterQuery.follow(longUserIds);
+        }
+        
+        if (allLocationsString == null && keywords == null && userIds ==
null) {
+            throw new IllegalArgumentException("At least one filter parameter is required");
+        }
 
-        twitterStream.filter(fq);
+        filterQuery.setIncludeEntities(true);
+        return filterQuery;
     }
 }

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/StreamingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/StreamingConsumer.java?rev=1233162&r1=1233161&r2=1233162&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/StreamingConsumer.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/streaming/StreamingConsumer.java
Thu Jan 19 04:38:41 2012
@@ -35,8 +35,8 @@ import twitter4j.TwitterException;
 public class StreamingConsumer extends Twitter4JConsumer implements StatusListener {
 
     TwitterEndpoint te;
-    private List<Status> receivedStatuses = new ArrayList<Status>();
-    private boolean clear;
+    private final List<Status> receivedStatuses = new ArrayList<Status>();
+    private volatile boolean clear;
 
     public StreamingConsumer(TwitterEndpoint te) {
         this.te = te;
@@ -44,7 +44,7 @@ public class StreamingConsumer extends T
 
     public List<Status> pollConsume() throws TwitterException {
         clear = true;
-        return Collections.unmodifiableList(receivedStatuses);
+        return Collections.unmodifiableList(new ArrayList<Status>(receivedStatuses));
     }
 
     public List<Status> directConsume() throws TwitterException {
@@ -54,8 +54,6 @@ public class StreamingConsumer extends T
 
     @Override
     public void onException(Exception ex) {
-        // TODO Auto-generated method stub
-
     }
 
     @Override
@@ -69,20 +67,14 @@ public class StreamingConsumer extends T
 
     @Override
     public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
-        // TODO Auto-generated method stub
-
     }
 
     @Override
     public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
-        // TODO Auto-generated method stub
-
     }
 
     @Override
     public void onScrubGeo(long userId, long upToStatusId) {
-        // TODO Auto-generated method stub
-
     }
 
 }

Modified: camel/trunk/components/camel-twitter/src/test/resources/test-options.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/test/resources/test-options.properties?rev=1233162&r1=1233161&r2=1233162&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/test/resources/test-options.properties (original)
+++ camel/trunk/components/camel-twitter/src/test/resources/test-options.properties Thu Jan
19 04:38:41 2012
@@ -16,7 +16,7 @@
 ## ---------------------------------------------------------------------------
 
 #This uses the Twitter 'cameltweet' account for testing purposes.
-+consumer.key=NMqaca1bzXsOcZhP2XlwA
-+consumer.secret=VxNQiRLwwKVD0K9mmfxlTTbVdgRpriORypnUbHhxeQw
-+access.token=26693234-W0YjxL9cMJrC0VZZ4xdgFMymxIQ10LeL1K8YlbBY
-+access.token.secret=BZD51BgzbOdFstWZYsqB5p5dbuuDV12vrOdatzhY4E
\ No newline at end of file
+consumer.key=NMqaca1bzXsOcZhP2XlwA
+consumer.secret=VxNQiRLwwKVD0K9mmfxlTTbVdgRpriORypnUbHhxeQw
+access.token=26693234-W0YjxL9cMJrC0VZZ4xdgFMymxIQ10LeL1K8YlbBY
+access.token.secret=BZD51BgzbOdFstWZYsqB5p5dbuuDV12vrOdatzhY4E
\ No newline at end of file



Mime
View raw message