Merge OSGiBGPRibRoutingPolicyFactory 29/96129/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 May 2021 08:55:47 +0000 (10:55 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 May 2021 09:18:30 +0000 (11:18 +0200)
We have OSGi R7, hence we can use constructor injection and side-step
the need to have two additional classes.

Change-Id: I4b2bc45dc09c0be729b23452b65cc65633586f02
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/openconfig-rp-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/impl/DefaultBGPRibRoutingPolicyFactory.java
bgp/openconfig-rp-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/impl/OSGiBGPRibRoutingPolicyFactory.java [deleted file]

index 22b5d6163af73b4d0afb93e119ed9e30514d2308..78f5c06c4c12a805a9817e53f091a5417a0efd7d 100644 (file)
@@ -21,8 +21,12 @@ import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.Config;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ClusterIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 
 @Singleton
+@Component(immediate = true)
 @MetaInfServices
 public final class DefaultBGPRibRoutingPolicyFactory implements BGPRibRoutingPolicyFactory {
     private final StatementRegistryConsumer statementRegistryConsumer;
@@ -33,8 +37,9 @@ public final class DefaultBGPRibRoutingPolicyFactory implements BGPRibRoutingPol
     }
 
     @Inject
-    public DefaultBGPRibRoutingPolicyFactory(final DataBroker databroker,
-            final StatementRegistryConsumer statementRegistryConsumer) {
+    @Activate
+    public DefaultBGPRibRoutingPolicyFactory(final @Reference DataBroker databroker,
+            final @Reference StatementRegistryConsumer statementRegistryConsumer) {
         this.databroker = requireNonNull(databroker);
         this.statementRegistryConsumer = requireNonNull(statementRegistryConsumer);
     }
diff --git a/bgp/openconfig-rp-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/impl/OSGiBGPRibRoutingPolicyFactory.java b/bgp/openconfig-rp-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/impl/OSGiBGPRibRoutingPolicyFactory.java
deleted file mode 100644 (file)
index 8c076be..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.protocol.bgp.openconfig.routing.policy.impl;
-
-import static com.google.common.base.Verify.verifyNotNull;
-
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory;
-import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.StatementRegistryConsumer;
-import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.Config;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ClusterIdentifier;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-
-@Component(immediate = true)
-// FIXME: integrate with DefaultBGPRibRoutingPolicyFactory once we have OSGi R7
-public final class OSGiBGPRibRoutingPolicyFactory implements BGPRibRoutingPolicyFactory {
-    @Reference
-    DataBroker dataBroker;
-    @Reference
-    StatementRegistryConsumer statementRegistryConsumer;
-
-    private DefaultBGPRibRoutingPolicyFactory delegate;
-
-    @Override
-    public BGPRibRoutingPolicy buildBGPRibPolicy(final long localAs, final Ipv4AddressNoZone bgpId,
-            final ClusterIdentifier clusterId, final Config policyConfig) {
-        return verifyNotNull(delegate).buildBGPRibPolicy(localAs, bgpId, clusterId, policyConfig);
-    }
-
-    @Activate
-    void activate() {
-        delegate = new DefaultBGPRibRoutingPolicyFactory(dataBroker, statementRegistryConsumer);
-    }
-
-    @Deactivate
-    void deactive() {
-        delegate = null;
-    }
-}