diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java index 114d12f0bc..45d5f50d98 100644 --- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java +++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java @@ -54,8 +54,6 @@ abstract class AbstractTwitterMessageSource extends IntegrationObjectSupport private volatile long lastPollForTweet; - private final TwitterPollingTask twitterPollingTask = new TwitterPollingTask(); - private volatile MetadataStore metadataStore; private volatile String metadataKey; @@ -130,7 +128,7 @@ abstract class AbstractTwitterMessageSource extends IntegrationObjectSupport // need to wait longer return null; } - this.twitterPollingTask.run(); + this.refreshTweetQueueIfNecessary(); tweet = this.tweets.poll(); this.lastPollForTweet = currentTime; } @@ -159,6 +157,22 @@ abstract class AbstractTwitterMessageSource extends IntegrationObjectSupport } } + private void refreshTweetQueueIfNecessary() { + try { + if (tweets.size() <= prefetchThreshold) { + List tweets = pollForTweets(lastEnqueuedId); + if (!CollectionUtils.isEmpty(tweets)) { + enqueueAll(tweets); + } + } + } + catch (RuntimeException e) { + throw e; + } + catch (Exception e) { + throw new MessagingException("failed while polling Twitter", e); + } + } /** * Subclasses must implement this to return tweets. @@ -167,27 +181,6 @@ abstract class AbstractTwitterMessageSource extends IntegrationObjectSupport protected abstract List pollForTweets(long sinceId); - private class TwitterPollingTask implements Runnable { - - public void run() { - try { - if (tweets.size() <= prefetchThreshold) { - List tweets = pollForTweets(lastEnqueuedId); - if (!CollectionUtils.isEmpty(tweets)) { - enqueueAll(tweets); - } - } - } - catch (RuntimeException e) { - throw e; - } - catch (Exception e) { - throw new MessagingException("failed while polling Twitter", e); - } - } - } - - private static class TweetComparator implements Comparator { public int compare(Tweet tweet1, Tweet tweet2) {