From 6170c47955948dbb4145ec05c5075d8df60c7991 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Mon, 8 Jun 2015 17:21:22 +0200 Subject: [PATCH] Improve performance of netconf notification processing Couple of minor performance fixes e.g: - create QName without revision when not needed - delete unnecessary logs - parse event time using QName.parseRevision Change-Id: Ic099e40fb5fdb7001af946e5f3e053911e54053f Signed-off-by: Maros Marsalek (cherry picked from commit 07797c1f8e35731ca7dce1d4524f669a171b731e) --- .../listener/NetconfDeviceCommunicator.java | 4 +--- .../mapping/NetconfMessageTransformer.java | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicator.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicator.java index 4f2f6ab38e..257cd464a9 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicator.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicator.java @@ -324,10 +324,8 @@ public class NetconfDeviceCommunicator implements NetconfClientSessionListener, } private void processNotification(final NetconfMessage notification) { - logger.debug("{}: Notification received: {}", id, notification); - if(logger.isTraceEnabled()) { - logger.trace("{}: Notification received: {}", id, msgToS(notification)); + logger.trace("{}: Notification received: {}", id, notification); } remoteDevice.onNotification(notification); diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java index 5b579a0a8a..d580043b20 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java @@ -123,8 +123,7 @@ public class NetconfMessageTransformer implements MessageTransformer stripped = stripNotification(message); final QName notificationNoRev; try { - // How to construct QName with no revision ? - notificationNoRev = QName.cachedReference(QName.create(stripped.getValue().getNamespace(), "0000-00-00", stripped.getValue().getName()).withoutRevision()); + notificationNoRev = QName.create(stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision(); } catch (final MissingNameSpaceException e) { throw new IllegalArgumentException("Unable to parse notification " + message + ", cannot find namespace", e); } @@ -144,6 +143,16 @@ public class NetconfMessageTransformer implements MessageTransformer EVENT_TIME_FORMAT = new ThreadLocal() { + protected SimpleDateFormat initialValue() { + return new SimpleDateFormat(NetconfNotification.RFC3339_DATE_FORMAT_BLUEPRINT); + } + + public void set(SimpleDateFormat value) { + throw new UnsupportedOperationException(); + } + }; + // FIXME move somewhere to util private static Map.Entry stripNotification(final NetconfMessage message) { final XmlElement xmlElement = XmlElement.fromDomDocument(message.getDocument()); @@ -165,17 +174,11 @@ public class NetconfMessageTransformer implements MessageTransformer(parseEventTime(eventTimeElement.getTextContent()), notificationElement); + return new AbstractMap.SimpleEntry<>(EVENT_TIME_FORMAT.get().parse(eventTimeElement.getTextContent()), notificationElement); } catch (NetconfDocumentedException e) { throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message); - } - } - - private static Date parseEventTime(final String eventTime) { - try { - return new SimpleDateFormat(NetconfNotification.RFC3339_DATE_FORMAT_BLUEPRINT).parse(eventTime); } catch (ParseException e) { - throw new IllegalArgumentException("Unable to parse event time from " + eventTime, e); + throw new IllegalArgumentException("Notification event time in wrong format " + EVENT_TIME + " " + message); } } -- 2.36.6