[cdi-dev] Can an observer be both async and sync?

John Ament john.ament at spartasystems.com
Mon Mar 6 06:49:32 EST 2017


I'll put in a ticket to update the spec.  I agree that it was intended to be forbidden, but I couldn't find anything saying it was.


John



________________________________
From: Martin Kouba <mkouba at redhat.com>
Sent: Monday, March 6, 2017 4:15 AM
To: Tomas Remes; John Ament
Cc: cdi-dev
Subject: Re: [cdi-dev] Can an observer be both async and sync?

Well, it's not 100% clear but I believe it should be forbidden. The spec
only states:

"An observer method may be declared by annotating a parameter
@javax.enterprise.event.Observes OR
@javax.enterprise.event.ObservesAsync of a default-access, public,
protected or private method. That parameter is the event parameter."

I think it wouldn't hurt to add:

"If an event parameter is annotated with both @Observes and
@ObservesAsync, the container automatically detects the problem and
treats it as a definition error."

Weld throws a DefinitionException.

Martin

Dne 6.3.2017 v 07:55 Tomas Remes napsal(a):
>
> Hi John,
>
> No it shouldn't. The problematic and confusing case would be when there is some other param (injection point) in this observer method and this param resolves to let's say @SessionScoped bean. How does it work then? Once it fails (since there's no context propagation for async event), once it works (sync event)? Therefore this was forbidden.
>
> Tom
>
> ----- Original Message -----
> From: "John Ament" <john.ament at spartasystems.com>
> To: "cdi-dev" <cdi-dev at lists.jboss.org>
> Sent: Monday, March 6, 2017 1:42:09 AM
> Subject: [cdi-dev] Can an observer be both async and sync?
>
>
>
> Section 10.4.4 has the following section which got me thinking
>
>
>
>
>
> public void refreshOnDocumentUpdate(@Observes(notifyObserver=IF_EXISTS) @Updated Document doc) { ... }
>
> public void asyncRefreshOnDocumentUpdate(@ObservesAsync(notifyObserver=IF_EXISTS) @Updated Document doc) { ... }
>
>
>
>
>
> I'm wondering, is it OK to have an observer method defined like this?
>
>
>
>
>
> public void asyncRefreshOnDocumentUpdate( @Observes(notifyObserver=IF_EXISTS) @ObservesAsync(notifyObserver=IF_EXISTS) @Updated Document doc) { ... }
>
>
>
>
>
> I don't see anything against this in the spec, but I suspect most people are going to think this shouldn't work. So I'm asking the question - should it work?
>
>
>
>
> John
>
>
>
>
>
>
>
>
>
> NOTICE: This e-mail message and any attachments may contain confidential, proprietary, and/or privileged information which should be treated accordingly. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this message, and destroy all physical and electronic copies. Thank you.
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
>

--
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic
________________________________
NOTICE: This e-mail message and any attachments may contain confidential, proprietary, and/or privileged information which should be treated accordingly. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this message, and destroy all physical and electronic copies. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20170306/05dea314/attachment-0001.html 


More information about the cdi-dev mailing list