Methods Summary |
---|
public RSSInfo | getInfo(java.lang.String url)Get an RSSInfo object from cache, or create a new
subscritpion if its not in the cache.
if (cache.containsKey(url)) {
return (RSSInfo)cache.get(url);
}
// add to cache
RSSInfo rInfo = new RSSInfo();
rInfo.parse(url);
cache.put(url, rInfo);
// create new subscription
RSSSubscription newSub = new RSSSubscription();
newSub.url = url;
newSub.updateFreq = UPDATE_FREQ;
putSubscription(newSub);
return rInfo;
|
public static apexample.model.RSSSubscriber | getInstance()Get a reference to the subscriber. Use this instead of the
constructor.
/* initialize singelton the singleton */
subscriber = new RSSSubscriber();
subscriber.start();
return subscriber;
|
private synchronized apexample.model.RSSSubscriber$RSSSubscription | getSubscription()Wait for next subscription to be ready for refresh
while(true) {
while(subscriptions.size() == 0) {
try { wait(); } catch(InterruptedException ie) {}
}
RSSSubscription nextSub = (RSSSubscription)subscriptions.first();
long curTime = System.currentTimeMillis();
if(curTime >= nextSub.nextUpdate) {
subscriptions.remove(nextSub);
return nextSub;
}
try {
wait(nextSub.nextUpdate - curTime);
} catch(InterruptedException ie) {}
}
|
private synchronized void | putSubscription(apexample.model.RSSSubscriber$RSSSubscription subs)Add a subscription
subs.nextUpdate = System.currentTimeMillis() + subs.updateFreq;
subscriptions.add(subs);
notify();
|
public void | quit()Cause this subscriber to stop
this.quit = true;
|
public void | run()Update subscriptions as they become ready for refresh
while(!quit) {
RSSSubscription subs = getSubscription();
try {
RSSInfo rInfo = new RSSInfo();
rInfo.parse(subs.url);
cache.put(subs.url, rInfo);
} catch(Exception ex) {
ex.printStackTrace();
}
putSubscription(subs);
}
|