void initializationCallback(Event *e) { DataObjectRefList dObjs = e->getDataObjectList(); for (DataObjectRefList::iterator it = dObjs.begin(); it != dObjs.end(); it++) { DataObjectRef dObj = *it; if (!purger->isResponsibleForDataObject(dObj)) { continue; } double now = (Timeval::now()).getTimeAsSecondsDouble(); double then = (dObj->getReceiveOrCreateTime()).getTimeAsSecondsDouble(); const Attribute *attr = dObj->getAttribute(purger->getMetricField(), "*", 1); double ttl = atof(attr->getValue().c_str()); if (now < (then + ttl + purger->getMinDBTimeS())) { purger->schedulePurge(dObj); } else { kernel->getDataStore()->deleteDataObject(dObj, purger->getKeepInBloomfilter()); } } }
void CachePurgerRelTTL::schedulePurge( DataObjectRef &dObj) { if (!isResponsibleForDataObject(dObj)) { HAGGLE_ERR("Cannot schedule purge for DO not responsible for\n"); return; } const Attribute *attr = dObj->getAttribute(metricField, "*", 1); if (!attr) { HAGGLE_ERR("Attribute not specified\n"); return; } double now = (Timeval::now()).getTimeAsSecondsDouble(); double ttl = atof(attr->getValue().c_str()); double then = (dObj->getReceiveOrCreateTime()).getTimeAsSecondsDouble(); double expTime = ttl - (now - then); expTime = expTime > minDBtimeS ? expTime : minDBtimeS; getKernel()->addEvent(new Event(deleteCallback, dObj, expTime)); }