private Stats getLastCallTimeCollection(
      String requestName, Map<String, Map<String, Number>> fallbackValues, long fallbackStartTime)
      throws IOException {

    File dataFile = new File(context.getResourceDataDirectory(), requestName);
    if (!dataFile.exists()) {
      return Stats.fromMap(
          fallbackValues, requestName, System.currentTimeMillis(), fallbackStartTime);
    } else {
      ObjectInputStream in = null;
      try {
        in = new ObjectInputStream(new FileInputStream(dataFile));

        Stats stats = (Stats) in.readObject();
        if (stats.serverStartTime == 0) {
          // we might get serverStartTime == 0 if the datafile comes from the old version of the
          // plugin
          // in that case just fallback to the old behavior that assumed no server restarts.
          // After that we save the new version of the stats with the start time remembered and we
          // will
          // switch to the new correct behavior from the next collection.
          stats.serverStartTime = fallbackStartTime;
        }

        return stats;
      } catch (IOException e) {
        throw new IOException(
            "Couldn't read the stored calltime data from file " + dataFile + ".", e);
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Couldn't find plugin API classes. This is serious!", e);
      } finally {
        StreamUtil.safeClose(in);
      }
    }
  }
    static Stats fromMap(
        Map<String, Map<String, Number>> map,
        String collectedMetric,
        long collectionTime,
        long serverStartTime) {

      Stats ret = new Stats();
      ret.serverStartTime = serverStartTime;
      ret.collectionTime = collectionTime;
      ret.data = new HashMap<String, StatsRecord>(map.size());

      for (Map.Entry<String, Map<String, Number>> entry : map.entrySet()) {
        StatsRecord rec = new StatsRecord();
        String methodName = entry.getKey();

        rec.invocations = entry.getValue().get("invocations").longValue();
        rec.total = entry.getValue().get(collectedMetric).longValue();

        ret.data.put(methodName, rec);
      }

      return ret;
    }