Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-62

Allow Event Listeners to have priorities

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Solved By
    • Major
    • 15.4-rc-1
    • 3.3-milestone-2
    • Observation
    • None

    Description

      Proposal sent to the devs list:

      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
      • 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?

      Thanks
      -Vincent

      See http://markmail.org/message/5542b4sdxrbsly5o

      Attachments

        Issue Links

          Activity

            People

              tmortagne Thomas Mortagne
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: