Merge OSGiRSVPExtensionConsumerContext 26/96126/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 May 2021 07:54:14 +0000 (09:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 12 May 2021 07:54:14 +0000 (09:54 +0200)
We have OSGi R7, hence we can use constructor injection and side-step
the need to have two additional classes.

Change-Id: Ida7548cca129e477a98de26967e641bc63f26f95
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/DefaultRSVPExtensionConsumerContext.java
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/ForwardingRSVPExtensionConsumerContext.java [deleted file]
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/OSGiRSVPExtensionConsumerContext.java [deleted file]
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/SimpleRSVPExtensionConsumerContext.java

index 0f3cb96e94afd7e7658f51779668e815eee6e5ae..65e702c72bcc343951ea4873421bf62a773729b5 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,22 +10,32 @@ package org.opendaylight.protocol.rsvp.parser.spi.pojo;
 
 import com.google.common.annotations.VisibleForTesting;
 import java.util.Arrays;
+import java.util.List;
 import java.util.ServiceLoader;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.NonNull;
 import org.kohsuke.MetaInfServices;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectRegistry;
+import org.opendaylight.protocol.rsvp.parser.spi.LabelRegistry;
+import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectRegistry;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionConsumerContext;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderActivator;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectRegistry;
+import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectRegistry;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
 
 /**
- * Starts and stops RSVPExtensionProviderActivator instances for a RSVPExtensionProviderContext.
- *
- * @author Thomas Pantelis
+ * Starts and stops {@link RSVPExtensionProviderActivator} instances for an {@link RSVPExtensionProviderContext}.
  */
 @Singleton
-@MetaInfServices(value = RSVPExtensionConsumerContext.class)
-public class DefaultRSVPExtensionConsumerContext extends ForwardingRSVPExtensionConsumerContext {
+@Component(immediate = true, service = RSVPExtensionConsumerContext.class)
+@MetaInfServices
+public final class DefaultRSVPExtensionConsumerContext implements RSVPExtensionConsumerContext {
     private final @NonNull SimpleRSVPExtensionProviderContext delegate = new SimpleRSVPExtensionProviderContext();
 
     public DefaultRSVPExtensionConsumerContext() {
@@ -41,8 +52,34 @@ public class DefaultRSVPExtensionConsumerContext extends ForwardingRSVPExtension
         extensionActivators.forEach(activator -> activator.start(delegate));
     }
 
+    @Activate
+    public DefaultRSVPExtensionConsumerContext(final @Reference(policyOption = ReferencePolicyOption.GREEDY)
+            List<RSVPExtensionProviderActivator> extensionActivators) {
+        extensionActivators.forEach(activator -> activator.start(delegate));
+    }
+
+    @Override
+    public RSVPTeObjectRegistry getRsvpRegistry() {
+        return delegate.getRsvpRegistry();
+    }
+
+    @Override
+    public XROSubobjectRegistry getXROSubobjectHandlerRegistry() {
+        return delegate.getXROSubobjectHandlerRegistry();
+    }
+
+    @Override
+    public EROSubobjectRegistry getEROSubobjectHandlerRegistry() {
+        return delegate.getEROSubobjectHandlerRegistry();
+    }
+
+    @Override
+    public RROSubobjectRegistry getRROSubobjectHandlerRegistry() {
+        return delegate.getRROSubobjectHandlerRegistry();
+    }
+
     @Override
-    RSVPExtensionConsumerContext delegate() {
-        return delegate;
+    public LabelRegistry getLabelHandlerRegistry() {
+        return delegate.getLabelHandlerRegistry();
     }
 }
diff --git a/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/ForwardingRSVPExtensionConsumerContext.java b/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/ForwardingRSVPExtensionConsumerContext.java
deleted file mode 100644 (file)
index e1fa3b7..0000000
+++ /dev/null
@@ -1,46 +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.rsvp.parser.spi.pojo;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectRegistry;
-import org.opendaylight.protocol.rsvp.parser.spi.LabelRegistry;
-import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectRegistry;
-import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionConsumerContext;
-import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectRegistry;
-import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectRegistry;
-
-abstract class ForwardingRSVPExtensionConsumerContext implements RSVPExtensionConsumerContext {
-
-    abstract @NonNull RSVPExtensionConsumerContext delegate();
-
-    @Override
-    public final RSVPTeObjectRegistry getRsvpRegistry() {
-        return delegate().getRsvpRegistry();
-    }
-
-    @Override
-    public final XROSubobjectRegistry getXROSubobjectHandlerRegistry() {
-        return delegate().getXROSubobjectHandlerRegistry();
-    }
-
-    @Override
-    public final EROSubobjectRegistry getEROSubobjectHandlerRegistry() {
-        return delegate().getEROSubobjectHandlerRegistry();
-    }
-
-    @Override
-    public final RROSubobjectRegistry getRROSubobjectHandlerRegistry() {
-        return delegate().getRROSubobjectHandlerRegistry();
-    }
-
-    @Override
-    public final LabelRegistry getLabelHandlerRegistry() {
-        return delegate().getLabelHandlerRegistry();
-    }
-}
diff --git a/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/OSGiRSVPExtensionConsumerContext.java b/rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/pojo/OSGiRSVPExtensionConsumerContext.java
deleted file mode 100644 (file)
index eb0b881..0000000
+++ /dev/null
@@ -1,45 +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.rsvp.parser.spi.pojo;
-
-import static com.google.common.base.Verify.verifyNotNull;
-
-import java.util.List;
-import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionConsumerContext;
-import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderActivator;
-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;
-import org.osgi.service.component.annotations.ReferencePolicyOption;
-
-@Component(immediate = true, service = RSVPExtensionConsumerContext.class)
-// FIXME: merge with DefaultRSVPExtensionConsumerContext once we have OSGi R7
-public final class OSGiRSVPExtensionConsumerContext extends ForwardingRSVPExtensionConsumerContext {
-    @Reference(policyOption = ReferencePolicyOption.GREEDY)
-    List<RSVPExtensionProviderActivator> extensionActivators;
-
-    private SimpleRSVPExtensionProviderContext delegate;
-
-    @Activate
-    void activate() {
-        final SimpleRSVPExtensionProviderContext local = new SimpleRSVPExtensionProviderContext();
-        extensionActivators.forEach(activator -> activator.start(local));
-        delegate = local;
-    }
-
-    @Deactivate
-    void deactivate() {
-        delegate = null;
-    }
-
-    @Override
-    RSVPExtensionConsumerContext delegate() {
-        return verifyNotNull(delegate);
-    }
-}
index b099a9e6446285340cd71515a148f72fdccfd098..d29280fc3ce28e36c5fd359441e94a183c723bd3 100644 (file)
@@ -5,7 +5,6 @@
  * 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.rsvp.parser.spi.pojo;
 
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionConsumerContext;