summaryrefslogtreecommitdiffstats
path: root/v3po/vpp-translate-utils/src/main/java/io/fd
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/vpp-translate-utils/src/main/java/io/fd')
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/AbstractInterfaceTypeCustomizer.java4
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java56
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/WriteTimeoutException.java33
3 files changed, 74 insertions, 19 deletions
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/AbstractInterfaceTypeCustomizer.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/AbstractInterfaceTypeCustomizer.java
index e1a5bf2bc..fd08472d7 100644
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/AbstractInterfaceTypeCustomizer.java
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/AbstractInterfaceTypeCustomizer.java
@@ -65,14 +65,14 @@ public abstract class AbstractInterfaceTypeCustomizer<D extends DataObject>
*/
@Override
public final void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataAfter,
- @Nonnull final WriteContext writeContext) throws WriteFailedException.CreateFailedException {
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
checkProperInterfaceType(writeContext, id);
writeInterface(id, dataAfter, writeContext);
}
protected abstract void writeInterface(final InstanceIdentifier<D> id, final D dataAfter,
final WriteContext writeContext)
- throws WriteFailedException.CreateFailedException;
+ throws WriteFailedException;
// Validation for update and delete is not necessary
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 extends JVppReply<?>> REP getReply(Future<REP> future) throws VppBaseCallException {
+ public static <REP extends JVppReply<?>> REP getReplyForWrite(@Nonnull Future<REP> future,
+ @Nonnull final InstanceIdentifier<?> replyType)
+ throws VppBaseCallException, WriteTimeoutException {
+ return getReplyForWrite(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS);
+ }
+
+ public static <REP extends JVppReply<?>> REP getReplyForWrite(@Nonnull Future<REP> 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 extends JVppReply<?>> REP getReplyForRead(@Nonnull Future<REP> future,
+ @Nonnull final InstanceIdentifier<?> replyType)
+ throws VppBaseCallException, ReadTimeoutException {
+ return getReplyForRead(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS);
+ }
+
+ public static <REP extends JVppReply<?>> REP getReplyForRead(@Nonnull Future<REP> 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 extends JVppReply<?>> REP getReply(@Nonnull Future<REP> future)
+ throws TimeoutException, VppBaseCallException {
+ return getReply(future, DEFAULT_TIMEOUT_IN_SECONDS);
+ }
+
public static <REP extends JVppReply<?>> REP getReply(@Nonnull Future<REP> 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
*/
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/WriteTimeoutException.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/WriteTimeoutException.java
new file mode 100644
index 000000000..9516459b2
--- /dev/null
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/WriteTimeoutException.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed 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 io.fd.honeycomb.v3po.translate.v3po.util;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Thrown when write method invocation times out.
+ */
+@Beta
+public class WriteTimeoutException extends WriteFailedException {
+
+ public WriteTimeoutException(final InstanceIdentifier<?> id, final Throwable cause) {
+ super(id, cause);
+ }
+
+}