[cdi-dev] [JBoss JIRA] (CDI-271) Provide a way to inject Event metadata into an observer method

Lincoln Baxter III (JIRA) jira-events at lists.jboss.org
Wed Mar 6 10:55:56 EST 2013


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

Lincoln Baxter III commented on CDI-271:
----------------------------------------

Hey folks, I'd like to re-open this issue.

Sorry for joining this late, but I think that omitting BeanManager support here is going to be problematic. It creates a situation where you have partially functional observer methods, and I already have a use-case where this will cause broken code (in Forge 2.) There must be some way to get the set of Qualifiers here.

Beyond Forge, this would break for any person attempting to implement something as simple as a Logging framework that selects based on event qualifiers, where their developers fire a logging event and forget to fire using Event<?>, but choose the BeanManager instead - now you have events not being logged if they omit a necessary qualifier, like, "@Logged".

I would argue that InjectionPoint doesn't really mean anything for an Event anyway, and is misleading. It's not the Event payload that was injected, it was the Event<?> mechanism.

My recommendation would be to add another Interface like, "EventMetadata" that can be injected in place of InjectionPoint in your examples above:

{code}
   public void handleEvent(@Observes @Any Object event, EventMetadata ip)
   {
   }
{code}

This makes far more sense to me, as it does not attempt to re-use an API that is not intended for this purpose (which is already showing signs of API abuse given the semi-broken / inconsistent functionality that is going to result from this choice.)

I don't think this is a complex change.

Additionally, it will not break code that may be doing operations on InjectionPoint instances by introducing additional InjectionPoints into the system (not sure of details of this, but it would be a concern I have with backwards compatability with CDI 1.0)
                
> Provide a way to inject Event metadata into an observer method
> --------------------------------------------------------------
>
>                 Key: CDI-271
>                 URL: https://issues.jboss.org/browse/CDI-271
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Events
>            Reporter: Arne Limburg
>            Assignee: Arne Limburg
>             Fix For: 1.1.PFD
>
>
> Currently there is no way for observer methods to access the qualifiers of the fired event (i.e. to access @Nonbinding members).
> Consider the following example:
> {code}
> @Inject @MyQualifier
> Event<MyObject> event;
> public void fireEvent(MyObject object, MyTypeValue type) {
>     event.select(new MyTypeAnnotationLiteral(type)).fire(object);
> }
> {code}
> Currently no observer can receive the value of MyTypeValue. I suggest to introduce an interface AnnotatedEvent that extends Annotated and contains this information. It then could be injected via the InjectionPoint like this:
> {code}
> public void observeEvent(@Observes @MyType MyObject object, InjectionPoint ip) {
>     MyType annotation = ip.getAnnotated().getAnnotation(MyType.class);
>     MyTypeValue value = annotation.value();
>     ...
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the cdi-dev mailing list