48d1c6fac603091b042b47451a0ef982c3221d4e
[appc.git] / appc-metric / appc-metric-bundle / src / main / java / org / onap / appc / metricservice / impl / MetricRegistryImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
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.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.metricservice.impl;
27
28 import java.util.Map;
29 import java.util.concurrent.ConcurrentHashMap;
30
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;
39
40
41 public class MetricRegistryImpl implements MetricRegistry {
42     private String name;
43     private Map<String, Metric> concurrentMetricMap = new ConcurrentHashMap<>();
44
45     public MetricRegistryImpl(String name) {
46         this.name = name;
47     }
48
49     @Override
50     public boolean register(Metric metric) {
51         return (concurrentMetricMap.putIfAbsent(metric.name(), metric) == null);
52     }
53
54     @Override
55     public void attach(PublishingPolicy publishPolicy) {
56 //TODO
57     }
58
59     @Override
60     public MetricBuilderFactory metricBuilderFactory() {
61         return new MetricBuilderFactoryImpl();
62     }
63
64     @Override
65     public PolicyBuilderFactory policyBuilderFactory() {
66         return new PolicyBuilderFactoryImpl() ;
67     }
68
69     @Override
70     public Counter counter(String value) {
71         return (Counter)concurrentMetricMap.get(value);
72     }
73
74     @Override
75     public Counter[] counters() {
76         return (Counter[])concurrentMetricMap.values().toArray();
77     }
78
79     @Override
80     public Metric[] metrics() {
81         java.util.Collection<Metric> var = concurrentMetricMap.values();
82         return var.toArray(new Metric[var.size()]);
83     }
84
85     @Override
86     public Metric metric(String metricName) {
87         return concurrentMetricMap.get(metricName);
88     }
89
90     @Override
91     public void dispose() {
92         concurrentMetricMap.clear();
93     }
94 }