From 2a70056865e7a7ddc1715dac6d9a3e6330d8078d Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 23 Sep 2024 11:17:07 +0200 Subject: [PATCH] Document Lifecycle support This closes #73 --- .../src/site/markdown/lifecycle.md | 14 ++++++++++++++ org.eclipse.sisu.inject/src/site/site.xml | 1 + .../src/site/markdown/conversion-to-jsr330.md | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.sisu.inject/src/site/markdown/lifecycle.md diff --git a/org.eclipse.sisu.inject/src/site/markdown/lifecycle.md b/org.eclipse.sisu.inject/src/site/markdown/lifecycle.md new file mode 100644 index 00000000..76f6c8ad --- /dev/null +++ b/org.eclipse.sisu.inject/src/site/markdown/lifecycle.md @@ -0,0 +1,14 @@ +# Lifecycle Support + +Each Sisu managed bean/component may optionally use annotations on methods to be called whenever the bean is started or stopped. + +Those are + +Annotation | Method called... | Leveraged Guice Hook +--- | --- + `org.eclipse.sisu.PostConstruct` (or `javax.annotation.PostConstruct`) | Before bean is started | [`com.google.inject.spi.InjectionListener.afterInjection(...)`](https://google.github.io/guice/api-docs/6.0.0/javadoc/com/google/inject/spi/InjectionListener.html#afterInjection(I)) + `org.eclipse.sisu.PreDestroy` (or `javax.annotation.PreDestroy.`) | Before bean is stopped | Is not called by default, only via [Plexus API](../org.eclipse.sisu.plexus). + + The annotations defined in [JSR 250](https://jcp.org/en/jsr/detail?id=250) are recognized in addition to the native Sisu ones when their classes are detected in the class path. + + The support needs to be explicitly enabled by passing an instance of [`org.eclipse.sisu.bean.LifecycleModule`](apidocs/org/eclipse/sisu/bean/LifecycleModule.html) when creating the `Injector`. \ No newline at end of file diff --git a/org.eclipse.sisu.inject/src/site/site.xml b/org.eclipse.sisu.inject/src/site/site.xml index 3c1ac832..856ca555 100644 --- a/org.eclipse.sisu.inject/src/site/site.xml +++ b/org.eclipse.sisu.inject/src/site/site.xml @@ -14,6 +14,7 @@ + diff --git a/org.eclipse.sisu.plexus/src/site/markdown/conversion-to-jsr330.md b/org.eclipse.sisu.plexus/src/site/markdown/conversion-to-jsr330.md index 3c1ddd7d..bd714f15 100644 --- a/org.eclipse.sisu.plexus/src/site/markdown/conversion-to-jsr330.md +++ b/org.eclipse.sisu.plexus/src/site/markdown/conversion-to-jsr330.md @@ -458,7 +458,9 @@ public class MyComponent ### Startable -Support for JSR250 lifecycle annotations is available when enabled for the Plexus wrapper (\[Maven 3.5+\](https://issues.apache.org/jira/browse/MNG-6084) enables JSR250 support). If JSR250 support is not enabled then applications can use other techniques to handle start/stop behavior. The examples below show the solution used in Sonatype Nexus, which relies on a modified implementation of the Google-Guava EventBus to manage lifecycle events. +Support for [Sisu/JSR250 lifecycle annotations](../org.eclipse.sisu.inject/lifecycle.html) is available when enabled for the Plexus wrapper (\[Maven 3.5+\](https://issues.apache.org/jira/browse/MNG-6084) enables JSR250 support). + +If JSR250 support is not enabled then applications can use other techniques to handle start/stop behavior. The examples below show the solution used in Sonatype Nexus, which relies on a modified implementation of the Google-Guava EventBus to manage lifecycle events. ``` @Component(role=Component.class, hint="my")