From 6e3de9c3e99fdf284e63f303d3a32bd4dfbd124e Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 27 Jun 2016 10:16:31 +0200 Subject: HONEYCOMB-100: introduce default 5s timeout in TranslateUtils.getReplyFor* calls Change-Id: Iac2bb428ea6adcc8d3da2238db1dec708df550f0 Signed-off-by: Marek Gradzki --- .../v3po/translate/v3po/util/TranslateUtils.java | 56 +++++++++++++++------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java') diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java index d44bf8fd5..1a6a50133 100644 --- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java +++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java @@ -39,30 +39,53 @@ import org.openvpp.jvpp.dto.JVppReply; public final class TranslateUtils { public static final Splitter COLON_SPLITTER = Splitter.on(':'); + public static final int DEFAULT_TIMEOUT_IN_SECONDS = 5; private TranslateUtils() { } - public static > REP getReply(Future future) throws VppBaseCallException { + public static > REP getReplyForWrite(@Nonnull Future future, + @Nonnull final InstanceIdentifier replyType) + throws VppBaseCallException, WriteTimeoutException { + return getReplyForWrite(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS); + } + + public static > REP getReplyForWrite(@Nonnull Future future, + @Nonnull final InstanceIdentifier replyType, + @Nonnegative final int timeoutInSeconds) + throws VppBaseCallException, WriteTimeoutException { try { - return future.get(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IllegalStateException("Interrupted", e); - } catch (ExecutionException e) { - // Execution exception could generally contains any exception - // when using exceptions instead of return codes just rethrow it for processing on corresponding place - if (e instanceof ExecutionException && (e.getCause() instanceof VppBaseCallException)) { - throw (VppBaseCallException) (e.getCause()); - } - throw new IllegalStateException(e); + return getReply(future, timeoutInSeconds); + } catch (TimeoutException e) { + throw new WriteTimeoutException(replyType, e); } } + public static > REP getReplyForRead(@Nonnull Future future, + @Nonnull final InstanceIdentifier replyType) + throws VppBaseCallException, ReadTimeoutException { + return getReplyForRead(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS); + } + + public static > REP getReplyForRead(@Nonnull Future future, + @Nonnull final InstanceIdentifier replyType, + @Nonnegative final int timeoutInSeconds) + throws VppBaseCallException, ReadTimeoutException { + try { + return getReply(future, timeoutInSeconds); + } catch (TimeoutException e) { + throw new ReadTimeoutException(replyType, e); + } + } + + public static > REP getReply(@Nonnull Future future) + throws TimeoutException, VppBaseCallException { + return getReply(future, DEFAULT_TIMEOUT_IN_SECONDS); + } + public static > REP getReply(@Nonnull Future future, - @Nonnull final InstanceIdentifier replyType, @Nonnegative final int timeoutInSeconds) - throws ReadTimeoutException, VppBaseCallException { + throws TimeoutException, VppBaseCallException { try { checkArgument(timeoutInSeconds > 0, "Timeout cannot be < 0"); return future.get(timeoutInSeconds, TimeUnit.SECONDS); @@ -72,12 +95,10 @@ public final class TranslateUtils { } catch (ExecutionException e) { // Execution exception could generally contains any exception // when using exceptions instead of return codes just rethrow it for processing on corresponding place - if (e.getCause() instanceof VppBaseCallException) { + if (e instanceof ExecutionException && (e.getCause() instanceof VppBaseCallException)) { throw (VppBaseCallException) (e.getCause()); } throw new IllegalStateException(e); - } catch (TimeoutException e) { - throw new ReadTimeoutException(replyType, e); } } @@ -188,6 +209,7 @@ public final class TranslateUtils { /** * Reverses bytes in the byte array + * * @param bytes input array * @return reversed array */ -- cgit 1.2.3-korg