Simplify code using Java 8 features
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardedDOMDataTree.java
index 0348e7a2af12fc45e86f19af0c5bcf600348feac..64c3f14dfb5dde59806c31dd3f92e92af745ebc7 100644 (file)
@@ -31,9 +31,9 @@ import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.AbstractMap.SimpleEntry;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.List;
@@ -238,17 +238,8 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
 
 
         //create shard registration for DEFAULT_SHARD
-        try {
-            initDefaultShard(LogicalDatastoreType.CONFIGURATION);
-        } catch (final InterruptedException | ExecutionException e) {
-            throw new IllegalStateException("Unable to create default shard frontend for config shard", e);
-        }
-
-        try {
-            initDefaultShard(LogicalDatastoreType.OPERATIONAL);
-        } catch (final InterruptedException | ExecutionException e) {
-            throw new IllegalStateException("Unable to create default shard frontend for operational shard", e);
-        }
+        initDefaultShard(LogicalDatastoreType.CONFIGURATION);
+        initDefaultShard(LogicalDatastoreType.OPERATIONAL);
     }
 
     private ListenableFuture<List<Void>> handleConfigShardLookup() {
@@ -267,7 +258,7 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
 
         ask.onComplete(new OnComplete<Object>() {
             @Override
-            public void onComplete(final Throwable throwable, final Object result) throws Throwable {
+            public void onComplete(final Throwable throwable, final Object result) {
                 if (throwable != null) {
                     future.setException(throwable);
                 } else {
@@ -288,12 +279,6 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
         return shardedDOMDataTree.registerListener(listener, subtrees, allowRxMerges, producers);
     }
 
-    @Override
-    @Deprecated
-    public Map<Class<? extends DOMDataTreeServiceExtension>, DOMDataTreeServiceExtension> getSupportedExtensions() {
-        return ImmutableClassToInstanceMap.of();
-    }
-
     @Override
     public ClassToInstanceMap<DOMDataTreeServiceExtension> getExtensions() {
         return ImmutableClassToInstanceMap.of();
@@ -378,19 +363,11 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
 
     void resolveShardAdditions(final Set<DOMDataTreeIdentifier> additions) {
         LOG.debug("{}: Resolving additions : {}", memberName, additions);
-        final ArrayList<DOMDataTreeIdentifier> list = new ArrayList<>(additions);
         // we need to register the shards from top to bottom, so we need to atleast make sure the ordering reflects that
-        Collections.sort(list, (o1, o2) -> {
-            if (o1.getRootIdentifier().getPathArguments().size() < o2.getRootIdentifier().getPathArguments().size()) {
-                return -1;
-            } else if (o1.getRootIdentifier().getPathArguments().size()
-                    == o2.getRootIdentifier().getPathArguments().size()) {
-                return 0;
-            } else {
-                return 1;
-            }
-        });
-        list.forEach(this::createShardFrontend);
+        additions
+            .stream()
+            .sorted(Comparator.comparingInt(o -> o.getRootIdentifier().getPathArguments().size()))
+            .forEachOrdered(this::createShardFrontend);
     }
 
     void resolveShardRemovals(final Set<DOMDataTreeIdentifier> removals) {
@@ -516,8 +493,7 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private void initDefaultShard(final LogicalDatastoreType logicalDatastoreType)
-            throws ExecutionException, InterruptedException {
+    private void initDefaultShard(final LogicalDatastoreType logicalDatastoreType) {
 
         final PrefixedShardConfigWriter writer = writerMap.get(logicalDatastoreType);