[ONOS-5874] Applying timeout for transactConfig().get(..) for preventing permanent block
in case of OVSDB connection closing
+ Extracted timeout as constant
Change-Id: I9dcc7748ed126653664f968d98c981414ca9a8cb
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
index d5fed14..e8dbcb5 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
@@ -90,6 +90,8 @@
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -100,6 +102,8 @@
*/
public class DefaultOvsdbClient implements OvsdbProviderService, OvsdbClientService {
+ private static final int TRANSACTCONFIG_TIMEOUT = 3; //sec
+
private final Logger log = LoggerFactory.getLogger(DefaultOvsdbClient.class);
private Channel channel;
@@ -958,8 +962,11 @@
List<OperationResult> results;
try {
- results = transactConfig(DATABASENAME, operations).get();
+ results = transactConfig(DATABASENAME, operations)
+ .get(TRANSACTCONFIG_TIMEOUT, TimeUnit.SECONDS);
return results.get(0).getUuid().value();
+ } catch (TimeoutException e) {
+ log.warn("TimeoutException thrown while to get result");
} catch (InterruptedException e) {
log.warn("Interrupted while waiting to get result");
Thread.currentThread().interrupt();
@@ -970,6 +977,7 @@
return null;
}
+
/**
* Handles port insert.
*