2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.appc.metricservice.metric.impl;
24 import java.text.SimpleDateFormat;
25 import java.util.Calendar;
26 import java.util.Date;
27 import java.util.TimeZone;
29 import org.openecomp.appc.metricservice.metric.MetricType;
30 import org.openecomp.appc.metricservice.metric.DmaapRequestCounterMetric;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
35 public class DmaapRequestCounterMetricImpl implements DmaapRequestCounterMetric {
38 private MetricType metricType;
39 private long recievedMessage;
40 private long publishedMessage;
41 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
42 private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapRequestCounterMetricImpl.class);
43 public DmaapRequestCounterMetricImpl(String name, MetricType metricType, long recievedMessage, long publishedMessage) {
45 this.metricType = metricType;
46 this.recievedMessage = recievedMessage;
47 this.publishedMessage=publishedMessage;
51 public void incrementRecievedMessage() {
52 this.recievedMessage+=1;
56 public void incrementPublishedMessage() {
57 this.publishedMessage+=1;
61 public String value() {
62 logger.debug("Value is getting calculated for metric :" + this.name);
64 Calendar cal = Calendar.getInstance();
65 cal.setTimeZone(TimeZone.getTimeZone("UTC"));
66 String date=dateFormat.format(cal.getTime());
67 String value=date+"["+recievedMessage+"],["+publishedMessage+"]";
68 logger.debug("Current value of the metric "+this.name+" :"+value);
71 logger.debug("Cant format the date.");
77 public String name() {
83 this.recievedMessage=0;
84 this.publishedMessage=0;
88 public MetricType type() {
89 return this.metricType;
93 public String toString() {