create new objects not list classes in NeutronNorthboundRSApplication 43/68343/3
authorMichael Vorburger <vorburger@redhat.com>
Thu, 15 Feb 2018 23:48:38 +0000 (00:48 +0100)
committerMichael Vorburger <vorburger@redhat.com>
Mon, 19 Feb 2018 17:57:18 +0000 (17:57 +0000)
this is related to & will be required by future work discussed on
https://lists.opendaylight.org/pipermail/neutron-dev/2018-February/001590.html

Change-Id: I18f0257bfe1dd346cc900c6dfbd4731c09b9ba75
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronNorthboundRSApplication.java

index 90e57edeea98d13a6432ec96c38cb8266708f9f6..0ef16a0ff80caed0fea9bfbf4e073ebe1e11c624 100644 (file)
@@ -5,11 +5,12 @@
  * 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.northbound.api;
 
+import static java.util.Collections.emptySet;
+
+import com.google.common.collect.ImmutableSet;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import javax.ws.rs.core.Application;
@@ -19,52 +20,55 @@ import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
  * This class is an instance of javax.ws.rs.core.Application and is used to return the classes
  * that will be instantiated for JAXRS processing. This is necessary
  * because package scanning in jersey doesn't yet work in OSGi environment.
- *
  */
 public final class NeutronNorthboundRSApplication extends Application {
     private static final int HASHMAP_SIZE = 3;
 
     @Override
     public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<>();
-        // northbound URIs
-        classes.add(NeutronNetworksNorthbound.class);
-        classes.add(NeutronSubnetsNorthbound.class);
-        classes.add(NeutronPortsNorthbound.class);
-        classes.add(NeutronRoutersNorthbound.class);
-        classes.add(NeutronFloatingIpsNorthbound.class);
-        classes.add(NeutronSecurityGroupsNorthbound.class);
-        classes.add(NeutronSecurityRulesNorthbound.class);
-        classes.add(NeutronFirewallNorthbound.class);
-        classes.add(NeutronFirewallPolicyNorthbound.class);
-        classes.add(NeutronFirewallRulesNorthbound.class);
-        classes.add(NeutronLoadBalancerNorthbound.class);
-        classes.add(NeutronLoadBalancerListenerNorthbound.class);
-        classes.add(NeutronLoadBalancerPoolNorthbound.class);
-        classes.add(NeutronLoadBalancerHealthMonitorNorthbound.class);
-        classes.add(NeutronMeteringLabelsNorthbound.class);
-        classes.add(NeutronMeteringLabelRulesNorthbound.class);
-        classes.add(NeutronVpnServicesNorthbound.class);
-        classes.add(NeutronVpnIkePoliciesNorthbound.class);
-        classes.add(NeutronVpnIpSecPoliciesNorthbound.class);
-        classes.add(NeutronVpnIpSecSiteConnectionsNorthbound.class);
-        classes.add(NeutronBgpvpnsNorthbound.class);
-        classes.add(NeutronL2gatewayNorthbound.class);
-        classes.add(NeutronL2gatewayConnectionNorthbound.class);
-        classes.add(NeutronSFCFlowClassifiersNorthbound.class);
-        classes.add(NeutronSFCPortPairsNorthbound.class);
-        classes.add(NeutronSFCPortPairGroupsNorthbound.class);
-        classes.add(NeutronSFCPortChainsNorthbound.class);
-        classes.add(NeutronQosPolicyNorthbound.class);
-        classes.add(NeutronTrunksNorthbound.class);
-        classes.add(NeutronTapServiceNorthbound.class);
-        classes.add(NeutronTapFlowNorthbound.class);
-
-        return classes;
+        return emptySet();
     }
 
     @Override
     public Set<Object> getSingletons() {
+        return ImmutableSet.builderWithExpectedSize(32)
+                .add(getMOXyJsonProvider())
+                // Northbound URIs JAX RS Resources:
+                .add(new NeutronNetworksNorthbound())
+                .add(new NeutronSubnetsNorthbound())
+                .add(new NeutronPortsNorthbound())
+                .add(new NeutronRoutersNorthbound())
+                .add(new NeutronFloatingIpsNorthbound())
+                .add(new NeutronSecurityGroupsNorthbound())
+                .add(new NeutronSecurityRulesNorthbound())
+                .add(new NeutronFirewallNorthbound())
+                .add(new NeutronFirewallPolicyNorthbound())
+                .add(new NeutronFirewallRulesNorthbound())
+                .add(new NeutronLoadBalancerNorthbound())
+                .add(new NeutronLoadBalancerListenerNorthbound())
+                .add(new NeutronLoadBalancerPoolNorthbound())
+                .add(new NeutronLoadBalancerHealthMonitorNorthbound())
+                .add(new NeutronMeteringLabelsNorthbound())
+                .add(new NeutronMeteringLabelRulesNorthbound())
+                .add(new NeutronVpnServicesNorthbound())
+                .add(new NeutronVpnIkePoliciesNorthbound())
+                .add(new NeutronVpnIpSecPoliciesNorthbound())
+                .add(new NeutronVpnIpSecSiteConnectionsNorthbound())
+                .add(new NeutronBgpvpnsNorthbound())
+                .add(new NeutronL2gatewayNorthbound())
+                .add(new NeutronL2gatewayConnectionNorthbound())
+                .add(new NeutronSFCFlowClassifiersNorthbound())
+                .add(new NeutronSFCPortPairsNorthbound())
+                .add(new NeutronSFCPortPairGroupsNorthbound())
+                .add(new NeutronSFCPortChainsNorthbound())
+                .add(new NeutronQosPolicyNorthbound())
+                .add(new NeutronTrunksNorthbound())
+                .add(new NeutronTapServiceNorthbound())
+                .add(new NeutronTapFlowNorthbound())
+                .build();
+    }
+
+    private MOXyJsonProvider getMOXyJsonProvider() {
         MOXyJsonProvider moxyJsonProvider = new MOXyJsonProvider();
 
         moxyJsonProvider.setAttributePrefix("@");
@@ -81,8 +85,6 @@ public final class NeutronNorthboundRSApplication extends Application {
         moxyJsonProvider.setNamespacePrefixMapper(namespacePrefixMapper);
         moxyJsonProvider.setNamespaceSeparator(':');
 
-        Set<Object> set = new HashSet<>(1);
-        set.add(moxyJsonProvider);
-        return set;
+        return moxyJsonProvider;
     }
 }