Пример #1
0
  protected void loadDeviceFile() throws IOException {

    device_files_last_mod = SystemTime.getMonotonousTime();

    if (device_files_ref != null) {

      device_files = device_files_ref.get();
    }

    if (device_files == null) {

      Map map = FileUtil.readResilientFile(getDeviceFile());

      device_files = (Map<String, Map<String, ?>>) map.get("files");

      if (device_files == null) {

        device_files = new HashMap<String, Map<String, ?>>();
      }

      device_files_ref = new WeakReference<Map<String, Map<String, ?>>>(device_files);

      log("Loaded device file for " + getName() + ": files=" + device_files.size());
    }

    final int GC_TIME = 15000;

    new DelayedEvent(
        "Device:gc",
        GC_TIME,
        new AERunnable() {
          public void runSupport() {
            synchronized (DeviceImpl.this) {
              if (SystemTime.getMonotonousTime() - device_files_last_mod >= GC_TIME) {

                if (device_files_dirty) {

                  saveDeviceFile();
                }

                device_files = null;

              } else {

                new DelayedEvent("Device:gc2", GC_TIME, this);
              }
            }
          }
        });
  }
    private Map<String, List<Long>> getContents() {
      if (contents == null) {

        File file = getCacheFile();

        if (file.exists()) {

          System.out.println("Reading cache: " + file);

          contents = FileUtil.readResilientFile(file);

        } else {

          contents = new HashMap<String, List<Long>>();
        }
      }

      return (contents);
    }