}
public void run(final Handler<Dataset> datasetHandler) throws TweetStoreException, TwitterClientException, PropertyException {
store.initialize();
try {
final TweetPersister persister = new TweetPersister(store, null);
try {
Handler<Tweet> handler = new Handler<Tweet>() {
@Override
public boolean isOpen() {
return persister.isOpen() && datasetHandler.isOpen();
}
@Override
public void handle(final Tweet tweet) throws HandlerException {
System.out.println("got this tweet: " + tweet);
buffer.clear();
persister.handle(tweet);
if (0 < buffer.size()) {
Collection<Statement> c = new LinkedList<Statement>();
c.addAll(buffer);
datasetHandler.handle(new Dataset(c));
}
}
};
CustomTwitterClient client = new CustomTwitterClient();
TweetPersistedLogger pLogger = new TweetPersistedLogger(client.getStatistics(), handler);
TweetFilterCriterion crit = new TweetFilterCriterion(TwitLogic.getConfiguration());
Filter<Tweet> f = new Filter<Tweet>(crit, pLogger);
// Add a "topic sniffer".
TopicSniffer topicSniffer = new TopicSniffer(f);
// Add a tweet annotator.
Matcher matcher = new MultiMatcher(
new DemoAfterthoughtMatcher());
final Handler<Tweet> annotator
= new TweetAnnotator(matcher, topicSniffer);
Handler<Tweet> deleter = new TweetDeleter(store);
TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), annotator);
Set<User> users = TwitLogic.findFollowList(client);
Set<String> terms = TwitLogic.findTrackTerms();
if (0 < users.size() || 0 < terms.size()) {
client.processFilterStream(users, terms, null, rLogger, deleter, 0);
} else {
client.processSampleStream(rLogger, deleter);
}
} finally {
persister.close();
}
} finally {
store.shutDown();
}
}