* We want to extract the currently queued hits from the HitCounter and
* then propogate them to the db for persistent storage.
*/
public void execute() {
UserManager umgr = null;
WeblogManager wmgr = null;
try {
umgr = RollerFactory.getRoller().getUserManager();
wmgr = RollerFactory.getRoller().getWeblogManager();
} catch (RollerException ex) {
// if we can't even get the manager instances then bail now
log.error("Error getting managers", ex);
return;
}
HitCountQueue hitCounter = HitCountQueue.getInstance();
// first get the current set of hits
List currentHits = hitCounter.getHits();
// now reset the queued hits
hitCounter.resetHits();
// tally the counts, grouped by weblog handle
Map hitsTally = new HashMap();
String weblogHandle = null;
for(int i=0; i < currentHits.size(); i++) {
weblogHandle = (String) currentHits.get(i);
Long count = (Long) hitsTally.get(weblogHandle);
if(count == null) {
count = new Long(1);
} else {
count = new Long(count.longValue()+1);
}
hitsTally.put(weblogHandle, count);
}
// iterate over the tallied hits and store them in the db
try {
long startTime = System.currentTimeMillis();
WebsiteData weblog = null;
String key = null;
Iterator it = hitsTally.keySet().iterator();
while(it.hasNext()) {
key = (String) it.next();
try {
weblog = umgr.getWebsiteByHandle(key);
wmgr.incrementHitCount(weblog, ((Long)hitsTally.get(key)).intValue());
} catch (RollerException ex) {
log.error(ex);
}
}