2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.metricservice.impl;
29 import java.util.concurrent.ConcurrentHashMap;
31 import org.onap.appc.metricservice.MetricRegistry;
32 import org.onap.appc.metricservice.metric.Counter;
33 import org.onap.appc.metricservice.metric.Metric;
34 import org.onap.appc.metricservice.metric.MetricBuilderFactory;
35 import org.onap.appc.metricservice.metric.impl.MetricBuilderFactoryImpl;
36 import org.onap.appc.metricservice.policy.PolicyBuilderFactory;
37 import org.onap.appc.metricservice.policy.PublishingPolicy;
38 import org.onap.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl;
41 public class MetricRegistryImpl implements MetricRegistry {
43 private Map<String, Metric> concurrentMetricMap = new ConcurrentHashMap<>();
45 public MetricRegistryImpl(String name) {
50 public boolean register(Metric metric) {
51 return (concurrentMetricMap.putIfAbsent(metric.name(), metric) == null);
55 public void attach(PublishingPolicy publishPolicy) {
60 public MetricBuilderFactory metricBuilderFactory() {
61 return new MetricBuilderFactoryImpl();
65 public PolicyBuilderFactory policyBuilderFactory() {
66 return new PolicyBuilderFactoryImpl() ;
70 public Counter counter(String value) {
71 return (Counter)concurrentMetricMap.get(value);
75 public Counter[] counters() {
76 return (Counter[])concurrentMetricMap.values().toArray();
80 public Metric[] metrics() {
81 java.util.Collection<Metric> var = concurrentMetricMap.values();
82 return var.toArray(new Metric[var.size()]);
86 public Metric metric(String metricName) {
87 return concurrentMetricMap.get(metricName);
91 public void dispose() {
92 concurrentMetricMap.clear();