[Hawkular-dev] [metrics] Looking for advice on ListenableFuture usage

John Mazzitelli mazz at redhat.com
Fri Jan 16 16:37:04 EST 2015


I originally was using Future, and you told me I should use google's ListenableFuture instead :)

I don't think Jay is using it in his alerts stuff, so I can only point you to the unit tests that test it:

see testSendRPC and testSendRPCAndUseListenableFuture in:

https://github.com/hawkular/hawkular-bus/blob/master/hawkular-bus-test-common/src/test/java/org/hawkular/bus/common/test/RPCTest.java

They send a "SpecificMessage" and expect a response back (where the message that comes back in the response merely echoes back to the caller the message that was originally sent in that "SpecificMessage" prefixed with the string "RESPONSE:").

----- Original Message -----
> I am not questioning the usefulness of MessageProcessor.sendRPC. I am
> wondering why you need/want ListenableFuture. If you want want to obtain
> responses asynchronously, use a message listener. I see that there is
> already code like BasicMessageListener that abstracts a lot of stuff for
> example. Can you point me to an example where the ListenableFuture is used?
> Maybe that will help me understand.
> 
> 
> > On Jan 16, 2015, at 12:52 PM, John Mazzitelli <mazz at redhat.com> wrote:
> > 
> > I find trying to write the same functionality in straight JMS will show the
> > usefulness of MessageProcessor.sendRPC.
> > 
> > Again, this is to support RPC-like functionality - which isn't trival in
> > JMS (as opposed to fire-and-forget, 1-way messaging). You wouldn't use
> > this sendRPC if you are just shooting a message on the bus and not
> > expecting a direct response to that message.
> > 
> > ----- Original Message -----
> >> 
> >>> On Jan 16, 2015, at 12:20 PM, John Mazzitelli <mazz at redhat.com> wrote:
> >>> 
> >>>> I haven’t looked at the code too closely yet, but why the need for
> >>>> ListenableFuture to get the response from the bus? JMS/messaging is
> >>>> already
> >>>> asynchronous.
> >>> 
> >>> In the RPC-like use-case, I send a message on the bus, and I expect to
> >>> get
> >>> a response back from that message. This API helps hide the annoying JMS
> >>> boiler-plate code you'd have to write to do that RPC-like functionality.
> >> 
> >> But aren’t you just putting in place more boiler plate with
> >> ListenableFuture?
> >> The problem with Java futures is that obtaining the result is blocking.
> >> ListenableFuture allows you to get the results asynchronously. We already
> >> get the results asynchronously with JMS right? I understand the desire for
> >> abstracting the JMS code, but I don’t what ListenableFuture buys you.
> > 
> > _______________________________________________
> > hawkular-dev mailing list
> > hawkular-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/hawkular-dev
> 
>



More information about the hawkular-dev mailing list