sclass DBWatcher { S dbID; RemoteDB db; long dbDate; long changeCount = 0; long exportedChangeCount = 0; *() {} *(S *dbID) {} bool live() { ret db != null; } void closeDB { if (db != null) { db.close(); db = null; } } void tryConnect { closeDB(); pcall-short { //print("Trying to connect to " + dbID); db = new RemoteDB(dbID); if (db != null) print("Connected to " + dbID + "."); } } void step { bool liveBefore = live(); if (!live()) tryConnect(); if (!liveBefore && live()) changeCount = 0; if (live() && getLiveData()) ret; closeDB(); getStaticData(); } bool getLiveData() false on exception { time2 { long cc = db.xchangeCount(); int n = db.xcount(); } bool change = cc != changeCount; if (change) ++exportedChangeCount; changeCount = cc; print((change ? "CHANGE. " : "") + "Live change count: " + cc + ", objects: " + n); true; } bool getStaticData() false on exception { File conceptsFile = getFilePossiblyGZipped(getProgramFile(dbID, "concepts.structure")); long mod = conceptsFile.lastModified(); bool change = mod != dbDate; if (change) ++exportedChangeCount; dbDate = mod; print((change ? "CHANGE. " : "") + "DB date: " + dbDate); true; } void run { repeat with sleep 1 { step(); } } }