2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.metricservice.metric.impl;
27 import org.openecomp.appc.metricservice.metric.MetricType;
28 import org.openecomp.appc.metricservice.metric.PrimitiveCounter;
30 import java.text.SimpleDateFormat;
31 import java.util.Calendar;
32 import java.util.HashMap;
33 import java.util.concurrent.atomic.AtomicLong;
36 public class DefaultPrimitiveCounter implements PrimitiveCounter {
38 private MetricType metricType;
39 private AtomicLong counter = new AtomicLong();
41 private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
42 private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
44 public DefaultPrimitiveCounter(String name, MetricType metricType, long counter) {
46 this.metricType = metricType;
47 this.counter.set(counter);
50 public DefaultPrimitiveCounter(String name, MetricType metricType) {
53 this.metricType = metricType;
57 public void increment() {
62 public void increment(long value) {
63 this.counter.incrementAndGet();
67 public void decrement() {
72 public void decrement(long value) {
73 this.counter.decrementAndGet();
78 return this.counter.get();
82 public String name() {
89 Calendar cal = Calendar.getInstance();
90 lastResetTime = dateTimeFormat.format(cal.getTime());
94 public String toString() {
95 return "DefaultPrimitiveCounter{" + "name='" + name + '\'' + ", metricType=" + metricType + ", counter="
96 + counter.get() + '}';
100 public MetricType type() {
101 return this.metricType;
105 public HashMap<String, String> getMetricsOutput() {
106 return new HashMap<>();
110 public String getLastModified() {
111 return lastResetTime;