Remove SingletonWithLifecycle, because @Singleton is not inherited
authorMichael Vorburger <vorburger@redhat.com>
Tue, 6 Sep 2016 15:20:06 +0000 (17:20 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Tue, 6 Sep 2016 16:11:17 +0000 (18:11 +0200)
and move @PostConstruct & @PreDestroy from interface Lifecycle to class
AbstractLifecycle, because method annotations are only inherited from
classes, not interfaces

See
http://stackoverflow.com/questions/7761513/is-there-something-like-annotation-inheritance-in-java,
http://stackoverflow.com/questions/5536583/the-mystery-of-java-ee-6-annotations-inheritance,
http://stackoverflow.com/questions/13015831/can-guices-singleton-annotation-be-inherited,
http://stackoverflow.com/questions/10596744/is-it-possible-for-class-to-inherit-the-annotaions-of-the-super-class,
http://stackoverflow.com/questions/4745798/why-java-classes-do-not-inherit-annotations-from-implemented-interfaces,
http://stackoverflow.com/questions/23973107/how-to-use-inherited-annotation-in-java,
http://stackoverflow.com/questions/10082619/how-do-java-method-annotations-work-in-conjunction-with-method-overriding

Note that none of the annotations in question here have an @Inherited
annotation themselves.  For @PostConstruct & @PreDestroy it works anyway
with the blueprint-maven-plugin (I've now fully tested this end-to-end
in the netvirt aclservice-impl), and should be the same with Guice +
Mycila from what I can tell looking at that implementation.

Unrelated to above, this also fixes up the features.xml which I
originally forgot.

Change-Id: I1848838fa3123cd5fd7892445d26c89cc07a476c
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
inject/src/main/java/org/opendaylight/infrautils/inject/AbstractLifecycle.java
inject/src/main/java/org/opendaylight/infrautils/inject/Lifecycle.java
inject/src/main/java/org/opendaylight/infrautils/inject/SingletonWithLifecycle.java [deleted file]

index 7ac3d98d39aef38b49e82ca208896e93a36a08a4..1532cf1380f22503956bcbc1e5a9b07540442fc9 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.infrautils.inject;
 
 import java.util.concurrent.atomic.AtomicReference;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,6 +38,7 @@ public abstract class AbstractLifecycle implements Lifecycle {
      * Please implement {@link #start()} instead of overriding this (here intentionally final) method.
      */
     @Override
+    @PostConstruct // NOTE: @PostConstruct is *NOT* inherited from interface, so must be here
     @SuppressWarnings("checkstyle:IllegalCatch")
     public final void init() throws ModuleSetupRuntimeException {
         if (state.compareAndSet(State.STOPPED, State.STARTED)) {
@@ -53,6 +56,7 @@ public abstract class AbstractLifecycle implements Lifecycle {
      * Please implement {@link #stop()} instead of overriding this (here intentionally final) method.
      */
     @Override
+    @PreDestroy // NOTE: @PostConstruct is *NOT* inherited from interface, so must be here
     @SuppressWarnings("checkstyle:IllegalCatch")
     public final void destroy() throws ModuleSetupRuntimeException {
         if (state.compareAndSet(State.STARTED, State.STOPPED)) {
index b35f505d363da0a90aeee8a6f8b215c050d9ba7b..f28e08d8528789edcaf07f20060b460d3d3879fa 100644 (file)
@@ -7,25 +7,19 @@
  */
 package org.opendaylight.infrautils.inject;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-
 /**
  * Something which can be {@link #init()}-ialized and {@link #destroy()}-d.
  *
  * <p>Annotated so that Dependency Injection Frameworks (whichever) automatically call these methods during wiring.
  *
  * @see AbstractLifecycle
- * @see SingletonWithLifecycle
  *
  * @author Michael Vorburger
  */
 public interface Lifecycle {
 
-    @PostConstruct
     void init() throws ModuleSetupRuntimeException;
 
-    @PreDestroy
     void destroy() throws ModuleSetupRuntimeException;
 
     boolean isRunning();
diff --git a/inject/src/main/java/org/opendaylight/infrautils/inject/SingletonWithLifecycle.java b/inject/src/main/java/org/opendaylight/infrautils/inject/SingletonWithLifecycle.java
deleted file mode 100644 (file)
index e685578..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2016 Red Hat, 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.infrautils.inject;
-
-import javax.inject.Scope;
-import javax.inject.Singleton;
-
-/**
- * A Singleton AbstractLifecycle.
- *
- * <p>In ODL, most wired objects ("beans") are {@link Singleton}, and it therefore
- * makes sense to have this class and let both exposed Services and wired
- * objects internal to bundles extend this.
- *
- * <p>Future use of DI in ODL may introduce additional non-{@link Singleton} {@link Scope}s.
- *
- * @author Michael Vorburger
- */
-@Singleton
-public abstract class SingletonWithLifecycle extends AbstractLifecycle {
-}