org.eclipse.jgit.storage.dht
Class Sync<T>

java.lang.Object
  extended by org.eclipse.jgit.storage.dht.Sync<T>
Type Parameters:
T - type of value object.
All Implemented Interfaces:
AsyncCallback<T>

public abstract class Sync<T>
extends java.lang.Object
implements AsyncCallback<T>

Helper to implement a synchronous method in terms of an asynchronous one.

Implementors can use this type to wait for an asynchronous computation to complete on a background thread by passing the Sync instance as though it were the AsyncCallback:

 Sync<T> sync = Sync.create();
 async(..., sync);
 return sync.get(timeout, TimeUnit.MILLISECONDS);
 


Constructor Summary
Sync()
           
 
Method Summary
static
<T> Sync<T>
create()
          Helper method to create a new sync object.
abstract  T get(long timeout, java.util.concurrent.TimeUnit unit)
          Wait for the asynchronous operation to complete.
 T get(Timeout timeout)
          Wait for the asynchronous operation to complete.
static
<T> Sync<T>
none()
          Singleton callback that ignores onSuccess, onFailure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jgit.storage.dht.AsyncCallback
onFailure, onSuccess
 

Constructor Detail

Sync

public Sync()
Method Detail

create

public static <T> Sync<T> create()
Helper method to create a new sync object.

Type Parameters:
T - type of value object.
Returns:
a new instance.

none

public static <T> Sync<T> none()
Singleton callback that ignores onSuccess, onFailure.

Type Parameters:
T - type of value object.
Returns:
callback that discards all results.

get

public T get(Timeout timeout)
      throws DhtException,
             java.lang.InterruptedException,
             java.util.concurrent.TimeoutException
Wait for the asynchronous operation to complete.

To prevent application deadlock, waiting can only be performed with the supplied timeout.

Parameters:
timeout - amount of time to wait before failing.
Returns:
the returned value.
Throws:
DhtException - the asynchronous operation failed.
java.lang.InterruptedException - the current thread was interrupted before the operation completed.
java.util.concurrent.TimeoutException - the timeout elapsed before the operation completed.

get

public abstract T get(long timeout,
                      java.util.concurrent.TimeUnit unit)
               throws DhtException,
                      java.lang.InterruptedException,
                      java.util.concurrent.TimeoutException
Wait for the asynchronous operation to complete.

To prevent application deadlock, waiting can only be performed with the supplied timeout.

Parameters:
timeout - amount of time to wait before failing.
unit - units of timeout. For example TimeUnit.MILLISECONDS.
Returns:
the returned value.
Throws:
DhtException - the asynchronous operation failed.
java.lang.InterruptedException - the current thread was interrupted before the operation completed.
java.util.concurrent.TimeoutException - the timeout elapsed before the operation completed.


Copyright © 2011. All Rights Reserved.