[jsr342-experts] Application ready event
- From: Pete Muir <pmuir@...>
- To: jsr342-experts@...
- Subject: [jsr342-experts] Application ready event
- Date: Wed, 28 Nov 2012 18:39:13 +0000
A long requested feature from the community has been for some sort of
"application ready" event, which is fired just before the application is put
into service, and starts handling external requests.
Some use cases:
* Loading/processing some data, for example data that's been collected whilst
the application was down
* Starting timers or async events
* Other application initialization tasks
This event should happen once all services (e.g. CDI, BV, JPA, EJB, JTA)
required by the application are ready.
There may be some optional services, e.g. those that are started on demand,
that are not required, and do not need to be ready for this event to be sent.
This event should happen before the application starts handling external
requests (e.g. web service requests, web requests, ejb remote invocations).
In general, it seems sane that an application cannot handle requests
successfully until all required services are available.
For the purposes of this proposal, we define external request as one
originating from outside the application deployment, and internal as one
originating from inside the application deployment.
In order to tackle this problem one step at a time, we propose we start by
just considering external requests as those coming in via the Servlet
container. This should make the problem more manageable!
Should the application wish to perform some sync task, and allow the
application to handle requests, whilst performing it, this also needs to be
Finally, the application needs to be able to say to the server that it is
ready to start servicing requests.
We would propose that we need to make these changes to the spec.
1) We send a CDI event when the required services are ready
2) By default this event *does not* block the server immediately moving to
servicing external requests
3) The observer of this event is able to act as though it were executing
during application runtime, and can make any internal call. If it makes an
external call to itself, that call will not succeed
4) We introduce the ability to suspend external requests, until the event
observers complete, or until the external requests are told to proceed. We
propose for now we focus on web requests and add a servlet context parameter
that enable the ability to suspend external requests, and add a
ServletContext.ready() method, that tells the request completes. In future
iterations we need to address other remote protocols. The observers can make
this call at any point, at which point the app starts processing external
requests, the observer may continue to execute beyond here.