System.out.println("For more information, please see:\n"
+ " <URL:http://wiki.github.com/joshsh/twitlogic/configuring-and-running-twitlogic>.");
}
private void run() throws Exception {
Sail workingSail = new MemoryStore();
workingSail.initialize();
try {
Sail streamingSail = new MockUdpTransactionSail(workingSail);
try {
TweetStore store = new TweetStore(streamingSail);
store.doNotRefreshCoreMetadata();
store.initialize();
try {
// A connection with which to repeatedly clear the working store
final SailConnection c = workingSail.getConnection();
try {
c.begin();
// Offline persister
final TweetPersister persister = new TweetPersister(store, null);
try {
CustomTwitterClient client = new CustomTwitterClient();
TweetPersistedLogger pLogger = new TweetPersistedLogger(client.getStatistics(), persister);
// Add a "topic sniffer".
TopicSniffer topicSniffer = new TopicSniffer(pLogger);
// Add a tweet annotator.
Matcher matcher = new MultiMatcher(
new DemoAfterthoughtMatcher());
final Handler<Tweet> annotator
= new TweetAnnotator(matcher, topicSniffer);
Handler<Tweet> adder = new Handler<Tweet>() {
public boolean isOpen() {
return annotator.isOpen();
}
public void handle(final Tweet tweet) throws HandlerException {
try {
c.clear();
c.commit();
c.begin();
} catch (SailException e) {
throw new HandlerException(e);
}
annotator.handle(tweet);
}
};
Handler<Tweet> deleter = new TweetDeleter(store);
TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), adder);
client.processSampleStream(rLogger, deleter);
} finally {
persister.close();
}
} finally {
c.rollback();
c.close();
}
} finally {
store.shutDown();
}
} finally {
streamingSail.shutDown();
}
} finally {
workingSail.shutDown();
}
}