[cdi-dev] [JBoss JIRA] Issue Comment Edited: (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:36:22 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 edited comment on CDI-4 at 5/10/11 1:34 PM:
---------------------------------------------------------------
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:
{code}@EventBinding
public annotation Controlled { ... values ...}{code}
{code}@Controlled(Type.DELTA)
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.)
{code}public class Bean {
@Inject BeanManager manager;
public void fireEvent()
{
manager.fire(new EventInstance());
}
}{code}
The controller is then passed control of the event firing:
{code}
@EventBinding
@Controlled
public class CustomController implements EventController
{
@Override
public void performEvent(EventInstance<?> event, Controlled 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 )
{
if(Type.DELTA.equals(anno.type()))
o.fire(event.getEvent())
else
o.fire(new EventInstance("foo"));
}
}
}
{code}
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.
was (Author: lincolnthree):
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:
{code}@EventBinding
public annotation Controlled { ... values ...}{code}
{code}@Controlled(Type.DELTA)
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.)
{code}
@EventBinding
@Controlled
public class CustomController implements EventController
{
@Override
public void performEvent(EventInstance<?> event, Controlled 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 )
{
if(Type.DELTA.equals(anno.type()))
o.fire(event.getEvent())
else
o.fire(new EventInstance("foo"));
}
}
}
{code}
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