From 7a38e384c9ff783f17e9db92a730bdf654dbda6b Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 5 Mar 2010 01:48:56 +0200 Subject: [PATCH] wrap checked TimeoutException with runtime ElasticSearchTimeoutException --- .../ElasticSearchInterruptedException.java | 4 ++- .../ElasticSearchTimeoutException.java | 36 +++++++++++++++++++ .../elasticsearch/action/ActionFuture.java | 26 +++++++++++--- .../action/support/PlainActionFuture.java | 7 ++-- 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchTimeoutException.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchInterruptedException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchInterruptedException.java index 32177d82635..87657c48eb8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchInterruptedException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchInterruptedException.java @@ -20,7 +20,9 @@ package org.elasticsearch; /** - * @author kimchy (Shay Banon) (Shay Banon) + * The same as {@link InterruptedException} simply a runtime one. + * + * @author kimchy (shay.banon) */ public class ElasticSearchInterruptedException extends ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchTimeoutException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchTimeoutException.java new file mode 100644 index 00000000000..6caccaaa292 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/ElasticSearchTimeoutException.java @@ -0,0 +1,36 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch; + +/** + * The same as {@link java.util.concurrent.TimeoutException} simply a runtime one. + * + * @author kimchy (shay.banon) + */ +public class ElasticSearchTimeoutException extends ElasticSearchException { + + public ElasticSearchTimeoutException(String message) { + super(message); + } + + public ElasticSearchTimeoutException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/ActionFuture.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/ActionFuture.java index 097cc30db22..de336c2c08a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/ActionFuture.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/ActionFuture.java @@ -23,16 +23,34 @@ import org.elasticsearch.ElasticSearchException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; /** - * @author kimchy (Shay Banon) + * An extension to {@link Future} allowing for simplified "get" operations. + * + * @author kimchy (shay.banon) */ public interface ActionFuture extends Future { + /** + * Similar to {@link #get()}, just wrapping the {@link InterruptedException} with + * {@link org.elasticsearch.ElasticSearchInterruptedException}, and throwing the actual + * cause of the {@link java.util.concurrent.ExecutionException}. + */ T actionGet() throws ElasticSearchException; - T actionGet(long timeoutMillis) throws ElasticSearchException, TimeoutException; + /** + * 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}. + * + * @param timeoutMillis Timeout in millis + */ + T actionGet(long timeoutMillis) throws ElasticSearchException; - T actionGet(long timeout, TimeUnit unit) throws ElasticSearchException, TimeoutException; + /** + * 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(long timeout, TimeUnit unit) throws ElasticSearchException; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/PlainActionFuture.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/PlainActionFuture.java index 794192f685e..7a1efa80978 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/PlainActionFuture.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/PlainActionFuture.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.support; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchInterruptedException; +import org.elasticsearch.ElasticSearchTimeoutException; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; import org.elasticsearch.transport.TransportException; @@ -109,13 +110,15 @@ public class PlainActionFuture implements ActionFuture, ActionListener } } - @Override public T actionGet(long timeoutMillis) throws ElasticSearchException, TimeoutException { + @Override public T actionGet(long timeoutMillis) throws ElasticSearchException { return actionGet(timeoutMillis, TimeUnit.MILLISECONDS); } - @Override public T actionGet(long timeout, TimeUnit unit) throws ElasticSearchException, TimeoutException { + @Override public T actionGet(long timeout, TimeUnit unit) throws ElasticSearchException { try { return get(timeout, unit); + } catch (TimeoutException e) { + throw new ElasticSearchTimeoutException(e.getMessage()); } catch (InterruptedException e) { throw new ElasticSearchInterruptedException(e.getMessage()); } catch (ExecutionException e) {