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>
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;
* 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)) {
* 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)) {
*/
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();
+++ /dev/null
-/*
- * 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 {
-}