[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Gordon Hutchison (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Gordon Hutchison commented on CDI-729:
--------------------------------------
This sort of approach could prove very useful in tryin to 'plug-together' a stream of CDI events from some other reactive stream.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-729:
----------------------------------------
I'm using events because I don't know the impl I will use (it is a library which is integrated with some 3rd party backend). The event is very handy on both side since it doesn't couple strongly both maintainers. The only blocking point is to have what CDI provides in synchronous mode: return when done. For completionstage it is providing a way to register another stage in the event chain.
I can't put the chaining in the caller (because I don't know it)
I can't throw an exception in the observer because the processing is done through a completionstage in another thread so it is missed and likely happen after the caller already returned anyway (timing issue). This is also why fire() (not async) doesn't work.
I'm not sure I got your solution but sounds like registering a task to delay the completion of the returned stage is not a big deal (clearly not in impl side) and would help to be reactive in apps.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Matej Novotny (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Matej Novotny commented on CDI-729:
-----------------------------------
Chaining can be done from the event-firing side, but the loose coupling is intentional. Observers often don't know about other observers as they may come from different bean archives.
What you are trying to do could be done, for instance, with interceptors which seem a good match for logging after certain action was performed.
But I suppose you are mainly trying events because they can be asynchronous. If that's the case, what Martin says is probably the go-to way and can be achieved 'natively'.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba commented on CDI-729:
----------------------------------
Well, observers are not designed to return anything. If you return some object it is just ignored. The reason is that observers were designed for decoupled communication. Ideally, observers should NOT depend on each other and emitters should NOT depend on observers either.
In your example, the observer which saves the entity could throw an exception if something goes wrong so that the {{CompletionStage}} returned from {{fire()}} would end up exceptionally. Of course, if you need to perform the save action asynchronously you'd probably have to fire another async event when it's done and declare another async observer for this particular event.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-729:
----------------------------------------
You do the same for all, note that the proposal still returns the compltionstage with the event and not with the transformed payload, it is all about chaining, not transforming which is not possible with a loosely coupled chain.
Issue I hit today in a modern app is that I can't use that mecanism natively because i return way before actual completion :(.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Matej Novotny (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Matej Novotny commented on CDI-729:
-----------------------------------
[~rmannibucau] and what if you have multiple observers?
How does the chain proceed there? Who goes first, who second? What if both observers expect to go first.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-729:
----------------------------------------
If the observer execute some reactive code returning a CompletionStage there is no way in current spec to chain the CompletionStage of the processing to the event firing to ensure it is executed before returning. This makes the whole API quite useless and requires to define another way to fire event and compose them.
{code}
public CompletionStage<Entity> save(Entity e);
{code}
{code}
fireAsync(new Persist(entity))
{code}
How do you compose both?
What you want is:
{code}
CompletionStage<?> onPersist(@ObserveAsync CompletionStage<Persist> persist) {
return persist.thenCompose(event -> repo.save(event.getEntity());
}
{code}
This way the fireAsync ensures the persistence is done:
{code}
event.fireAsync(new Persist(entity))
.thenApply(event -> log.info("{} persisted", event.getEntity()));
{code}
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba commented on CDI-729:
----------------------------------
Pls provide a more concrete example. I don't understand the description.
> Async event not CompletionStage friendly
> ----------------------------------------
>
> Key: CDI-729
> URL: https://issues.jboss.org/browse/CDI-729
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-729) Async event not CompletionStage friendly
by Romain Manni-Bucau (JIRA)
Romain Manni-Bucau created CDI-729:
--------------------------------------
Summary: Async event not CompletionStage friendly
Key: CDI-729
URL: https://issues.jboss.org/browse/CDI-729
Project: CDI Specification Issues
Issue Type: Feature Request
Reporter: Romain Manni-Bucau
The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
Here is a sample:
1. fireAsync(persistEvent)
2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months
[JBoss JIRA] (CDI-728) The CDI specification javadoc is setting lang=french in the headers
by Emmanuel Bernard (JIRA)
[ https://issues.jboss.org/browse/CDI-728?page=com.atlassian.jira.plugin.sy... ]
Emmanuel Bernard commented on CDI-728:
--------------------------------------
[~mkouba] you are raising a good point. If we truly want world domination, translating the spec is necessary. It will fix any inconsistencies anyway ahahahahah.
> The CDI specification javadoc is setting lang=french in the headers
> -------------------------------------------------------------------
>
> Key: CDI-728
> URL: https://issues.jboss.org/browse/CDI-728
> Project: CDI Specification Issues
> Issue Type: Clarification
> Components: Javadoc and API
> Affects Versions: 2.0 .Final
> Reporter: Sanne Grinovero
> Priority: Trivial
>
> The page http://docs.jboss.org/cdi/api/2.0/ is setting
> {noformat}
> <html lang="fr">
> {noformat}
> However the content seems to be in English.
> It's a bit annoying as each time I open it my browser kicks in with a popup to ask if I want it to translate for me.
> I guess there are too many native French speakers on the team to have noticed ;)
> Thanks
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)
6 years, 6 months