[ 
https://issues.apache.org/jira/browse/AVRO-539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044060#comment-13044060
 ] 

Scott Carey edited comment on AVRO-539 at 6/3/11 9:17 PM:
----------------------------------------------------------

One other option, don't return a future.  Instead a user can make one.  This is 
more verbose however:

{code}
 public void add(int arg1, int arg2, Callback<Integer> cb) throws IOException; 
{code}

Use a future:

{code}
  Future<Integer> f = new ProtocolFuture<Integer>();
  add(1, 2, f);
  Integer result = f.get();
{code}

ProtocolFuture<T> is relatively simple, with pseudo-code like:

{code}
public class ProtocolFuture<T> implements Future<T>, Callback<T> {
  private T result = null;
  private CountDownLatch latch = new CountDownLatch(1);

  @Override
  public final void handleResult(T result) {
    this.result = result;
    latch.countDown();
  }

  @Override
  public void T get() throws InterruptedException {
    latch.await();
    return result;
  }
}
{code}

Although the above class isn't so useful for Jetty, it could potentially be for 
other protocol implementations.

For very high throughput, creating an unused Future with each call might be a 
small problem too.

I'm not convinced I like this solution better, it is an interesting alternative 
though.


      was (Author: scott_carey):
    One other option, don't return a future.  Instead a user can make one.  
This is more verbose however:

{code}
 public void add(int arg1, int arg2, Callback<Integer> cb) throws IOException; 
{code}

Use a future:

{code}
 Future<Integer> f = new ProtocolFuture<Integer>();
 add(1, 2, f);
 Integer result = f.get();
{code}

ProtocolFuture<T> is relatively simple, with pseudo-code like:

{code}
public class ProtocolFuture<T> implements Future<T>, Callback<T> {
  private T result = null;
  private CountDownLatch latch = new CountDownLatch(1);

  @Override
  public void handleResult(T result) {
    this.result = result;
    latch.countDown();
  }

  @Override
  public void T get() throws InterruptedException {
    latch.await();
    return result;
  }
}
{code}

Although the above class isn't so useful for Jetty, it could potentially be for 
other protocol implementations.

For very high throughput, creating an unused Future with each call might be a 
small problem too.

I'm not convinced I like this solution better, it is an interesting alternative 
though.

  
> 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

Reply via email to