コード例 #1
0
  private void printStat(LiveStatistics ls) {
    long ms = ls.getTimeperiod() * 15000;
    DateTime time = new DateTime(ms);

    StringBuilder sb = new StringBuilder();
    sb.append(time.getDayOfMonth())
        .append(".")
        .append(time.getMonthOfYear())
        .append(".")
        .append(time.getYear());
    sb.append(" ")
        .append(time.getHourOfDay())
        .append(":")
        .append(time.getMinuteOfHour())
        .append(":")
        .append(time.getSecondOfMinute());

    System.out.println(
        ls.getTimeperiod()
            + ";"
            + ls.getAccountName()
            + "; date: "
            + sb.toString()
            + " value: "
            + ls.getValue()
            + " unitType: "
            + ls.getUnitType()
            + " valueType: "
            + ls.getValueType());
  }
コード例 #2
0
  @Override
  public void storeIncomingStatistics(List<LiveStatistics> liveStatisticsList) {
    for (LiveStatistics ls : liveStatisticsList) {
      long hoursSince1970 = ls.getTimeperiod() / 240;
      int fifteenSecondPeriodsSinceStartOfHour =
          LiveStatisticsUtil.getFifteensecondTimeperiodsSinceStartOfHour(ls.getTimeperiod() * 15);
      Double calculatedValue =
          LiveStatisticsUtil.calculateValueBasedOnUnitType(
              ls.getValue(), UnitType.fromValue(ls.getUnitType()));

      BasicMetricHour mhToStore =
          metricHoursToStoreHash.get(
              ls.getAccountName() + ";" + ls.getGuiPath() + ";" + hoursSince1970);
      boolean wasInStoreHash = mhToStore != null;

      if (mhToStore == null) {
        // Not in store-hash chech in metricHourCache
        mhToStore =
            metricHourCache.getIfPresent(
                ls.getAccountName() + ";" + ls.getGuiPath() + ";" + hoursSince1970);
      }

      if (mhToStore == null) {
        // Not in metricHourCache, fetch from Riak
        mhToStore = getMetricHour(ls.getAccountName(), ls.getGuiPath(), hoursSince1970);
      }

      if (mhToStore == null) {
        // Not in Riak, create
        mhToStore =
            new BasicMetricHour(
                ls.getGuiPath(),
                ls.getAccountName(),
                hoursSince1970,
                ls.getValueType(),
                ls.getUnitType());
      }

      mhToStore.getMetrics()[fifteenSecondPeriodsSinceStartOfHour] =
          LiveStatisticsUtil.calculateValueBasedOnValueType(
              ls, calculatedValue, ValueType.fromValue(ls.getValueType()));

      if (!wasInStoreHash) {
        metricHoursToStoreHash.put(
            ls.getAccountName() + ";" + ls.getGuiPath() + ";" + hoursSince1970, mhToStore);
      }
    }

    persistRecentMetricHours();
  }