private inline fetchINeutronCRUD and remove NeutronCRUDInterfaces 31/70931/3
authorMichael Vorburger <vorburger@redhat.com>
Fri, 13 Apr 2018 19:14:24 +0000 (21:14 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Tue, 17 Apr 2018 17:07:00 +0000 (19:07 +0200)
Change-Id: I94735fa65369947effe058986ecfbf68b34d7b61
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronCRUDInterfaces.java [deleted file]
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java

diff --git a/neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronCRUDInterfaces.java b/neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronCRUDInterfaces.java
deleted file mode 100644 (file)
index 7923aac..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2013, 2015 IBM Corporation 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.neutron.spi;
-
-import java.util.Collection;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class NeutronCRUDInterfaces {
-    private static final Logger LOG = LoggerFactory.getLogger(NeutronCRUDInterfaces.class);
-
-    private NeutronCRUDInterfaces() {
-        throw new UnsupportedOperationException("NeutronCRUDInterfaces class shouldn't be instantiated");
-    }
-
-    public static <T extends INeutronObject<T>, I extends INeutronCRUD<T>> I fetchINeutronCRUD(
-        Class<I> clazz, Object bundle) {
-        try {
-            BundleContext bundleCtx = FrameworkUtil.getBundle(bundle.getClass()).getBundleContext();
-            Collection<ServiceReference<I>> services = bundleCtx.getServiceReferences(clazz, null);
-            for (ServiceReference<I> service : services) {
-                return bundleCtx.getService(service);
-            }
-        } catch (InvalidSyntaxException e) {
-            LOG.error("Error in getInstances", e);
-        }
-        return null;
-    }
-}
index 1e0fdf90c9c731d20e173871fd953a5110eb2089..cfffca3fa38ad9e49978d2038e4e277cd97edafa 100644 (file)
@@ -12,14 +12,23 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.net.HttpURLConnection;
+import java.util.Collection;
 import java.util.List;
 import javax.ws.rs.core.Response;
 import org.opendaylight.neutron.spi.INeutronCRUD;
 import org.opendaylight.neutron.spi.INeutronObject;
-import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R extends INeutronRequest<T>,
         I extends INeutronCRUD<T>> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractNeutronNorthbound.class);
+
     // T extends INeutronObject<T> as 0th type argument
     private static final int NEUTRON_ARGUMENT_TYPE_INDEX = 0;
     // NeutronRequest extends INeutronRequest<T> as 1st type argument
@@ -71,13 +80,27 @@ public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R e
     protected I getNeutronCRUD() {
         // cls = I.class
         Class<I> cls = getActualTypeArgument(NEUTRON_CRUD_TYPE_INDEX);
-        I neutronCrud = NeutronCRUDInterfaces.fetchINeutronCRUD(cls, (Object) this);
+        I neutronCrud = fetchINeutronCRUD(cls, (Object) this);
         if (neutronCrud == null) {
             throw new ServiceUnavailableException(serviceUnavailable());
         }
         return neutronCrud;
     }
 
+    private static <T extends INeutronObject<T>, I extends INeutronCRUD<T>> I fetchINeutronCRUD(Class<I> clazz,
+            Object bundle) {
+        try {
+            BundleContext bundleCtx = FrameworkUtil.getBundle(bundle.getClass()).getBundleContext();
+            Collection<ServiceReference<I>> services = bundleCtx.getServiceReferences(clazz, null);
+            for (ServiceReference<I> service : services) {
+                return bundleCtx.getService(service);
+            }
+        } catch (InvalidSyntaxException e) {
+            LOG.error("Error in getInstances", e);
+        }
+        return null;
+    }
+
     protected Response show(String uuid,
             // return fields
             List<String> fields) {