camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1436214 - /camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
Date Mon, 21 Jan 2013 07:33:15 GMT
Author: ningjiang
Date: Mon Jan 21 07:33:15 2013
New Revision: 1436214

URL: http://svn.apache.org/viewvc?rev=1436214&view=rev
Log:
CAMEL-5982 enable the filterOld option on the SearchProducer

Modified:
    camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java

Modified: camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java?rev=1436214&r1=1436213&r2=1436214&view=diff
==============================================================================
--- camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
(original)
+++ camel/trunk/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/producer/SearchProducer.java
Mon Jan 21 07:33:15 2013
@@ -29,7 +29,7 @@ import twitter4j.Twitter;
 
 public class SearchProducer extends Twitter4JProducer {
 
-    private long lastId;
+    private volatile long lastId;
 
     public SearchProducer(TwitterEndpoint te) {
         super(te);
@@ -37,6 +37,7 @@ public class SearchProducer extends Twit
 
     @Override
     public void process(Exchange exchange) throws Exception {
+        long myLastId = lastId;
         // keywords from header take precedence
         String keywords = exchange.getIn().getHeader(TwitterConstants.TWITTER_KEYWORDS, String.class);
         if (keywords == null) {
@@ -48,8 +49,8 @@ public class SearchProducer extends Twit
         }
 
         Query query = new Query(keywords);
-        if (lastId != 0) {
-            query.setSinceId(lastId);
+        if (te.getProperties().isFilterOld() && myLastId != 0) {
+            query.setSinceId(myLastId);
         }
 
         Twitter twitter = te.getProperties().getTwitter();
@@ -57,14 +58,20 @@ public class SearchProducer extends Twit
         QueryResult results = twitter.search(query);
         List<Status> list = results.getTweets();
 
-        for (Status t : list) {
-            long newId = t.getId();
-            if (newId > lastId) {
-                lastId = newId;
+        if (te.getProperties().isFilterOld()) {
+            for (Status t : list) {
+                long newId = t.getId();
+                if (newId > myLastId) {
+                    myLastId = newId;
+                }
             }
         }
 
         exchange.getIn().setBody(list);
+        // update the lastId after finished the processing
+        if (myLastId > lastId) {
+            lastId = myLastId;
+        }
     }
 
 }



Mime
View raw message