[
https://issues.apache.org/jira/browse/AVRO-539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043948#comment-13043948
]
James Baldassari commented on AVRO-539:
---------------------------------------
I agree that exposing both a future and callback API is preferable because it
gives users a lot of flexibility in how they implement their clients. I don't
think there is a one-size-fits-all solution for asynchronous messaging.
Doug, to answer a couple of your questions:
* Yes, we can absolutely use Future<T> rather than CallFuture<T> in the
generated interfaces as CallFuture implements Future, and the extra methods in
CallFuture probably aren't useful to most clients anyway.
* I prefer callbacks to futures in general because in a truly asynchronous
programming style the callback pattern is easier to implement. With a Future
you either have to wait on it immediately (which isn't asynchronous from the
client's perspective) or you have to stick it in some collection and have other
threads iterating over that collection processing and cleaning up completed
Futures. Back to my original point, Futures are more convenient in some cases,
which is why I think it's good to have both.
One other thing users will have to be aware of when using the callback API is
that their callback handlers should never perform long-running tasks because
that will block the event handler thread in the Netty thread pool, potentially
preventing future messages from being processed. They should either perform
very quick tasks or pass off the callback result to a queue/thread pool for
processing. We should explain some of these nuances on the wiki or in some
quickstart guide.
So unless anyone has any objections, I'm going to proceed with a new version of
the patch that generates client-facing interfaces like this:
{code:title=CalculatorClient.java|borderStyle=solid}
public interface CalculatorClient extends Calculator {
public static final Protocol PROTOCOL = Calculator.PROTOCOL;
Future<Integer> add(int arg1, int arg2, Callback<Integer> callback) throws
IOException;
}
{code}
If the user wants to use only the Future and not the Callback, the user can
pass in a null for the Callback parameter.
> Allow asynchronous clients to specify a callback to be run when server
> processing completes
> -------------------------------------------------------------------------------------------
>
> Key: AVRO-539
> URL: https://issues.apache.org/jira/browse/AVRO-539
> Project: Avro
> Issue Type: New Feature
> Reporter: Jeff Hammerbacher
> Attachments: AVRO-539.patch
>
>
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira