refactored 'task' inner class into a private method for simplicity

This commit is contained in:
Mark Fisher
2010-11-18 19:48:14 -05:00
parent 382e074f59
commit 262adbaeab

View File

@@ -54,8 +54,6 @@ abstract class AbstractTwitterMessageSource<T> 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<T> 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<T> extends IntegrationObjectSupport
}
}
private void refreshTweetQueueIfNecessary() {
try {
if (tweets.size() <= prefetchThreshold) {
List<Tweet> 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<T> extends IntegrationObjectSupport
protected abstract List<Tweet> pollForTweets(long sinceId);
private class TwitterPollingTask implements Runnable {
public void run() {
try {
if (tweets.size() <= prefetchThreshold) {
List<Tweet> 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<Tweet> {
public int compare(Tweet tweet1, Tweet tweet2) {