public CounterMetricValue getCounterMetricValue() { if (counter != null) { return counter; } counter = new CounterMetricValue(getTimeRange(), value); return counter; }
@Override public String toString() { return "UpdateMetricCommand{" + "metric='" + getMetric() + "'" + "resource='" + getResource() + "'" + ", value=" + getValue() + ", range=" + getTimeRange() + "}"; }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; UpdateMetricCommand other = (UpdateMetricCommand) obj; return (Double.compare(getValue(), other.getValue()) == 0) && ObjectUtil.typedEquals(getMetric(), other.getMetric()) && ObjectUtil.typedEquals(getTimeRange(), other.getTimeRange()) && ObjectUtil.typedEquals(getResource(), other.getResource()) ; }
@Override public int hashCode() { int result=ObjectUtil.hashCode(getTimeRange()); result = 31 * result + MathUtil.hashValue(getValue()); result = 31 * result + ObjectUtil.hashCode(getResource()); result = 31 * result + ObjectUtil.hashCode(getMetric()); return result; } }
@Override @InsightEndPoint public void executeCommand(UpdateMetricCommand command) { ResourceMetricKey key = command.getKey(); MetricData adapter = dataRepo.createOrGetMetricData(key); if (adapter instanceof CounterMetricDataAdapter) { CounterMetricDataAdapter mData = (CounterMetricDataAdapter) adapter; mData.increment(command.getCounterMetricValue()); return; } if (adapter instanceof GaugeMetricDataAdapter) { GaugeMetricDataAdapter mData = (GaugeMetricDataAdapter) adapter; IDataPoint point = command.getPoint(); GaugeMetricValue value = new GaugeMetricValueBuilder(command.getTimeRange()).addPoint(point.getValue()).build(); mData.addValues(singletonList(value)); return; } } }