[mod-shell/Java] How to update output/console when in an async handler?

28 views
Skip to first unread message

Nassos Michas

unread,
Jun 7, 2014, 5:01:47 PM6/7/14
to crash...@googlegroups.com
Hi there,

I was wondering if anyone has a good idea on that one:

I implemented a Java command which before it concludes sends a message to Vertx eventbus. How is it possible to update the output/user console with the results of this message since the results come back asynchronously? What I've tried to do is pass the invocation context in my command, get a ref to the RenderPrintWriter and then just println() and flush() inside my Handler<Message<JsonObject>> which kind of works as the output is indeed sent back to the user, however it "interrupts" the user's current shell prompt and the user needs to press Enter to get a new prompt back.


Thanks!

Julien Viet

unread,
Jun 7, 2014, 5:38:25 PM6/7/14
to crash...@googlegroups.com
Hi,

the vertx “bus send” message that accept a “reply” option that seem to implement the behaviour you describe: it waits until the response handler is called, unless the user press control-c to interrupt the command : https://github.com/crashub/mod-shell/blob/master/src/main/resources/crash/commands/vertx/bus.groovy

is it what you are looking for ?

Julien Viet
julienviet.com
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "CRaSH User Group".
> Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse crash-users...@googlegroups.com (mailto:crash-users...@googlegroups.com).
> Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.



Nassos Michas

unread,
Jun 10, 2014, 2:00:29 PM6/10/14
to crash...@googlegroups.com
Hi Julien,

First, thanks for the first class support ;)

I actually implemented a logic similar to the Groovy bus command link you sent, so inside my eventbus reply Handler I wait on a lock on an AtomicReference<Message> which does the trick nicely.


-n-
> Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse crash-users...@googlegroups.com (mailto:crash-users+unsub...@googlegroups.com).

Julien Viet

unread,
Jun 10, 2014, 2:05:28 PM6/10/14
to crash...@googlegroups.com
great!

keep in mind about how control-c will interrupt your thread when pressed!

http://www.crashub.org/1.3/reference.html#_command_interruption

Julien Viet
julienviet.com


On Tuesday 10 June 2014 at 20:00, Nassos Michas wrote:

> Hi Julien,
>
> First, thanks for the first class support ;)
>
> I actually implemented a logic similar to the Groovy bus command link you sent, so inside my eventbus reply Handler I wait on a lock on an AtomicReference<Message> which does the trick nicely.
>
>
> -n-
>
> On Sunday, June 8, 2014 12:38:25 AM UTC+3, Julien Viet wrote:
> > Hi,
> >
> > the vertx “bus send” message that accept a “reply” option that seem to implement the behaviour you describe: it waits until the response handler is called, unless the user press control-c to interrupt the command : https://github.com/crashub/mod-shell/blob/master/src/main/resources/crash/commands/vertx/bus.groovy
> >
> > is it what you are looking for ?
> >
> > Julien Viet
> > julienviet.com (http://julienviet.com)
> >
> >
> > On Saturday 7 June 2014 at 23:01, Nassos Michas wrote:
> >
> > > Hi there,
> > >
> > > I was wondering if anyone has a good idea on that one:
> > >
> > > I implemented a Java command which before it concludes sends a message to Vertx eventbus. How is it possible to update the output/user console with the results of this message since the results come back asynchronously? What I've tried to do is pass the invocation context in my command, get a ref to the RenderPrintWriter and then just println() and flush() inside my Handler<Message<JsonObject>> which kind of works as the output is indeed sent back to the user, however it "interrupts" the user's current shell prompt and the user needs to press Enter to get a new prompt back.
> > >
> > >
> > > Thanks!
> > >
> > > --
> > > Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "CRaSH User Group".
> > > Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse crash-users...@googlegroups.com (javascript:) (mailto:crash-users...@googlegroups.com (javascript:)).
> > > Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.
> >
>
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "CRaSH User Group".
> Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse crash-users...@googlegroups.com (mailto:crash-users...@googlegroups.com).
Reply all
Reply to author
Forward
0 new messages