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.DispatchingFuntionMetric;
30 import org.openecomp.appc.metricservice.metric.MetricType;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
35 public class DispatchingFuntionMetricImpl implements DispatchingFuntionMetric {
37 private MetricType metricType;
38 private long acceptedRequested;
39 private long rejectedRequest;
40 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
41 private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapRequestCounterMetricImpl.class);
43 public DispatchingFuntionMetricImpl(String name, MetricType metricType, long acceptedRequested, long rejectedRequest) {
45 this.metricType = metricType;
46 this.acceptedRequested = acceptedRequested;
47 this.rejectedRequest = rejectedRequest;
51 public void incrementAcceptedRequest() {
52 this.acceptedRequested+=1;
56 public void incrementRejectedRequest() {
57 this.rejectedRequest+=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+"["+acceptedRequested+","+rejectedRequest+"]"+"@"+(acceptedRequested+rejectedRequest);
68 logger.debug("Current value of the metric "+this.name+" :"+value);
72 logger.debug("Cant format the date.");
79 public String name() {
85 this.acceptedRequested=0;
86 this.rejectedRequest=0;
90 public MetricType type() {
91 return this.metricType;
94 public String toString() {