Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Avro >> mail # user >> Async Callbacks using Netty


Copy link to this message
-
Re: Async Callbacks using Netty
Well that's really strange.  I'm not sure why you would be seeing a
different result there.  Just to be sure we're both running the exact same
code, I'm going to send you a maven project off list that I've been using
to run my tests.  See if the tests will pass for you.  If so, then you can
compare the code and find out where the difference is.

-James
On Wed, Feb 1, 2012 at 2:22 AM, William Afendy <[EMAIL PROTECTED]> wrote:

> Hi James,
>
> Thank you for taking the time explaining async in great details. Your
> example is exactly the direction I want to go, but I'm getting a
> different result. Is it be possible that there's some jar files
> missing?
>
> Here is what I got after I applied your mod:
>
> // Test async call:
>
> 3. Wed Feb 01 14:58:45 SGT 2012: Saying Hello (async)...
> 4. Wed Feb 01 14:58:50 SGT 2012: Chat.hello(Callback<CharSequence>)
> returned
> 5. Wed Feb 01 14:58:50 SGT 2012: Callback<CharSequence>.get() returned
> "Hello-17"
>
> // The Client code
>
> NettyTransceiver transceiver = new NettyTransceiver(new
> InetSocketAddress(6666));
> Chat.Callback client > SpecificRequestor.getClient(Chat.Callback.class, transceiver);
>
> final CallFuture<CharSequence> future1 = new CallFuture<CharSequence>();
> System.out.println("\n3. " + new Date() + ": Saying Hello (async)...");
> client.hello(future1); // This should not block.
> System.out.println("4. " + new Date() + ":
> Chat.hello(Callback<CharSequence>) returned");
> CharSequence asyncResult = future1.get(); // This should block for 5
> seconds
> System.out.println("5. " + new Date() + ":
> Callback<CharSequence>.get() returned \"" + asyncResult + "\"");
> transceiver.close();
>
> // Jar Libraries
>
> avro-1.6.1.jar
> avro-ipc-1.6.1.jar
> netty-3.3.0.Final.jar
> slf4j-log4j12-1.6.1.jar
> slf4j-api-1.6.1.jar
> log4j-1.2.15.jar
> jackson-core-asl-1.4.2.jar
> jackson-mapper-asl-1.4.2.jar
>
>
>
> On Wed, Feb 1, 2012 at 2:24 PM, James Baldassari <[EMAIL PROTECTED]>
> wrote:
> > Hi William,
> >
> > Great test.  I ran your code, and it worked as expected for me, but I
> made
> > some slight changes to the client side to demonstrate what's happening:
> >
> >     // Test sync call:
> >     System.out.println("1. " + new Date() + ": Saying Hello (sync)...");
> >     CharSequence syncResult = client.hello(); // This should block for 5
> > seconds
> >     System.out.println("2. " new Date() + ": Chat.hello() returned \"" +
> > syncResult + "\"");
> >
> >     // Test async call:
> >
> >     final CallFuture<CharSequence> future1 = new
> CallFuture<CharSequence>();
> >     System.out.println("\n3. " + new Date() + ": Saying Hello
> (async)...");
> >     client.hello(future1); // This should not block.
> >     System.out.println("4. " + new Date() + ":
> > Chat.hello(Callback<CharSequence>) returned");
> >     CharSequence asyncResult = future1.get(); // This should block for 5
> > seconds
> >     System.out.println("5. " + new Date() + ":
> Callback<CharSequence>.get()
> > returned \"" + asyncResult + "\"");
> >
> > When I ran that I got the following output:
> >
> >     1. Wed Feb 01 00:13:36 EST 2012: Saying Hello (sync)...
> >     2. Wed Feb 01 00:13:41 EST 2012: Chat.hello() returned "Hello"
> >
> >     3. Wed Feb 01 00:13:41 EST 2012: Saying Hello (async)...
> >     4. Wed Feb 01 00:13:41 EST 2012: Chat.hello(Callback<CharSequence>)
> > returned
> >     5. Wed Feb 01 00:13:46 EST 2012: Callback<CharSequence>.get()
> returned
> > "Hello"
> >
> > As you can see, the synchronous call (lines 1-2) blocked for about 5
> seconds
> > as expected.  When the asynchronous call was invoked it returned
> immediately
> > (note timestamps on lines 3-4).  The part that blocked was the
> > CallFuture.get() on line 5 of the output.  The result of the callback
> can't
> > be obtained until the server returns it (after waiting 5 seconds).
> >
> > I think I may know why this behavior seems confusing.  In practice I
> don't
> > think many people will use CallFuture.  It's basically an adapter to