From: Robert Varga Date: Thu, 4 Dec 2014 22:55:47 +0000 (+0100) Subject: BUG-2459: do not convert NetconfMessage X-Git-Tag: release/lithium~790^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=1c68c2531155313c1f4ec8a2f510f7a9a2db74de BUG-2459: do not convert NetconfMessage 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 --- diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java index 2aa89ba2c4..e16c0c9d9d 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -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 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); }