[cdi-dev] CDI-75 clarifications - was: Scoped CDI Events?
Jens Schumann
jens.schumann at openknowledge.de
Thu Aug 30 05:20:01 EDT 2012
Am 29.08.12 13:10 schrieb "Martin Kouba" unter <mkouba at redhat.com>:
>This reminds me that the spec should clarify the case when the context of
>the bean declaring the observer is not active. Currently in RI (Weld) you
>get ContextNotActiveException. Which is logical although probably not the
>best from the user point of view.
>
>I will file an issue. Thanks for the tip! :-)
Maybe it should be handled in https://issues.jboss.org/browse/CDI-75 too.
Why?
Initially I thought it would be a good idea to ignore an observer method
if a scope is not active and notifyObserver is IF_EXISTS. But now I
believe this is partially wrong. Too me there is a difference between
A) the observer bean scope is active without an active bean in scope and
B) the observer bean scope is not active
IF_EXISTS refers to A) only, I believe. Because if IF_EXISTS applies to A)
and B) I am unable to support ALWAYS for active scopes while being ignored
if a scope is not active.
Why would someone need that? Very often we initialize our application
during startup. During startup request and application scope are active
[1]. Usually a session scoped observer should be ignored during startup.
But at runtime - with an active session scope - I need ALWAYS semantics
for those observers.
So I would vote for:
- ALWAYS observer methods will throw an ContextNotActiveException(?) if
scope is not active.
- IF_EXISTS observer methods will throw an ContextNotActiveException(?) if
scope is not active.
- IF_EXISTS observer methods will be ignored if scope is active but no
active bean is in scope.
- (The newly created) IF_ACTIVE observer method (naming TBD) will be
ignored if scope is inactive. If scope is active it will be treated as
ALWAYS.
- There might be a need for IF_ACTIVE_AND_EXISTS;).
This might break backwards compatibility though.
Jens
[1] We do that manually but would love to see @Startup/@PostConstruct
support with active application and request scopes.
More information about the cdi-dev
mailing list