Moving all files to root directory
[appc.git] / appc-metric / appc-metric-bundle / src / main / java / org / openecomp / appc / metricservice / impl / MetricRegistryImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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  */
21
22 package org.openecomp.appc.metricservice.impl;
23
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26
27 import org.openecomp.appc.metricservice.MetricRegistry;
28 import org.openecomp.appc.metricservice.metric.Counter;
29 import org.openecomp.appc.metricservice.metric.Metric;
30 import org.openecomp.appc.metricservice.metric.MetricBuilderFactory;
31 import org.openecomp.appc.metricservice.metric.impl.MetricBuilderFactoryImpl;
32 import org.openecomp.appc.metricservice.policy.PolicyBuilderFactory;
33 import org.openecomp.appc.metricservice.policy.PublishingPolicy;
34 import org.openecomp.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl;
35
36
37 public class MetricRegistryImpl implements MetricRegistry {
38     private String name;
39     private Map<String,Metric> concurrentMetricMap=new ConcurrentHashMap<String,Metric>();
40
41     public MetricRegistryImpl(String name) {
42         this.name = name;
43     }
44
45     @Override
46     public boolean register(Metric metric) {
47         if(concurrentMetricMap.get(metric.name())==null){
48             concurrentMetricMap.put(metric.name(),metric);
49             return true;
50         }
51         return false;
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         if(concurrentMetricMap.get(value)!=null )
72             return (Counter)concurrentMetricMap.get(value) ;
73         else
74             return null;
75
76     }
77
78     @Override
79     public Counter[] counters() {
80         return (Counter[])concurrentMetricMap.values().toArray();
81     }
82
83     @Override
84     public Metric[] metrics() {
85         java.util.Collection<Metric> var = concurrentMetricMap.values();
86         return var.toArray(new Metric[var.size()]);
87     }
88
89     @Override
90     public Metric metric(String metricName) {
91         return concurrentMetricMap.get(metricName);
92     }
93
94     @Override
95     public void dispose() {
96         concurrentMetricMap.clear();
97     }
98 }