}
private void start(final Factory<SailConnectionListener> factory) throws Exception {
NotifyingSail baseSail = new MemoryStore();
baseSail.initialize();
Sail sail = new QueueingSail(baseSail, factory.create());
try {
// Create a persistent store.
TweetStore store = new TweetStore(sail);
store.setSailConnectionListenerFactory(factory);
store.doNotRefreshCoreMetadata();
store.initialize();
try {
// Create a client for communication with Twitter.
CustomTwitterClient client = new CustomTwitterClient();
Set<User> users = TwitLogic.findFollowList(client);
Set<String> terms = TwitLogic.findTrackTerms();
final Handler<Tweet> annotator
= createAnnotator(store, client);
final SailConnection c = sail.getConnection();
//c.addConnectionListener(listener);
try {
Handler<Tweet> adder = new Handler<Tweet>() {
public boolean isOpen() {
return !closed && 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);
}
};
// Can't use a deleter here.
NullHandler<Tweet> d = new NullHandler<Tweet>();
// TODO: optionally gather historical tweets
TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), adder);
if (0 < users.size() || 0 < terms.size()) {
client.processFilterStream(users, terms, null, rLogger, d, 0);
} else {
client.processSampleStream(rLogger, d);
}
} finally {
c.close();
}
} finally {
store.shutDown();
}
} finally {
sail.shutDown();
}
}