Removed sonar warnings from binding-dom-adapter. 18/46818/4
authorDana Kutenicsova <dana.kutenics@gmail.com>
Wed, 12 Oct 2016 09:00:00 +0000 (11:00 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 14 Nov 2016 13:41:03 +0000 (13:41 +0000)
Change-Id: I25fce8206a8219e9bb5479b2df07d9bb70388d89
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeIdentifier.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMCursorAwareWriteTransactionAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeProducerAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeWriteCursorAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMMountPointServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcImplementationAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingToNormalizedNodeCodec.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/ContextReferenceExtractor.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/FutureSchema.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java

index 52e2317cb34ee61dce30a9c7a3e34ea194abdc04..ab51f40ecf1ece81868283ffff63aba9ff157cc2 100644 (file)
@@ -41,7 +41,8 @@ public final class DataTreeIdentifier<T extends DataObject> implements Immutable
      *
      * @return Logical data store type. Guaranteed to be non-null.
      */
-    public @Nonnull LogicalDatastoreType getDatastoreType() {
+    @Nonnull
+    public LogicalDatastoreType getDatastoreType() {
         return datastoreType;
     }
 
@@ -50,7 +51,8 @@ public final class DataTreeIdentifier<T extends DataObject> implements Immutable
      *
      * @return Instance identifier corresponding to the root node.
      */
-    public @Nonnull InstanceIdentifier<T> getRootIdentifier() {
+    @Nonnull
+    public InstanceIdentifier<T> getRootIdentifier() {
         return rootIdentifier;
     }
 
index 6110acda6ee39d187116799b5b46ed61d74dfc2b..31c5971d0f191b47d0e5df8be915228ac03f8802 100644 (file)
@@ -34,7 +34,7 @@ public class BindingDOMCursorAwareWriteTransactionAdapter<T extends DOMDataTreeC
 
     @Nullable
     @Override
-    public <T extends DataObject> DataTreeWriteCursor createCursor(final DataTreeIdentifier<T> path) {
+    public <P extends DataObject> DataTreeWriteCursor createCursor(final DataTreeIdentifier<P> path) {
         final YangInstanceIdentifier yPath = codec.toNormalized(path.getRootIdentifier());
         final DOMDataTreeWriteCursor cursor = delegate.createCursor(
                 new DOMDataTreeIdentifier(path.getDatastoreType(), yPath));
index fd91c1c2af24e171c12705bb1050a79a3b7ef2cb..6ae74c7d9a40dc1223d3114c9c8865a431b710a9 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.mdsal.binding.api.DataTreeProducerException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerBusyException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException;
 
 class BindingDOMDataTreeProducerAdapter implements DataTreeProducer {
@@ -53,11 +52,8 @@ class BindingDOMDataTreeProducerAdapter implements DataTreeProducer {
     public void close() throws DataTreeProducerException {
         try {
             delegate.close();
-        } catch (final DOMDataTreeProducerBusyException e) {
-            throw new DataTreeProducerException(e.getMessage(), e);
         } catch (final DOMDataTreeProducerException e) {
             throw new DataTreeProducerException(e.getMessage(), e);
         }
     }
-
 }
index be5989d7944981889dd747f1e986091a95140188..afb252fc95c6ea0c195ef8ba45973e7fbb133809 100644 (file)
@@ -43,12 +43,12 @@ public class BindingDOMDataTreeWriteCursorAdapter<T extends DOMDataTreeWriteCurs
         return ret.getLastPathArgument();
     }
 
-    private <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> convertToNormalized(
-            final PathArgument child, final T data) {
+    private <P extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> convertToNormalized(
+            final PathArgument child, final P data) {
         stack.push(child);
         final InstanceIdentifier<?> iid = InstanceIdentifier.create(stack);
         final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry
-            = codec.toNormalizedNode(new SimpleEntry<>(iid, data));
+                = codec.toNormalizedNode(new SimpleEntry<>(iid, data));
         stack.pop();
         return entry;
     }
@@ -59,13 +59,13 @@ public class BindingDOMDataTreeWriteCursorAdapter<T extends DOMDataTreeWriteCurs
     }
 
     @Override
-    public <T extends DataObject> void merge(final PathArgument child, final T data) {
+    public <P extends DataObject> void merge(final PathArgument child, final P data) {
         final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = convertToNormalized(child, data);
         delegate.merge(entry.getKey().getLastPathArgument(), entry.getValue());
     }
 
     @Override
-    public <T extends DataObject> void write(PathArgument child, T data) {
+    public <P extends DataObject> void write(final PathArgument child, P data) {
         final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = convertToNormalized(child, data);
         delegate.write(entry.getKey().getLastPathArgument(), entry.getValue());
     }
index 7c5027e6c6949c58bbb4f4b2c7438e472c40b805..ba5d4fe6d2918350db60d7b56e5a631e4ba06f93 100644 (file)
@@ -48,7 +48,7 @@ public class BindingDOMMountPointServiceAdapter implements MountPointService {
         YangInstanceIdentifier domPath = codec.toYangInstanceIdentifierBlocking(mountPoint);
         Optional<DOMMountPoint> domMount = mountService.getMountPoint(domPath);
         if (domMount.isPresent()) {
-            return Optional.<MountPoint>fromNullable(bindingMountpoints.getUnchecked(domMount.get()));
+            return Optional.fromNullable(bindingMountpoints.getUnchecked(domMount.get()));
         }
         return Optional.absent();
     }
@@ -56,7 +56,7 @@ public class BindingDOMMountPointServiceAdapter implements MountPointService {
     @Override
     public <T extends MountPointListener> ListenerRegistration<T> registerListener(InstanceIdentifier<?> path,
             T listener) {
-        return new BindingDOMMountPointListenerAdapter<T>(listener,codec,mountService);
+        return new BindingDOMMountPointListenerAdapter<>(listener, codec, mountService);
     }
 
 }
index 5900ce3aaaa31264085225442d61e152f23632c3..52ef07118653697137b300562455a6eab51d442e 100644 (file)
@@ -17,7 +17,6 @@ import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.mdsal.dom.api.DOMRpcException;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
@@ -47,16 +46,13 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
     public <T extends RpcService> BindingDOMRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec,
             final Class<T> type, final Map<SchemaPath, Method> localNameToMethod, final T delegate) {
         try {
-            this.invoker = SERVICE_INVOKERS.get(type, new Callable<RpcServiceInvoker>() {
-                @Override
-                public RpcServiceInvoker call() {
-                    final Map<QName, Method> map = new HashMap<>();
-                    for (Entry<SchemaPath, Method> e : localNameToMethod.entrySet()) {
-                        map.put(e.getKey().getLastComponent(), e.getValue());
-                    }
-
-                    return RpcServiceInvoker.from(map);
+            this.invoker = SERVICE_INVOKERS.get(type, () -> {
+                final Map<QName, Method> map = new HashMap<>();
+                for (Entry<SchemaPath, Method> e : localNameToMethod.entrySet()) {
+                    map.put(e.getKey().getLastComponent(), e.getValue());
                 }
+
+                return RpcServiceInvoker.from(map);
             });
         } catch (ExecutionException e) {
             throw new IllegalArgumentException("Failed to create invokers for type " + type, e);
@@ -73,7 +69,7 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
         final SchemaPath schemaPath = rpc.getType();
         final DataObject bindingInput = input != null ? deserilialize(rpc.getType(),input) : null;
         final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath,bindingInput);
-        return transformResult(schemaPath,bindingResult);
+        return transformResult(bindingResult);
     }
 
     private DataObject deserilialize(final SchemaPath rpcPath, final NormalizedNode<?, ?> input) {
@@ -88,7 +84,7 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
         return JdkFutureAdapters.listenInPoolThread(invoker.invokeRpc(delegate, schemaPath.getLastComponent(), input));
     }
 
-    private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(final SchemaPath schemaPath,
+    private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(
             final ListenableFuture<RpcResult<?>> bindingResult) {
         return LazyDOMRpcResultFuture.create(codec, bindingResult);
     }
index a4599c9815ff65d1226daf91eecc010300874a94..991abdb061785f7557c43e6e3e66f2359fba5e77 100644 (file)
@@ -24,19 +24,18 @@ import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 
 public class BindingDOMRpcServiceAdapter implements RpcConsumerRegistry {
 
-    protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = new Factory<RpcConsumerRegistry>() {
-
-        @Override
-        public BindingDOMAdapterBuilder<RpcConsumerRegistry> newBuilder() {
-            return new Builder();
-        }
-
-    };
+    protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = Builder::new;
 
     private final LoadingCache<Class<? extends RpcService>, RpcServiceAdapter> proxies = CacheBuilder.newBuilder()
             .weakKeys()
             .build(new CacheLoader<Class<? extends RpcService>, RpcServiceAdapter>() {
 
+                private RpcServiceAdapter createProxy(final Class<? extends RpcService> key) {
+                    Preconditions.checkArgument(BindingReflections.isBindingClass(key));
+                    Preconditions.checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
+                    return new RpcServiceAdapter(key, codec, domService);
+                }
+
                 @Override
                 public RpcServiceAdapter load(final Class<? extends RpcService> key) throws Exception {
                     return createProxy(key);
@@ -60,12 +59,6 @@ public class BindingDOMRpcServiceAdapter implements RpcConsumerRegistry {
         return (T) proxies.getUnchecked(rpcService).getProxy();
     }
 
-    private RpcServiceAdapter createProxy(final Class<? extends RpcService> key) {
-        Preconditions.checkArgument(BindingReflections.isBindingClass(key));
-        Preconditions.checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
-        return new RpcServiceAdapter(key, codec, domService);
-    }
-
     private static final class Builder extends BindingDOMAdapterBuilder<RpcConsumerRegistry> {
 
         @Override
index 2a7c32932b30a47899497d9dbf192eae8c2a7e86..646c026d8ef71c786ecffeed80523c6eb1b9dd7c 100644 (file)
@@ -347,7 +347,7 @@ public final class BindingToNormalizedNodeCodec implements BindingCodecTreeFacto
          * return non-null value.
          */
         final BindingCodecTreeNode<?> codecContext = currentCodecTree.getSubtreeCodec(bindingPath);
-        return new SimpleEntry<InstanceIdentifier<?>, BindingCodecTreeNode<?>>(bindingPath, codecContext);
+        return new SimpleEntry<>(bindingPath, codecContext);
     }
 
     @SuppressWarnings("unchecked")
index e04c9256894fc3f3f07831e7a08645be6bb589c6..d9b4bf08add6b78dc463a38558a3b9cc2cb16963 100644 (file)
@@ -32,7 +32,6 @@ abstract class ContextReferenceExtractor {
         }
     };
 
-
     private static final LoadingCache<Class<?>, ContextReferenceExtractor> EXTRACTORS = CacheBuilder.newBuilder()
             .weakKeys().build(new CacheLoader<Class<?>, ContextReferenceExtractor>() {
 
@@ -40,6 +39,41 @@ abstract class ContextReferenceExtractor {
                 public ContextReferenceExtractor load(final Class<?> key) throws Exception {
                     return create(key);
                 }
+
+                @Nonnull
+                private ContextReferenceExtractor create(final Class<?> key) {
+                    final Method contextGetter = getContextGetter(key);
+                    if (contextGetter == null) {
+                        return NULL_EXTRACTOR;
+                    }
+                    final Class<?> returnType = contextGetter.getReturnType();
+                    try {
+                        if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
+                            return DirectGetterRouteContextExtractor.create(contextGetter);
+                        }
+                        final Method getValueMethod = findGetValueMethod(returnType, InstanceIdentifier.class);
+                        if (getValueMethod != null) {
+                            return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
+                        } else {
+                            LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",
+                                    returnType);
+                        }
+                    } catch (final IllegalAccessException e) {
+                        LOG.warn(
+                                "Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR",
+                                e);
+                    }
+                    return NULL_EXTRACTOR;
+                }
+
+                private Method getContextGetter(final Class<?> key) {
+                    for (final Method method : key.getMethods()) {
+                        if (method.getAnnotation(RoutingContext.class) != null) {
+                            return method;
+                        }
+                    }
+                    return null;
+                }
             });
 
 
@@ -59,30 +93,8 @@ abstract class ContextReferenceExtractor {
      * @return Instance Identifier representing context reference
      *     or null, if data object does not contain context reference.
      */
-    abstract @Nullable InstanceIdentifier<?> extract(DataObject obj);
-
-    @Nonnull
-    private static ContextReferenceExtractor create(final Class<?> key) {
-        final Method contextGetter = getContextGetter(key);
-        if (contextGetter == null) {
-            return NULL_EXTRACTOR;
-        }
-        final Class<?> returnType = contextGetter.getReturnType();
-        try {
-            if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
-                return DirectGetterRouteContextExtractor.create(contextGetter);
-            }
-            final Method getValueMethod = findGetValueMethod(returnType,InstanceIdentifier.class);
-            if (getValueMethod != null) {
-                return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
-            } else {
-                LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",returnType);
-            }
-        } catch (final IllegalAccessException e) {
-            LOG.warn("Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR", e);
-        }
-        return NULL_EXTRACTOR;
-    }
+    @Nullable
+    abstract InstanceIdentifier<?> extract(DataObject obj);
 
     @Nullable
     private static Method findGetValueMethod(final Class<?> type, final Class<?> returnType) {
@@ -96,16 +108,4 @@ abstract class ContextReferenceExtractor {
         }
         return null;
     }
-
-    private static Method getContextGetter(final Class<?> key) {
-        for (final Method method : key.getMethods()) {
-            if (method.getAnnotation(RoutingContext.class) != null) {
-                return method;
-            }
-        }
-        return null;
-    }
-
-
-
 }
index 7719bb0bab7e465777ca1db94701953ad8aa07d1..aaada60ee24d5e173b58d8cb6b2b216f343eb4bc 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.binding.Augmentation;
 class FutureSchema implements AutoCloseable {
 
     private final List<FutureSchemaPredicate> postponedOperations = new CopyOnWriteArrayList<>();
+    private final SettableFuture<?> schemaPromise = SettableFuture.create();
     private final long duration;
     private final TimeUnit unit;
 
@@ -115,8 +116,6 @@ class FutureSchema implements AutoCloseable {
         final void cancel() {
             schemaPromise.cancel(true);
         }
-
-        private final SettableFuture<?> schemaPromise = SettableFuture.create();
     }
 
 }
index 3835bc9a500e88928f96b5e9d995365e388a0a61..c5171e1228084c10034a2f0a317d6dd416809aad 100644 (file)
@@ -61,15 +61,6 @@ class RpcServiceAdapter implements InvocationHandler {
         proxy = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, this);
     }
 
-    private ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
-        final CheckedFuture<DOMRpcResult, DOMRpcException> result = delegate.invokeRpc(schemaPath, input);
-        if (result instanceof LazyDOMRpcResultFuture) {
-            return ((LazyDOMRpcResultFuture) result).getBindingFuture();
-        }
-
-        return transformFuture(schemaPath, result, codec.getCodecFactory());
-    }
-
     private RpcInvocationStrategy createStrategy(final Method method, final RpcDefinition schema) {
         final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(schema);
         if (strategy.isContextBasedRouted()) {
@@ -105,12 +96,12 @@ class RpcServiceAdapter implements InvocationHandler {
     private static boolean isObjectMethod(final Method method) {
         switch (method.getName()) {
             case "toString":
-                return (method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0);
+                return method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0;
             case "hashCode":
-                return (method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0);
+                return method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0;
             case "equals":
-                return (method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1 && method
-                        .getParameterTypes()[0] == Object.class);
+                return method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
+                        && method.getParameterTypes()[0] == Object.class;
             default:
                 return false;
         }
@@ -123,30 +114,12 @@ class RpcServiceAdapter implements InvocationHandler {
             case "hashCode":
                 return System.identityHashCode(self);
             case "equals":
-                return (self == args[0]);
+                return self == args[0];
             default:
                 return null;
         }
     }
 
-    private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
-            final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
-        return Futures.transform(domFuture, new Function<DOMRpcResult, RpcResult<?>>() {
-            @Override
-            public RpcResult<?> apply(final DOMRpcResult input) {
-                final NormalizedNode<?, ?> domData = input.getResult();
-                final DataObject bindingResult;
-                if (domData != null) {
-                    final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
-                    bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
-                } else {
-                    bindingResult = null;
-                }
-                return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
-            }
-        });
-    }
-
     private abstract class RpcInvocationStrategy {
 
         private final SchemaPath rpcName;
@@ -169,6 +142,30 @@ class RpcServiceAdapter implements InvocationHandler {
             return rpcName;
         }
 
+        private ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
+            final CheckedFuture<DOMRpcResult, DOMRpcException> result = delegate.invokeRpc(schemaPath, input);
+            if (result instanceof LazyDOMRpcResultFuture) {
+                return ((LazyDOMRpcResultFuture) result).getBindingFuture();
+            }
+
+            return transformFuture(schemaPath, result, codec.getCodecFactory());
+        }
+
+        private ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
+                final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
+            return Futures.transform(domFuture, (Function<DOMRpcResult, RpcResult<?>>) input -> {
+                final NormalizedNode<?, ?> domData = input.getResult();
+                final DataObject bindingResult;
+                if (domData != null) {
+                    final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
+                    bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
+                } else {
+                    bindingResult = null;
+                }
+                return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
+            });
+        }
+
     }
 
     private final class NonRoutedStrategy extends RpcInvocationStrategy {