add TimeValue based getter

This commit is contained in:
kimchy 2010-03-05 01:50:40 +02:00
parent 7a38e384c9
commit 45489ed1af
2 changed files with 13 additions and 0 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.util.TimeValue;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -53,4 +54,11 @@ public interface ActionFuture<T> extends Future<T> {
* cause of the {@link java.util.concurrent.ExecutionException}.
*/
T actionGet(long timeout, TimeUnit unit) throws ElasticSearchException;
/**
* Similar to {@link #get(long, java.util.concurrent.TimeUnit)}, just wrapping the {@link InterruptedException} with
* {@link org.elasticsearch.ElasticSearchInterruptedException}, and throwing the actual
* cause of the {@link java.util.concurrent.ExecutionException}.
*/
T actionGet(TimeValue timeout) throws ElasticSearchException;
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.ElasticSearchTimeoutException;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.util.TimeValue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@ -114,6 +115,10 @@ public class PlainActionFuture<T> implements ActionFuture<T>, ActionListener<T>
return actionGet(timeoutMillis, TimeUnit.MILLISECONDS);
}
@Override public T actionGet(TimeValue timeout) throws ElasticSearchException {
return actionGet(timeout.millis(), TimeUnit.MILLISECONDS);
}
@Override public T actionGet(long timeout, TimeUnit unit) throws ElasticSearchException {
try {
return get(timeout, unit);