Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Lifecycle support #175

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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