[cdi-dev] [JBoss JIRA] Commented: (CDI-4) Need a way to provide ordering for Event observers (@Observes)

Lincoln Baxter III (JIRA) jira-events at lists.jboss.org
Tue May 10 13:15:19 EDT 2011

    [ https://issues.jboss.org/browse/CDI-4?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12601116#comment-12601116 ] 

Lincoln Baxter III commented on CDI-4:

If we add this API, I'd also like to see an SPI that can be used in tandem, so that Event firing may additionally be controlled using custom annotations and an Event firing controller.

For instance:
public annotation Custom { ... values ...}{code}

public class EventInstance {...}{code}

Where the annotation is bound to the controller just like we do for Interceptors and Decorators (which also need an ordering solution if I am not mistaken.)

public class CustomController implements EventController
   public void performEvent(EventInstance<?> event, Annotation anno, Set<ObserverInstance> observers) {
      // this method can sort through the list of observers and fire the event for each observer in order as it sees fit.
      for( ObserverInstance o : observers )
            o.fire(new EventInstance("foo"));

This would effectively enable custom ordering and fire-control, without additional coupling or implementation specific details. However, I don't believe that @Before and @After could be implemented using this SPI; this would be an additional feature that could take advantage of the @Before or @After hints if desired.

> Need a way to provide ordering for Event observers (@Observes)
> --------------------------------------------------------------
>                 Key: CDI-4
>                 URL: https://issues.jboss.org/browse/CDI-4
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Events, Portable Extensions
>    Affects Versions: 1.0
>         Environment: All
>            Reporter: Lincoln Baxter III
>            Assignee: Mike Brock
>             Fix For: TBD
> There needs to be a way to specify some kind of ordering for Event observers. 
> Understandably, this is somewhat counter-intuitive to the general concept of observing an event, but there is going to be need for this in an upcoming JBoss project. While it can be done manually, it might be nice to have a built-in API.

This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

More information about the cdi-dev mailing list