X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager-facade-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Ffacade%2Fxml%2Fmapping%2Fconfig%2FServiceRegistryWrapper.java;h=0d04194af669a55e25023cf1122a7e1b4806f267;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hp=054c064a361a5e14e2f81b58d03853649501196b;hpb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;p=controller.git diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java index 054c064a36..0d04194af6 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/ServiceRegistryWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -9,7 +9,7 @@ package org.opendaylight.controller.config.facade.xml.mapping.config; import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.Map; import javax.management.InstanceNotFoundException; import javax.management.ObjectName; @@ -21,72 +21,66 @@ public class ServiceRegistryWrapper { private final ServiceReferenceReadableRegistry configServiceRefRegistry; - public ServiceRegistryWrapper(ServiceReferenceReadableRegistry configServiceRefRegistry) { + public ServiceRegistryWrapper(final ServiceReferenceReadableRegistry configServiceRefRegistry) { this.configServiceRefRegistry = configServiceRefRegistry; } - public ObjectName getByServiceAndRefName(String namespace, String serviceType, String refName) { + public ObjectName getByServiceAndRefName(final String namespace, final String serviceType, final String refName) { Map>> mappedServices = getMappedServices(); Map> serviceNameToRefNameToInstance = mappedServices.get(namespace); Preconditions.checkArgument(serviceNameToRefNameToInstance != null, - "No service mapped to %s:%s:%s. Wrong namespace, available namespaces: %s", - namespace, serviceType, refName, mappedServices.keySet()); + "No service mapped to %s:%s:%s. Wrong namespace, available namespaces: %s", namespace, serviceType, + refName, mappedServices.keySet()); Map refNameToInstance = serviceNameToRefNameToInstance.get(serviceType); Preconditions.checkArgument(refNameToInstance != null, - "No service mapped to %s:%s:%s. Wrong service type, available service types: %s" - , namespace, serviceType, refName, serviceNameToRefNameToInstance.keySet()); + "No service mapped to %s:%s:%s. Wrong service type, available service types: %s", namespace, + serviceType, refName, serviceNameToRefNameToInstance.keySet()); String instanceId = refNameToInstance.get(refName); Preconditions.checkArgument(instanceId != null, - "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s" - ,namespace, serviceType, refName, refNameToInstance.keySet()); + "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s", namespace, serviceType, + refName, refNameToInstance.keySet()); Services.ServiceInstance serviceInstance = Services.ServiceInstance.fromString(instanceId); Preconditions.checkArgument(serviceInstance != null, - "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s" - ,namespace, serviceType, refName, refNameToInstance.keySet()); + "No service mapped to %s:%s:%s. Wrong ref name, available ref names: %s", namespace, serviceType, + refName, refNameToInstance.keySet()); - String qNameOfService = configServiceRefRegistry.getServiceInterfaceName(namespace, serviceType); + String serviceName = configServiceRefRegistry.getServiceInterfaceName(namespace, serviceType); try { /* - Remove transaction name as this is redundant - will be stripped in DynamicWritableWrapper, - and makes it hard to compare with service references got from MXBean attributes - */ - return ObjectNameUtil.withoutTransactionName( - configServiceRefRegistry.getServiceReference(qNameOfService, refName)); - } catch (InstanceNotFoundException e) { - throw new IllegalArgumentException("No serviceInstance mapped to " + refName - + " under service name " + serviceType + " , " + refNameToInstance.keySet(), e); + * Remove transaction name as this is redundant - will be stripped in + * DynamicWritableWrapper, and makes it hard to compare with service references + * got from MXBean attributes + */ + return ObjectNameUtil + .withoutTransactionName(configServiceRefRegistry.getServiceReference(serviceName, refName)); + } catch (final InstanceNotFoundException e) { + throw new IllegalArgumentException("No serviceInstance mapped to " + refName + " under service name " + + serviceType + " , " + refNameToInstance.keySet(), e); } } public Map>> getMappedServices() { - Map>> retVal = Maps.newHashMap(); + Map>> retVal = new HashMap<>(); Map> serviceMapping = configServiceRefRegistry.getServiceMapping(); - for (Map.Entry> qNameToRefNameEntry : serviceMapping.entrySet()){ - for (String refName : qNameToRefNameEntry.getValue().keySet()) { + for (Map.Entry> nameToRefEntry : serviceMapping.entrySet()) { + for (String refName : nameToRefEntry.getValue().keySet()) { - ObjectName on = qNameToRefNameEntry.getValue().get(refName); + ObjectName on = nameToRefEntry.getValue().get(refName); Services.ServiceInstance si = Services.ServiceInstance.fromObjectName(on); - QName qname = QName.create(qNameToRefNameEntry.getKey()); + QName qname = QName.create(nameToRefEntry.getKey()); String namespace = qname.getNamespace().toString(); - Map> serviceToRefs = retVal.get(namespace); - if(serviceToRefs==null) { - serviceToRefs = Maps.newHashMap(); - retVal.put(namespace, serviceToRefs); - } + Map> serviceToRefs = retVal.computeIfAbsent(namespace, + k -> new HashMap<>()); String localName = qname.getLocalName(); - Map refsToSis = serviceToRefs.get(localName); - if(refsToSis==null) { - refsToSis = Maps.newHashMap(); - serviceToRefs.put(localName, refsToSis); - } + Map refsToSis = serviceToRefs.computeIfAbsent(localName, k -> new HashMap<>()); Preconditions.checkState(!refsToSis.containsKey(refName), "Duplicate reference name %s for service %s:%s, now for instance %s", refName, namespace,