2  * ============LICENSE_START=======================================================
 
   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
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  23 package org.openecomp.appc.metricservice.impl;
 
  26 import java.util.concurrent.ConcurrentHashMap;
 
  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;
 
  38 public class MetricRegistryImpl implements MetricRegistry {
 
  40     private Map<String,Metric> concurrentMetricMap=new ConcurrentHashMap<String,Metric>();
 
  42     public MetricRegistryImpl(String name) {
 
  47     public boolean register(Metric metric) {
 
  48         if(concurrentMetricMap.get(metric.name())==null){
 
  49             concurrentMetricMap.put(metric.name(),metric);
 
  56     public void attach(PublishingPolicy publishPolicy) {
 
  61     public MetricBuilderFactory metricBuilderFactory() {
 
  62         return new MetricBuilderFactoryImpl();
 
  66     public PolicyBuilderFactory policyBuilderFactory() {
 
  67         return new PolicyBuilderFactoryImpl() ;
 
  71     public Counter counter(String value) {
 
  72         if(concurrentMetricMap.get(value)!=null )
 
  73             return (Counter)concurrentMetricMap.get(value) ;
 
  80     public Counter[] counters() {
 
  81         return (Counter[])concurrentMetricMap.values().toArray();
 
  85     public Metric[] metrics() {
 
  86         java.util.Collection<Metric> var = concurrentMetricMap.values();
 
  87         return var.toArray(new Metric[var.size()]);
 
  91     public Metric metric(String metricName) {
 
  92         return concurrentMetricMap.get(metricName);
 
  96     public void dispose() {
 
  97         concurrentMetricMap.clear();