BUG-2459: do not convert NetconfMessage 84/13384/5
authorRobert Varga <rovarga@cisco.com>
Thu, 4 Dec 2014 22:55:47 +0000 (23:55 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 8 Dec 2014 09:02:41 +0000 (09:02 +0000)
Router's onNetconfMessage shows up as a hotspot in performance traces,
which turns out to be another case of coversion of XML document to a
string just for debugging/error handling purposes.

In case of a debug + error we are taking the hit of one toString()
operation, but that should be fine. We make that up by being smarter
about creating maps in the error path.

Change-Id: I78ec6ad44c4689b67bbc51184465c5092b0d8657
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java

index 2aa89ba..e16c0c9 100644 (file)
@@ -96,35 +96,31 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
             final NetconfServerSession session) throws NetconfDocumentedException {
         Preconditions.checkNotNull(allNetconfOperations, "Operation router was not initialized properly");
 
-        NetconfOperationExecution netconfOperationExecution;
-
-        String messageAsString = "";
+        final NetconfOperationExecution netconfOperationExecution;
         try {
-            messageAsString = XmlUtil.toString(message);
             netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session);
         } catch (IllegalArgumentException | IllegalStateException e) {
+            final String messageAsString = XmlUtil.toString(message);
             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();
-
-            NetconfDocumentedException.ErrorTag tag;
+            final NetconfDocumentedException.ErrorTag tag;
             if (e instanceof IllegalArgumentException) {
-                errorInfo.put(NetconfDocumentedException.ErrorTag.operation_not_supported.toString(), e.getMessage());
                 tag = NetconfDocumentedException.ErrorTag.operation_not_supported;
             } else {
-                errorInfo.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage());
                 tag = NetconfDocumentedException.ErrorTag.operation_failed;
             }
 
-            throw new NetconfDocumentedException(errorMessage, e, NetconfDocumentedException.ErrorType.application,
-                    tag, NetconfDocumentedException.ErrorSeverity.error, errorInfo);
+            throw new NetconfDocumentedException(
+                String.format("Unable to handle rpc %s on session %s", messageAsString, session),
+                e, NetconfDocumentedException.ErrorType.application,
+                tag, NetconfDocumentedException.ErrorSeverity.error,
+                Collections.singletonMap(tag.toString(), e.getMessage()));
         } catch (RuntimeException e) {
             throw handleUnexpectedEx("Unexpected exception during netconf operation sort", e);
         }
 
         try {
-            return executeOperationWithHighestPriority(message, netconfOperationExecution, messageAsString);
+            return executeOperationWithHighestPriority(message, netconfOperationExecution);
         } catch (RuntimeException e) {
             throw handleUnexpectedEx("Unexpected exception during netconf operation execution", e);
         }
@@ -147,9 +143,12 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     }
 
     private Document executeOperationWithHighestPriority(final Document message,
-            final NetconfOperationExecution netconfOperationExecution, final String messageAsString)
+            final NetconfOperationExecution netconfOperationExecution)
             throws NetconfDocumentedException {
-        LOG.debug("Forwarding netconf message {} to {}", messageAsString, netconfOperationExecution.netconfOperation);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Forwarding netconf message {} to {}", XmlUtil.toString(message), netconfOperationExecution.netconfOperation);
+        }
+
         return netconfOperationExecution.execute(message);
     }