Skip to content

Commit

Permalink
Document Lifecycle support
Browse files Browse the repository at this point in the history
This closes #73
  • Loading branch information
kwin committed Sep 23, 2024
1 parent ebd1009 commit 3766bfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions org.eclipse.sisu.inject/src/site/markdown/lifecycle.md
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions org.eclipse.sisu.inject/src/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<menu name="Overview">
<item name="Introduction" href="index.html"/>
<item name="Named Index" href="named-index.html"/>
<item name="Lifecycle Support" href="lifecycle.html"/>
</menu>
</body>
</site>
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3766bfa

Please sign in to comment.