Remove duplicate dependency declaration
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / osgi / NetconfOperationRouterImpl.java
index c2ab36f2c68ac8478d89fc14b02b6729e0ccf072..6915ee4bfe373fa2ac402cedb5edd5f7540f643f 100644 (file)
@@ -10,6 +10,12 @@ package org.opendaylight.controller.netconf.impl.osgi;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import java.util.TreeMap;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerSession;
@@ -17,9 +23,9 @@ import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCommit;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultGetSchema;
+import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultNetconfOperation;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultStartExi;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultStopExi;
-import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultNetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
@@ -30,15 +36,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
 public class NetconfOperationRouterImpl implements NetconfOperationRouter {
 
-    private static final Logger logger = LoggerFactory.getLogger(NetconfOperationRouterImpl.class);
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationRouterImpl.class);
 
     private final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot;
     private Set<NetconfOperation> allNetconfOperations;
@@ -47,7 +47,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot;
     }
 
-    private void initNetconfOperations(Set<NetconfOperation> allOperations) {
+    private synchronized void initNetconfOperations(Set<NetconfOperation> allOperations) {
         allNetconfOperations = allOperations;
     }
 
@@ -83,7 +83,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         for (NetconfOperationService netconfOperationService : netconfOperationServiceSnapshot.getServices()) {
             final Set<NetconfOperation> netOpsFromService = netconfOperationService.getNetconfOperations();
             for (NetconfOperation netconfOperation : netOpsFromService) {
-                Preconditions.checkState(result.contains(netconfOperation) == false,
+                Preconditions.checkState(!result.contains(netconfOperation),
                         "Netconf operation %s already present", netconfOperation);
                 result.add(netconfOperation);
             }
@@ -97,12 +97,13 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         Preconditions.checkNotNull(allNetconfOperations, "Operation router was not initialized properly");
 
         NetconfOperationExecution netconfOperationExecution;
-        String messageAsString = XmlUtil.toString(message);
 
+        String messageAsString = "";
         try {
+            messageAsString = XmlUtil.toString(message);
             netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session);
         } catch (IllegalArgumentException | IllegalStateException e) {
-            logger.warn("Unable to handle rpc {} on session {}", messageAsString, session, e);
+            LOG.warn("Unable to handle rpc {} on session {}", messageAsString, session, e);
 
             String errorMessage = String.format("Unable to handle rpc %s on session %s", messageAsString, session);
             Map<String, String> errorInfo = Maps.newHashMap();
@@ -135,7 +136,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     }
 
     private NetconfDocumentedException handleUnexpectedEx(String s, Exception e) throws NetconfDocumentedException {
-        logger.error(s, e);
+        LOG.error(s, e);
 
         Map<String, String> info = Maps.newHashMap();
         info.put(NetconfDocumentedException.ErrorSeverity.error.toString(), e.toString());
@@ -148,14 +149,14 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     private Document executeOperationWithHighestPriority(Document message,
             NetconfOperationExecution netconfOperationExecution, String messageAsString)
             throws NetconfDocumentedException {
-        logger.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.netconfOperation);
+        LOG.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.netconfOperation);
         return netconfOperationExecution.execute(message);
     }
 
     private NetconfOperationExecution getNetconfOperationWithHighestPriority(
             Document message, NetconfServerSession session) throws NetconfDocumentedException {
 
-        TreeMap<HandlingPriority, NetconfOperation> sortedByPriority = getSortedNetconfOperationsWithCanHandle(
+        NavigableMap<HandlingPriority, NetconfOperation> sortedByPriority = getSortedNetconfOperationsWithCanHandle(
                 message, session);
 
         Preconditions.checkArgument(sortedByPriority.isEmpty() == false,
@@ -174,9 +175,9 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
             if (netconfOperation instanceof DefaultNetconfOperation) {
                 ((DefaultNetconfOperation) netconfOperation).setNetconfSession(session);
             }
-            if (handlingPriority.equals(HandlingPriority.CANNOT_HANDLE) == false) {
+            if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) {
 
-                Preconditions.checkState(sortedPriority.containsKey(handlingPriority) == false,
+                Preconditions.checkState(!sortedPriority.containsKey(handlingPriority),
                         "Multiple %s available to handle message %s with priority %s",
                         NetconfOperation.class.getName(), message, handlingPriority);
                 sortedPriority.put(handlingPriority, netconfOperation);
@@ -220,7 +221,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         }
 
         public static NetconfOperationExecution createExecutionChain(
-                TreeMap<HandlingPriority, NetconfOperation> sortedByPriority, HandlingPriority handlingPriority) {
+                NavigableMap<HandlingPriority, NetconfOperation> sortedByPriority, HandlingPriority handlingPriority) {
             NetconfOperation netconfOperation = sortedByPriority.get(handlingPriority);
             HandlingPriority subsequentHandlingPriority = sortedByPriority.lowerKey(handlingPriority);