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