2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.metricservice.metric.impl;
26 import org.onap.appc.metricservice.metric.MetricType;
27 import org.onap.appc.metricservice.metric.PrimitiveCounter;
29 import java.text.SimpleDateFormat;
30 import java.util.Calendar;
31 import java.util.HashMap;
32 import java.util.concurrent.atomic.AtomicLong;
35 public class DefaultPrimitiveCounter implements PrimitiveCounter {
37 private MetricType metricType;
38 private AtomicLong counter = new AtomicLong();
40 private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
41 private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
43 public DefaultPrimitiveCounter(String name, MetricType metricType, long counter) {
45 this.metricType = metricType;
46 this.counter.set(counter);
49 public DefaultPrimitiveCounter(String name, MetricType metricType) {
52 this.metricType = metricType;
56 public void increment() {
61 public void increment(long value) {
62 this.counter.incrementAndGet();
66 public void decrement() {
71 public void decrement(long value) {
72 this.counter.decrementAndGet();
77 return this.counter.get();
81 public String name() {
88 Calendar cal = Calendar.getInstance();
89 lastResetTime = dateTimeFormat.format(cal.getTime());
93 public String toString() {
94 return "DefaultPrimitiveCounter{" + "name='" + name + '\'' + ", metricType=" + metricType + ", counter="
95 + counter.get() + '}';
99 public MetricType type() {
100 return this.metricType;
104 public HashMap<String, String> getMetricsOutput() {
105 return new HashMap<>();
109 public String getLastModified() {
110 return lastResetTime;