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.impl;
27 import java.util.concurrent.ConcurrentHashMap;
29 import org.onap.appc.metricservice.MetricRegistry;
30 import org.onap.appc.metricservice.metric.Counter;
31 import org.onap.appc.metricservice.metric.Metric;
32 import org.onap.appc.metricservice.metric.MetricBuilderFactory;
33 import org.onap.appc.metricservice.metric.impl.MetricBuilderFactoryImpl;
34 import org.onap.appc.metricservice.policy.PolicyBuilderFactory;
35 import org.onap.appc.metricservice.policy.PublishingPolicy;
36 import org.onap.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl;
39 public class MetricRegistryImpl implements MetricRegistry {
41 private Map<String,Metric> concurrentMetricMap=new ConcurrentHashMap<String,Metric>();
43 public MetricRegistryImpl(String name) {
48 public boolean register(Metric metric) {
49 if(concurrentMetricMap.get(metric.name())==null){
50 concurrentMetricMap.put(metric.name(),metric);
57 public void attach(PublishingPolicy publishPolicy) {
62 public MetricBuilderFactory metricBuilderFactory() {
63 return new MetricBuilderFactoryImpl();
67 public PolicyBuilderFactory policyBuilderFactory() {
68 return new PolicyBuilderFactoryImpl() ;
72 public Counter counter(String value) {
73 if(concurrentMetricMap.get(value)!=null )
74 return (Counter)concurrentMetricMap.get(value) ;
81 public Counter[] counters() {
82 return (Counter[])concurrentMetricMap.values().toArray();
86 public Metric[] metrics() {
87 java.util.Collection<Metric> var = concurrentMetricMap.values();
88 return var.toArray(new Metric[var.size()]);
92 public Metric metric(String metricName) {
93 return concurrentMetricMap.get(metricName);
97 public void dispose() {
98 concurrentMetricMap.clear();