The first of the new features are ordered observer methods. This requirement came up a long ago and several approaches were proposed in the meantime, as documented by CDI-4.The Alpha1 release employs the general-purpose @Priority annotation to determine the order in which observer methods are to be notified.

There are many open questions about this feature. Here are some of the rules we set for the purpose of this experimental implementation. These are by no means set in stone but instead we encourage you to give us feedback on these:

Each observer method has a certain priority value. An observer method that does not define a priority explicitly is given the default priority which is 2500 (in the middle of the Interceptor.Priority.APPLICATION range)

The priority of an observer method determines the order. An observer method with lower value is called before an observer method with higher value

If multiple observer methods define the same priority value, the order is undefined

Observer methods priorities should match existing priority range convention

The ordering applies to both transactional and non-transactional observer methods

The priority annotation is applied on the event parameter (not the observer method)

Here’s an example:

public void sendWelcome(@Observes @Priority(APPLICATION + 800) @Registered User user) { // ... }

Note that javax.annotation.Priority can currently only be applied to types. Therefore, we temporarily created a substitute called org.jboss.weld.experimental.Priority which is identical to the original except that it can also be applied on parameters (of observer methods). The plan is to propagate this change back to javax.annotation.Priority . In the meantime, Weld’s twin gets the job done.

In addition to the @Priority annotation, the SPI was also enhanced to expose the priority of an observer method. We are not touching javax.enterprise interfaces just yet. Instead, the org.jboss.weld.experimental package contains proposals for how the new SPI should look like. As the package name suggests, this SPI is good for a test-drive but do not expect it to be stable. To use the experimental SPIs, you’ll need to add a dependency on weld-api.

Here’s an example of reading the observer method priority using the SPI in an Extension. ExperimentalProcessObserverMethod and ExperimentalObserverMethod interfaces come from the org.jboss.weld.experimental package .

public class SimpleExtension implements Extension { void observe(@Observes ExperimentalProcessObserverMethod<User, ?> event) { ExperimentalObserverMethod<User> observerMethod = event.getObserverMethod(); this.priority = observerMethod.getPriority(); } }