public boolean updateSourceStatusStop(ISource src, long queueSize, long doneQueueSize, boolean crawlerStopRequested, boolean pause, boolean pauseBySchedule, XMLConfig config) {
logger.log(" Source " + String.valueOf(src.getId()) + " ending : update status and counters");
MongoDBCollection coll = new MongoDBCollection(db,"sources");
String query = String.format("{\"id\": %1$s}", src.getId());
BasicDBObject docsearch = MongoDBHelper.JSON2BasicDBObject(query);
synchronized (sourcesCollMonitor) {
DBCursor cur = coll.getColl().find(docsearch);
if (cur.count()!=1) return false;
BasicDBObject doc = (BasicDBObject) cur.next();
BasicDBObject doc2 = (BasicDBObject) doc.copy();
doc2.put("crawl_lastpagecount", doneQueueSize);
doc2.put("crawl_pagecount", getSourcePageCount(src.getId()));
doc2.put("crawl_pagecount_success", getSourcePageCountSuccess(src.getId()));
doc2.put("crawl_pagecount_pushed", getSourcePageCountPushed(src.getId()));
// TODO: v4
/*
if (item.getDepth()==0) {
rootUrlStatusCode = statusCode;
rootUrlStatusMessage = statusMessage.trim();
}
*/
//doc2.put("crawl_status", rootUrlStatusCode);
//doc2.put("crawl_status", rootUrlStatusMessage);
/*
s += ",crawl_lastpagecount = " + String.valueOf(done.size());
s += ",crawl_pagecount = '" + pageCount + "'";
s += ",crawl_pagecount_success = '" + pageCountSuccess + "'";
s += ",crawl_pagecount_pushed = '" + pageCountPushed + "'";
s += ",crawl_status = '" + rootUrlStatusCode + "'";
s += ",crawl_status_message = '" + rootUrlStatusMessage.replace("'", "\\'") + "'";
*/
if (queueSize==0)
doc2.put("crawl_firstcompleted", "1");
if (pause) {
doc2.put("running_crawl_item_processed", doneQueueSize);
doc2.put("running_crawl_item_to_process", queueSize);
if (pauseBySchedule) {
doc2.put("crawl_process_status", ISource.CRAWL_PROCESS_STATUS_PAUSE_BY_SCHEDULE);
}
doc2.put("crawl_priority", "4");
} else {
doc2.put("running_crawl_item_processed", 0);
doc2.put("running_crawl_item_to_process", 0);
doc2.put("crawl_process_status", ISource.CRAWL_PROCESS_MODE_NONE);
//if (crawlerStopRequested) {
// doc2.put("crawl_priority", 2);
//}
//else {
doc2.put("crawl_priority", "0");
int crawlPeriod;
if (src.isOptimized())
crawlPeriod = Integer.parseInt(config.getProperty("/crawler/param[@name='period_optimized_source']", "24"));
else
crawlPeriod = Integer.parseInt(config.getProperty("/crawler/param[@name='period']", "168"));
Date read_nexttime = getNextCrawlStartDate(src.getCurrentCrawlNextTime(), crawlPeriod, Integer.parseInt(src.getCrawlPeriod()));
doc2.put("crawl_nexttime", read_nexttime);
//}
}
doc2.put("running_crawl_lastupdate", new Date());
doc2.put("crawl_lasttime_end", new Date());
doc2.put("crawl_mode", ISource.CRAWL_PROCESS_MODE_NONE);
if (src.getExtra()!=null && src.getExtra().asXml()!=null)
doc2.put("extra", src.getExtra().asXml().replaceAll("'", "''"));
else
doc2.put("extra", "");
coll.update(doc, doc2);
updateSourceLog(src, 0);
}
return true;
}