On Thu, Nov 24, 2011 at 1:58 PM, Vincent Massol <vincent(a)massol.net> wrote:
Hi devs,
Summary:
========
I'd like to add the notion of Priority to Event Listeners. The reason is that in some
cases it's important that some listeners execute before others.
The problem at hand:
=================
Here's a typical use case: When receiving the ApplicationStartedEvent, we have lot of
code that needs to initialize. Initialization order is important (you can compare it to
run levels in OS): for example some init must happen after the Database initialization has
happened.
Note that another solution exists for this use case: some initializations could introduce
their own events (such as a DatabaseStartedEvent) and other init could listen on those
events instead of the generic ApplicationStartedEvent. However I can see several drawbacks
to this:
* it's less generic than the priority solution
* it means creating more events
* but more importantly it means that modules will have strong dependencies (at maven
level) on each other whereas it's not necessary and shouldn't be the case. In our
example use case: it means that inits that must happen after database is started will need
to depend on oldcore (which is where DB is started ATM)
Proposal:
========
* Don't break backward compat in Observation module
* Introduce a PrioritizedEventListener interface that adds a getPriority() method
* Modify ObservationManager implementation to take into account priorities
* In order to make it simple I propose to have only a single priority per Listener and
not a priority per event supported by a given listener
General Context
=============
To give some context here's what I'd like to do on the medium term:
* Step 1: Introduce notion of priority in EventListeners
* Step 2: Refactor XWiki init to use an EventListener on AppStarted with low priority
* Step 3: Refactor wiki macros to use an EventListener on AppStarted with priority value
lower than at step2
Will also allows to finally finish wiki components which was stuck
without any way to be called when the database is ready for it to
initialize.
* Step 4: Write an EventListener for the new UI
Extensions with a priority value higher than the one of step2 <-- this is the initial
goal that led me to make this proposal ;)
WDYT?
+1
Thanks
-Vincent
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Thomas Mortagne