Hi William, The documentation around the async interface is definitely lacking. There should probably be a separate page on the Avro site for that. I'll try to find some time to work on it. In the meantime you can see some examples I put up on github:https://github.com/jbaldassari/Avro-RPC
As for the problem you're having, there are no major issues with your code. The only thing wrong is that the server side (ChatImpl) should implement Chat, not Chat.Callback. One of the nice things about the async interface is that it only affects the client side of the RPC; the server doesn't have to have any knowledge that it's async. So the server implements the regular sync interface (Chat), and then the client is free to use either the sync or async version when invoking RPCs. Does that answer your question? -James On Tue, Jan 31, 2012 at 8:50 PM, William Afendy <[email protected]> wrote: > Hi, > > I'm trying to implement Asynchronous calls by using NettyServer > implementation. After digging the source code, I found an example on how to > use NettyServer from TestNettyServerWithCallbacks.java > > When running a few test, I realize that NettyServer never calls > hello(Callback) method, instead it keeps calling the synchronous hello() > method. The client program prints out "Hello" but I'm expecting > "Hello-ASYNC" as a result. I really have no clue what's going on. > > I hope someone can shine some light on me and perhaps point out the > mistake or correct my logic. Below are the codes I use to perform a simple > asynchronous test. > > ======================= > AvroClient.java - Client code. > ======================= > > public class AvroClient { > public static void main(String[] args) throws InterruptedException, > ExecutionException, TimeoutException { > try { > NettyTransceiver transceiver = new NettyTransceiver(new > InetSocketAddress(6666)); > Chat.Callback client = > SpecificRequestor.getClient(Chat.Callback.class, transceiver); > > final CallFuture<CharSequence> future1 = new > CallFuture<CharSequence>(); > client.hello(future1); > > System.out.println(future1.get()); > > transceiver.close(); > > } catch (IOException ex) { > System.err.println(ex); > } > } > } > > =========================== > AvroNetty.java - The Server Code > =========================== > > public class AvroNetty { > public static void main(String[] args) { > Index indexImpl = new AsyncIndexImpl(); > Chat chatImpl = new ChatImpl(); > > Server server = new NettyServer(new SpecificResponder(Chat.class, > chatImpl), new InetSocketAddress(6666)); > server.start(); > System.out.println("Server is listening at port " + server.getPort()); > } > } > > =========== > ChatImpl.java > =========== > > public class ChatImpl implements Chat.Callback { > @Override > public void hello(org.apache.avro.ipc.Callback<CharSequence> callback) > throws IOException { > callback.handleResult("Hello-ASYNC"); > } > > @Override > public CharSequence hello() throws AvroRemoteException { > return new Utf8("Hello"); > } > } > > ============================================= > Chat.java - This interface is auto-generated by avro-tool > ============================================= > > @SuppressWarnings("all") > public interface Chat { > public static final org.apache.avro.Protocol PROTOCOL = > org.apache.avro.Protocol.parse("{\"protocol\":\"Chat\",\"namespace\":\"avro.test\",\"types\":[],\"messages\":{\"hello\":{\"request\":[],\"response\":\"string\"}}}"); > java.lang.CharSequence hello() throws org.apache.avro.AvroRemoteException; > > @SuppressWarnings("all") > public interface Callback extends Chat { > public static final org.apache.avro.Protocol PROTOCOL = > avro.test.Chat.PROTOCOL; > void hello(org.apache.avro.ipc.Callback<java.lang.CharSequence> > callback) throws java.io.IOException; > } > } > > ==================== > Here is the Avro Schema > ==================== > > { > "namespace": "avro.test", > "protocol": "Chat", > > "types" : [], > > "messages": { > "hello": { > "request": [], > "response": "string" > } > } > } > > > Thanks, > > -- > William Afendy >
