Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-124

Clarify how the ObserverMethod interface should be used

    XMLWordPrintable

Details

    • Clarification
    • Resolution: Done
    • Major
    • 1.1.PRD
    • 1.0
    • Events
    • None
    • Documentation (Ref Guide, User Guide, etc.)

    Description

      The CDI specification (10.5) says:

      "For a custom implementation of the ObserverMethod interface defined in Section 11.1.3, "The ObserverMethod interface",
      the container must call getReception() and getTransactionPhase() to determine if the observer method is a conditional
      or transactional observer method, and notify() to invoke the method."

      However, calling ObserverMethod.getReception() is useless.

      An ObserverMethod implementation can be registered by an portable extension via the AfterBeanDiscovery event. The observer method may or may not be hosted by a CDI bean:
      a) A portable extension adds a different way of declaring an observer method on a CDI bean (e.g. using a different annotation like @Listens, or allowing a different method signature)
      b) A portable extension allows CDI observer methods to be registered on non-CDI beans (e.g. on a Spring Bean)

      In both cases, the container is not able find out if an instance of the hosting component has been created already - it does not know the hosting bean in (a) and it obviously does not know anything about the Spring bean (b).

      Therefore, if the observer method is conditional (ObserverMethod.getReception() returns IF_EXISTS), the container cannot decide whether it should invoke the observer method since it has no way of finding out whether the underlying instance exists or not.

      As a result, the container has to invoke ObserverMethod.notify() anyway. That's why I consider ObserverMethod.getReception() useless.

      To fix the problem, I think that the responsibility of deciding whether to invoke a conditional observer method should be shifted from container to the ObserverMethod implementation.

      Attachments

        Activity

          People

            pmuiratbleepbleep Pete Muir (Inactive)
            rhn-engineering-jharting Jozef Hartinger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: