Repository: camel Updated Branches: refs/heads/camel-2.16.x b1555bae4 -> 612ec99f8 refs/heads/master 311ecf26d -> 3e94cdd3e
CAMEL-9553: camel-twitter delay option should use the inherited option. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a4390871 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a4390871 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a4390871 Branch: refs/heads/master Commit: a4390871d083054d63f585052dd0060efce885f6 Parents: 311ecf2 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Feb 1 09:34:14 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Feb 1 09:34:14 2016 +0100 ---------------------------------------------------------------------- components/camel-twitter/src/main/docs/twitter.adoc | 8 +++++++- .../component/twitter/TwitterConfiguration.java | 13 ------------- .../component/twitter/TwitterEndpointPolling.java | 15 ++++++++++++++- .../twitter/consumer/TwitterConsumerPolling.java | 11 ++++------- .../camel/component/twitter/SearchPollingTest.java | 2 +- 5 files changed, 26 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a4390871/components/camel-twitter/src/main/docs/twitter.adoc ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/main/docs/twitter.adoc b/components/camel-twitter/src/main/docs/twitter.adoc index 927581a..6a056e6 100644 --- a/components/camel-twitter/src/main/docs/twitter.adoc +++ b/components/camel-twitter/src/main/docs/twitter.adoc @@ -128,6 +128,9 @@ Producer endpoints URI options ^^^^^^^^^^^ + + + // endpoint options: START The Twitter component supports 43 endpoint options which are listed below: @@ -141,7 +144,6 @@ The Twitter component supports 43 endpoint options which are listed below: | consumerSecret | common | | String | The consumer secret. Can also be configured on the TwitterComponent level instead. | user | common | | String | Username used for user timeline consumption direct message production etc. | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored. -| delay | consumer | 60 | int | Delay in seconds between polling from twitter. | sendEmptyMessageWhenIdle | consumer | false | boolean | If the polling consumer did not poll any files you can enable this option to send an empty message (no body) instead. | type | consumer | direct | EndpointType | Endpoint type to use. Only streaming supports event type. | distanceMetric | consumer (advanced) | km | String | Used by the non-stream geography search to search by radius using the configured metrics. The unit can either be mi for miles or km for kilometers. You need to configure all the following options: longitude latitude radius and distanceMetric. @@ -157,6 +159,7 @@ The Twitter component supports 43 endpoint options which are listed below: | backoffErrorThreshold | scheduler | | int | The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | backoffIdleThreshold | scheduler | | int | The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | backoffMultiplier | scheduler | | int | To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. +| delay | scheduler | 60000 | long | Milliseconds before the next poll. | greedy | scheduler | false | boolean | If greedy is enabled then the ScheduledPollConsumer will run immediately again if the previous run polled 1 or more messages. | initialDelay | scheduler | 1000 | long | Milliseconds before the first poll starts. | runLoggingLevel | scheduler | TRACE | LoggingLevel | The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. @@ -180,6 +183,9 @@ The Twitter component supports 43 endpoint options which are listed below: |======================================================================= // endpoint options: END + + + [[Twitter-Messageheaders]] Message headers ^^^^^^^^^^^^^^^ http://git-wip-us.apache.org/repos/asf/camel/blob/a4390871/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java index df34a4d..e586a58 100644 --- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java +++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java @@ -46,8 +46,6 @@ public class TwitterConfiguration { private String consumerSecret; @UriParam private String user; - @UriParam(label = "consumer", defaultValue = "60") - private int delay = 60; @UriParam(label = "filter") private String keywords; @UriParam(label = "filter") @@ -238,17 +236,6 @@ public class TwitterConfiguration { this.keywords = keywords; } - public int getDelay() { - return delay; - } - - /** - * Delay in seconds between polling from twitter. - */ - public void setDelay(int delay) { - this.delay = delay; - } - public EndpointType getType() { return type; } http://git-wip-us.apache.org/repos/asf/camel/blob/a4390871/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterEndpointPolling.java ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterEndpointPolling.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterEndpointPolling.java index 7b6ed34..250c33a 100644 --- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterEndpointPolling.java +++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterEndpointPolling.java @@ -35,6 +35,10 @@ import org.apache.camel.spi.UriParam; @UriEndpoint(scheme = "twitter", title = "Twitter", syntax = "twitter:kind", consumerClass = Twitter4JConsumer.class, label = "api,social") public class TwitterEndpointPolling extends DefaultPollingEndpoint implements TwitterEndpoint { + @UriParam(optionalPrefix = "consumer.", defaultValue = "" + TwitterConsumerPolling.DEFAULT_CONSUMER_DELAY, label = "consumer,scheduler", + description = "Milliseconds before the next poll.") + private long delay = TwitterConsumerPolling.DEFAULT_CONSUMER_DELAY; + @UriParam private TwitterConfiguration properties; @@ -48,7 +52,7 @@ public class TwitterEndpointPolling extends DefaultPollingEndpoint implements Tw Twitter4JConsumer twitter4jConsumer = Twitter4JFactory.getConsumer(this, getEndpointUri()); // update the pulling lastID with sinceId twitter4jConsumer.setLastId(properties.getSinceId()); - Consumer tc = new TwitterConsumerPolling(this, processor, twitter4jConsumer); + TwitterConsumerPolling tc = new TwitterConsumerPolling(this, processor, twitter4jConsumer); configureConsumer(tc); return tc; } @@ -146,4 +150,13 @@ public class TwitterEndpointPolling extends DefaultPollingEndpoint implements Tw return EndpointType.POLLING; } + /** + * Milliseconds before the next poll. + */ + @Override + public void setDelay(long delay) { + super.setDelay(delay); + this.delay = delay; + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/a4390871/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java index 3885927..6236116 100644 --- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java +++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.component.twitter.TwitterEndpoint; +import org.apache.camel.component.twitter.TwitterEndpointPolling; import org.apache.camel.component.twitter.consumer.streaming.StreamingConsumer; import org.apache.camel.impl.ScheduledPollConsumer; @@ -31,18 +32,14 @@ import org.apache.camel.impl.ScheduledPollConsumer; */ public class TwitterConsumerPolling extends ScheduledPollConsumer { + public static final long DEFAULT_CONSUMER_DELAY = 60 * 1000L; private Twitter4JConsumer twitter4jConsumer; - public TwitterConsumerPolling(TwitterEndpoint endpoint, Processor processor, + public TwitterConsumerPolling(TwitterEndpointPolling endpoint, Processor processor, Twitter4JConsumer twitter4jConsumer) { super(endpoint, processor); - + setDelay(DEFAULT_CONSUMER_DELAY); this.twitter4jConsumer = twitter4jConsumer; - - int delay = endpoint.getProperties().getDelay(); - setInitialDelay(1); - setDelay(delay); - setTimeUnit(TimeUnit.SECONDS); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/a4390871/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/SearchPollingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/SearchPollingTest.java b/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/SearchPollingTest.java index d9b1ceb..15ee335 100644 --- a/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/SearchPollingTest.java +++ b/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/SearchPollingTest.java @@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory; public class SearchPollingTest extends CamelTwitterConsumerTestSupport { @Override protected String getUri() { - return "twitter://search?type=polling&keywords=java&"; + return "twitter://search?type=polling&keywords=java&delay=5000&"; } @Override