From b731e2f1dd0972409b136aebc7b463dd72c9cfad Mon Sep 17 00:00:00 2001 From: CNlucius Date: Tue, 13 Sep 2016 11:40:12 +0800 Subject: ONOSFW-171 O/S-SFC-ONOS scenario documentation Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365 Signed-off-by: CNlucius --- .../consistent/impl/DefaultConsistentMap.java | 204 --------------------- 1 file changed, 204 deletions(-) delete mode 100644 framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultConsistentMap.java (limited to 'framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultConsistentMap.java') diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultConsistentMap.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultConsistentMap.java deleted file mode 100644 index 6f7b5487..00000000 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultConsistentMap.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2015 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. - * 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.onosproject.store.consistent.impl; - -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.Set; - -import org.onosproject.store.service.ConsistentMap; -import org.onosproject.store.service.ConsistentMapException; -import org.onosproject.store.service.MapEventListener; -import org.onosproject.store.service.Versioned; - -/** - * ConsistentMap implementation that is backed by a Raft consensus - * based database. - * - * @param type of key. - * @param type of value. - */ -public class DefaultConsistentMap implements ConsistentMap { - - private static final int OPERATION_TIMEOUT_MILLIS = 5000; - - private final DefaultAsyncConsistentMap asyncMap; - private Map javaMap; - - public String name() { - return asyncMap.name(); - } - - public DefaultConsistentMap(DefaultAsyncConsistentMap asyncMap) { - this.asyncMap = asyncMap; - } - - @Override - public int size() { - return complete(asyncMap.size()); - } - - @Override - public boolean isEmpty() { - return complete(asyncMap.isEmpty()); - } - - @Override - public boolean containsKey(K key) { - return complete(asyncMap.containsKey(key)); - } - - @Override - public boolean containsValue(V value) { - return complete(asyncMap.containsValue(value)); - } - - @Override - public Versioned get(K key) { - return complete(asyncMap.get(key)); - } - - @Override - public Versioned computeIfAbsent(K key, - Function mappingFunction) { - return complete(asyncMap.computeIfAbsent(key, mappingFunction)); - } - - @Override - public Versioned computeIfPresent(K key, - BiFunction remappingFunction) { - return complete(asyncMap.computeIfPresent(key, remappingFunction)); - } - - @Override - public Versioned compute(K key, - BiFunction remappingFunction) { - return complete(asyncMap.compute(key, remappingFunction)); - } - - @Override - public Versioned computeIf(K key, - Predicate condition, - BiFunction remappingFunction) { - return complete(asyncMap.computeIf(key, condition, remappingFunction)); - } - - @Override - public Versioned put(K key, V value) { - return complete(asyncMap.put(key, value)); - } - - @Override - public Versioned putAndGet(K key, V value) { - return complete(asyncMap.putAndGet(key, value)); - } - - @Override - public Versioned remove(K key) { - return complete(asyncMap.remove(key)); - } - - @Override - public void clear() { - complete(asyncMap.clear()); - } - - @Override - public Set keySet() { - return complete(asyncMap.keySet()); - } - - @Override - public Collection> values() { - return complete(asyncMap.values()); - } - - @Override - public Set>> entrySet() { - return complete(asyncMap.entrySet()); - } - - @Override - public Versioned putIfAbsent(K key, V value) { - return complete(asyncMap.putIfAbsent(key, value)); - } - - @Override - public boolean remove(K key, V value) { - return complete(asyncMap.remove(key, value)); - } - - @Override - public boolean remove(K key, long version) { - return complete(asyncMap.remove(key, version)); - } - - @Override - public boolean replace(K key, V oldValue, V newValue) { - return complete(asyncMap.replace(key, oldValue, newValue)); - } - - @Override - public boolean replace(K key, long oldVersion, V newValue) { - return complete(asyncMap.replace(key, oldVersion, newValue)); - } - - private static T complete(CompletableFuture future) { - try { - return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new ConsistentMapException.Interrupted(); - } catch (TimeoutException e) { - throw new ConsistentMapException.Timeout(); - } catch (ExecutionException e) { - if (e.getCause() instanceof ConsistentMapException) { - throw (ConsistentMapException) e.getCause(); - } else { - throw new ConsistentMapException(e.getCause()); - } - } - } - - @Override - public void addListener(MapEventListener listener) { - asyncMap.addListener(listener); - } - - @Override - public void removeListener(MapEventListener listener) { - asyncMap.addListener(listener); - } - - @Override - public Map asJavaMap() { - synchronized (this) { - if (javaMap == null) { - javaMap = new ConsistentMapBackedJavaMap<>(this); - } - } - return javaMap; - } -} \ No newline at end of file -- cgit 1.2.3-korg