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