65389da30f01dc4ba28c7bd4d20cc34036416bc2
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.metricservice.impl;
24
25 import java.util.Map;
26 import java.util.concurrent.ConcurrentHashMap;
27
28 import org.openecomp.appc.metricservice.MetricRegistry;
29 import org.openecomp.appc.metricservice.metric.Counter;
30 import org.openecomp.appc.metricservice.metric.Metric;
31 import org.openecomp.appc.metricservice.metric.MetricBuilderFactory;
32 import org.openecomp.appc.metricservice.metric.impl.MetricBuilderFactoryImpl;
33 import org.openecomp.appc.metricservice.policy.PolicyBuilderFactory;
34 import org.openecomp.appc.metricservice.policy.PublishingPolicy;
35 import org.openecomp.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl;
36
37
38 public class MetricRegistryImpl implements MetricRegistry {
39     private String name;
40     private Map<String,Metric> concurrentMetricMap=new ConcurrentHashMap<String,Metric>();
41
42     public MetricRegistryImpl(String name) {
43         this.name = name;
44     }
45
46     @Override
47     public boolean register(Metric metric) {
48         if(concurrentMetricMap.get(metric.name())==null){
49             concurrentMetricMap.put(metric.name(),metric);
50             return true;
51         }
52         return false;
53     }
54
55     @Override
56     public void attach(PublishingPolicy publishPolicy) {
57 //TODO
58     }
59
60     @Override
61     public MetricBuilderFactory metricBuilderFactory() {
62         return new MetricBuilderFactoryImpl();
63     }
64
65     @Override
66     public PolicyBuilderFactory policyBuilderFactory() {
67         return new PolicyBuilderFactoryImpl() ;
68     }
69
70     @Override
71     public Counter counter(String value) {
72         if(concurrentMetricMap.get(value)!=null )
73             return (Counter)concurrentMetricMap.get(value) ;
74         else
75             return null;
76
77     }
78
79     @Override
80     public Counter[] counters() {
81         return (Counter[])concurrentMetricMap.values().toArray();
82     }
83
84     @Override
85     public Metric[] metrics() {
86         java.util.Collection<Metric> var = concurrentMetricMap.values();
87         return var.toArray(new Metric[var.size()]);
88     }
89
90     @Override
91     public Metric metric(String metricName) {
92         return concurrentMetricMap.get(metricName);
93     }
94
95     @Override
96     public void dispose() {
97         concurrentMetricMap.clear();
98     }
99 }