Added asConsistentMap() method to AsyncConsistentMap for creating a new ConsistentMap instance.
Moved default implementation of ConsistentMap to core/api bundle

Change-Id: Idb7457a93247a007a9990dd82ed1dfd1eaf30010
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMap.java b/core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMap.java
similarity index 93%
rename from core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMap.java
rename to core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMap.java
index f804611..5809318 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMap.java
+++ b/core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMap.java
@@ -1,5 +1,7 @@
+package org.onosproject.store.primitives;
+
 /*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2016 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,9 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package org.onosproject.store.primitives.impl;
-
 import java.util.Collection;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -30,7 +29,6 @@
 import java.util.function.Predicate;
 
 import org.onlab.util.Tools;
-import org.onosproject.store.primitives.ConsistentMapBackedJavaMap;
 import org.onosproject.store.service.AsyncConsistentMap;
 import org.onosproject.store.service.ConsistentMap;
 import org.onosproject.store.service.ConsistentMapException;
@@ -49,15 +47,15 @@
  */
 public class DefaultConsistentMap<K, V> extends Synchronous<AsyncConsistentMap<K, V>> implements ConsistentMap<K, V> {
 
-    private static final int OPERATION_TIMEOUT_MILLIS = 5000;
     private static final int MAX_DELAY_BETWEEN_RETY_MILLS = 50;
-
     private final AsyncConsistentMap<K, V> asyncMap;
+    private final long operationTimeoutMillis;
     private Map<K, V> javaMap;
 
-    public DefaultConsistentMap(AsyncConsistentMap<K, V> asyncMap) {
+    public DefaultConsistentMap(AsyncConsistentMap<K, V> asyncMap, long operationTimeoutMillis) {
         super(asyncMap);
         this.asyncMap = asyncMap;
+        this.operationTimeoutMillis = operationTimeoutMillis;
     }
 
     @Override
@@ -203,9 +201,9 @@
         return asJavaMap().toString();
     }
 
-    private static <T> T complete(CompletableFuture<T> future) {
+    private <T> T complete(CompletableFuture<T> future) {
         try {
-            return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+            return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS);
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
             throw new ConsistentMapException.Interrupted();
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java
index 2bec77a..8e2bae0 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java
@@ -25,6 +25,8 @@
 import java.util.function.Function;
 import java.util.function.Predicate;
 
+import org.onosproject.store.primitives.DefaultConsistentMap;
+
 /**
  * A distributed, strongly consistent map whose methods are all executed asynchronously.
  * <p>
@@ -315,4 +317,14 @@
      * @return future that will be completed when the operation finishes
      */
     CompletableFuture<Void> removeListener(MapEventListener<K, V> listener);
+
+    /**
+     * Returns a new {@link ConsistentMap} that is backed by this instance.
+     *
+     * @param timeoutMillis timeout duration for the returned ConsistentMap operations
+     * @return new {@code ConsistentMap} instance
+     */
+    default ConsistentMap<K, V> asConsistentMap(long timeoutMillis) {
+        return new DefaultConsistentMap<>(this, timeoutMillis);
+    }
 }
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMapBuilder.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMapBuilder.java
index cfd9425..6f3fadd 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMapBuilder.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/DefaultConsistentMapBuilder.java
@@ -41,6 +41,7 @@
     private boolean metering = true;
     private boolean relaxedReadConsistency = false;
     private final DatabaseManager manager;
+    private static final long DEFAULT_OPERATION_TIMEOUT_MILLIS = 5000L;
 
     public DefaultConsistentMapBuilder(DatabaseManager manager) {
         this.manager = manager;
@@ -107,7 +108,7 @@
 
     @Override
     public ConsistentMap<K, V> build() {
-        return new DefaultConsistentMap<>(buildAndRegisterMap());
+        return buildAndRegisterMap().asConsistentMap(DEFAULT_OPERATION_TIMEOUT_MILLIS);
     }
 
     @Override