package beacon;

public class ServerMaintenanceThread extends Thread {
  BUserInfoDatabase idb;
  BUserLocationDatabase ldb;
  String dump;

  ServerMaintenanceThread(BUserInfoDatabase buid, BUserLocationDatabase buld, String dbfile){
    idb = buid;
    ldb = buld;
    dump = dbfile;
  }

  public void run(){
    int iexpct=0;
    int ddumpct=0;
    while(true){
      // This gets done every two minutes
      ldb.expire();

      // The info expiry only gets done once a day
      if(iexpct==0)
	idb.expire();
      iexpct++;
      if(iexpct >= (24*30))
	iexpct = 0;

      // The disk dump gets done every hour
      if(ddumpct==0)
	idb.dump(dump);
      ddumpct++;
      if(ddumpct >= 1)
	ddumpct = 0;

      // Sleep for two minutes
      //      try { Thread.sleep(1000*60*2); } catch (Exception e) { }
      try { Thread.sleep(1000*10); } catch (Exception e) { }
    }
  }
}
