Issue 9: updated javadoc

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1433 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-16 22:07:23 +00:00
parent f5135f3868
commit 7388293178
1 changed files with 84 additions and 84 deletions

View File

@ -27,116 +27,116 @@ import java.util.concurrent.*;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* // TODO: Adrian: Document this! * Command that returns an asynchronous result. Generic type parameters associate the request (
* {@code Q}) with the response ({#code R}). When the response is parsed, it will return value (
* {@code T}).
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class FutureCommand<Q, R, T> implements Future<T> { public class FutureCommand<Q, R, T> implements Future<T> {
private final Q request; private final Q request;
private final ResponseRunnableFuture<R, T> responseRunnableFuture; private final ResponseRunnableFuture<R, T> responseRunnableFuture;
private volatile int failureCount; private volatile int failureCount;
public int incrementFailureCount() { public int incrementFailureCount() {
return ++failureCount; return ++failureCount;
} }
public int getFailureCount() { public int getFailureCount() {
return failureCount; return failureCount;
} }
public FutureCommand(Q request, ResponseCallable<R, T> responseCallable) { public FutureCommand(Q request, ResponseCallable<R, T> responseCallable) {
this.request = checkNotNull(request, "request"); this.request = checkNotNull(request, "request");
this.responseRunnableFuture = new ResponseRunnableFutureTask<R, T>( this.responseRunnableFuture = new ResponseRunnableFutureTask<R, T>(checkNotNull(
checkNotNull(responseCallable, "responseCallable")); responseCallable, "responseCallable"));
} }
public Q getRequest() { public Q getRequest() {
return request; return request;
} }
public ResponseRunnableFuture<R, T> getResponseFuture() { public ResponseRunnableFuture<R, T> getResponseFuture() {
return responseRunnableFuture; return responseRunnableFuture;
} }
public void setException(Exception e) { public void setException(Exception e) {
responseRunnableFuture.setException(e); responseRunnableFuture.setException(e);
} }
public boolean cancel(boolean b) { public boolean cancel(boolean b) {
return responseRunnableFuture.cancel(b); return responseRunnableFuture.cancel(b);
} }
public boolean isCancelled() { public boolean isCancelled() {
return responseRunnableFuture.isCancelled(); return responseRunnableFuture.isCancelled();
} }
public boolean isDone() { public boolean isDone() {
return responseRunnableFuture.isDone(); return responseRunnableFuture.isDone();
} }
public T get() throws InterruptedException, ExecutionException { public T get() throws InterruptedException, ExecutionException {
return responseRunnableFuture.get(); return responseRunnableFuture.get();
} }
public T get(long l, TimeUnit timeUnit) throws InterruptedException, public T get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
ExecutionException, TimeoutException { TimeoutException {
return responseRunnableFuture.get(l, timeUnit); return responseRunnableFuture.get(l, timeUnit);
} }
/** /**
* // TODO: Adrian: Document this! * // TODO: Adrian: Document this!
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public static class ResponseRunnableFutureTask<R, T> extends FutureTask<T> public static class ResponseRunnableFutureTask<R, T> extends FutureTask<T> implements
implements ResponseRunnableFuture<R, T> { ResponseRunnableFuture<R, T> {
private final ResponseCallable<R, T> callable; private final ResponseCallable<R, T> callable;
public ResponseRunnableFutureTask(ResponseCallable<R, T> tCallable) { public ResponseRunnableFutureTask(ResponseCallable<R, T> tCallable) {
super(tCallable); super(tCallable);
this.callable = tCallable; this.callable = tCallable;
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "{" + "tCallable=" + callable return getClass().getSimpleName() + "{" + "tCallable=" + callable + '}';
+ '}'; }
}
public R getResponse() { public R getResponse() {
return callable.getResponse(); return callable.getResponse();
} }
public void setResponse(R response) { public void setResponse(R response) {
callable.setResponse(response); callable.setResponse(response);
} }
/** /**
* opening this to public so that other errors can be associated with * opening this to public so that other errors can be associated with the request, for example
* the request, for example i/o errors. * i/o errors.
* *
* @param throwable * @param throwable
*/ */
@Override @Override
public void setException(Throwable throwable) { public void setException(Throwable throwable) {
super.setException(throwable); super.setException(throwable);
} }
} }
public interface ResponseRunnableFuture<R, T> extends Response<R>, public interface ResponseRunnableFuture<R, T> extends Response<R>, Runnable, Future<T> {
Runnable, Future<T> { public void setException(Throwable throwable);
public void setException(Throwable throwable); }
}
public interface ResponseCallable<R, T> extends Response<R>, Callable<T> { public interface ResponseCallable<R, T> extends Response<R>, Callable<T> {
} }
public interface Response<R> { public interface Response<R> {
public R getResponse(); public R getResponse();
public void setResponse(R response); public void setResponse(R response);
} }
} }