[cdi-dev] [JBoss JIRA] (CDI-601) Add container lifecycle event fired before container destroys all contexts
Martin Kouba (JIRA)
issues at jboss.org
Thu Jul 28 07:24:01 EDT 2016
[ https://issues.jboss.org/browse/CDI-601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13271990#comment-13271990 ]
Martin Kouba commented on CDI-601:
----------------------------------
Yes, sounds better. Maybe even {{ApplicationStopped}}?
bq. My original notion was for @ApplicationScoped beans not to be destroyed while other beans still hold contextual references to them...
This might be pretty complext, if even possible for non-inject cases ({{BeanManager.getReference()}}, {{Instance.get()}}) and unmanaged contextual instances.
What I had in mind when creating this ticket was that it might be useful to introduce some generic event fired *when an application is stopped before all contexts are destroyed* and which would allow a bean to perform cleanup using the dependencies, i.e. fired before {{@PreDestroy}} and {{@Destroyed(X.class)}}. [~chrisjr] WRT your use case - your "@Dependent worker bean" would just observe {{ApplicationStopped}} and do all the cleanup ({{@ApplicationScoped}} beans would not be destroyed yet).
{code:java}
@Dependent
class Worker {
@Inject
Service service;
void shutdown(@Observes ApplicationStopped event) {
// At this point Service is not destroyed yet, nor is its @PreDestroy called
service.doSomeStuff();
}
}
@ApplicationScoped
class Service {
@PreDestroy
void destroy() {
// Perform local cleanup
}
void doSomeStuff() {
}
}
{code}
> Add container lifecycle event fired before container destroys all contexts
> --------------------------------------------------------------------------
>
> Key: CDI-601
> URL: https://issues.jboss.org/browse/CDI-601
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Martin Kouba
> Fix For: 2.0 (discussion)
>
>
> The name might be something like {{BeforeContainerShutdown}}. Note that we probably cannot change the name or semantics of {{BeforeShutdown}}, which is fired after container destroys all contexts. The motivation is to allow the beans to perform some kind of cleanup before dependencies could be disposed (the ordering of destruction is not defined).
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the cdi-dev
mailing list