/*-
* ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.appc.metricservice.metric.impl;
+package org.onap.appc.metricservice.metric.impl;
+
+import org.onap.appc.metricservice.metric.MetricType;
+import org.onap.appc.metricservice.metric.PrimitiveCounter;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicLong;
-import org.openecomp.appc.metricservice.metric.MetricType;
-import org.openecomp.appc.metricservice.metric.PrimitiveCounter;
+public class DefaultPrimitiveCounter implements PrimitiveCounter {
+ private String name;
+ private MetricType metricType;
+ private AtomicLong counter = new AtomicLong();
-public class DefaultPrimitiveCounter implements PrimitiveCounter{
- private String name;
- private MetricType metricType;
- private long counter;
+ private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
+ private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
public DefaultPrimitiveCounter(String name, MetricType metricType, long counter) {
this.name = name;
this.metricType = metricType;
- this.counter = counter;
+ this.counter.set(counter);
}
public DefaultPrimitiveCounter(String name, MetricType metricType) {
- this.counter=0;
+ this.counter.set(0);
this.name = name;
this.metricType = metricType;
}
@Override
public void increment(long value) {
- this.counter+=value;
+ this.counter.incrementAndGet();
}
@Override
@Override
public void decrement(long value) {
- this.counter-=value;
+ this.counter.decrementAndGet();
}
@Override
public long value() {
- return this.counter;
+ return this.counter.get();
}
@Override
@Override
public void reset() {
- this.counter=0 ;
+ this.counter.set(0);
+ Calendar cal = Calendar.getInstance();
+ lastResetTime = dateTimeFormat.format(cal.getTime());
}
@Override
public String toString() {
- return "DefaultPrimitiveCounter{" +
- "name='" + name + '\'' +
- ", metricType=" + metricType +
- ", counter=" + counter +
- '}';
+ return "DefaultPrimitiveCounter{" + "name='" + name + '\'' + ", metricType=" + metricType + ", counter="
+ + counter.get() + '}';
}
@Override
public MetricType type() {
return this.metricType;
}
+
+ @Override
+ public HashMap<String, String> getMetricsOutput() {
+ return new HashMap<>();
+ }
+
+ @Override
+ public String getLastModified() {
+ return lastResetTime;
+ }
}