-
Notifications
You must be signed in to change notification settings - Fork 78
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
add a portable event corresponding to application startup #496
Comments
I think that it would also make a lot of sense to specify some SPI (could be even CDI-based) to integrate with other technologies so that it's possible to fire this event when the app is ready, e.g. when the app is ready to accept http requests. |
Just a remark - we can do this two ways. It can either be an event of type As for name, I actually like
And as a side note - I wouldn't use
Not sure what you meant here. If it is just a plain CDI event, then you can fire it from just about anywhere and anytime you know all your libraries/fkws are ready (as an integrator). But maybe I am missing something? |
My point is that you might need some portable SPI to allow extension authors to participate in the "startup sequence", otherwise they would have to implement some runtime-specific API, e.g. |
Correct. I wouldn't mind [too much] doing a qualifier with
I think I'd prefer if it was defined in terms of application status, not CDI container status (see what happened with
That is a good point. If we called the event I'd be fine with that. |
Since this event is after startup and before shutdown, I think @afterstartup and @BeforeShutdown make sense. By the way, these events are only fired at runtime, right? I think the payload should contain the app name or CDI container name. |
That's the point of this issue - to have an event that really only happens when the app is actually running.
CDI container might work but I am not sure it has any value. |
I think it would be nice to find out which CDI container is up especially in Jakarta EE environment (if there is starting up order issue etc) |
We already have Also, even though I originally wanted to call it |
CDI doesn't provide an event that would correspond to application startup. A commonly used substitute is the
@Initialized(ApplicationScoped.class) Object
event, but that is fired "when the application context is initialized" (quoting from the spec).Traditionally, those two situations occur reasonably close in time, but with CDI Lite, we aim to expand the set of possible CDI implementation strategies to include those that initialize a lot of stuff (including the application context) ahead of time. In such case, the
@Initialized(ApplicationScoped.class) Object
event has no correlation to application startup. It may happen during application startup, or it may happen arbitrary number of hours before.Hence, I believe CDI should provide an event type that specifically corresponds to application startup. In some ways, it would be nice to restrict it to only be fired after the application fully starts up and everything is initialized, but that has prohibitive runtime costs; even the
@Initialized(ApplicationScoped.class) Object
event doesn't guarantee that (and firing the new event at the same time as this "old" event should be a valid implementation strategy for "purely runtime" CDI implementations such as Weld). So I propose to add an event type that is fired synchronously during application startup.As for the name, I originally thought it could be called
AfterStartup
, because that is symmetric to existingBeforeShutdown
, but that reasoning is invalid.BeforeShutdown
is a container lifecycle event that is designed for use with Portable Extensions (the spec directly says "observer methods of these events must belong to extensions"). Also, in previous paragraph, I specifically argue we shouldn't restrict the event to "after startup"; it should be "during startup". However,DuringStartup
looks ugly.There's also zero precedent (in CDI) for using naming conventions such as
On[Something]
or[Something]Event
, so I'd like to avoid those. The common event naming strategy in CDI is to just use a descriptive name.That would, in this case, be simply
Startup
. However, I'd like to reserve this name for a potential@Startup
annotation which would, similarly to EJB's@Startup
, force eager initialization of a bean.Any suggestions? :-)
For symmetry, we may want to declare a corresponding "during shutdown" event. We already have the
@BeforeDestroyed(ApplicationScoped.class) Object
and@Destroyed(ApplicationScoped.class) Object
events, and it's hard to imagine how these event types could be non-portable, so this is certainly not required. As I said, my main reason for adding such event type would be symmetry with the "during startup" event. Maybe also better discoverability (the application context events are, in my experience, not exactly obvious).The text was updated successfully, but these errors were encountered: