Improve performance of netconf notification processing 21/23721/3
authorMaros Marsalek <mmarsale@cisco.com>
Mon, 8 Jun 2015 15:21:22 +0000 (17:21 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 22 Jul 2015 08:13:42 +0000 (08:13 +0000)
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 <mmarsale@cisco.com>
(cherry picked from commit 07797c1f8e35731ca7dce1d4524f669a171b731e)

opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicator.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java

index 4f2f6ab38ea204a45b02473b55130900d9c627c3..257cd464a996ebc4efd906dceb6fae8db3800da3 100644 (file)
@@ -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);
index 5b579a0a8a3ecd936e6e5b6605b065dcc3f3fd6e..d580043b20ac61c12d2d112f962ccfb93902e327 100644 (file)
@@ -123,8 +123,7 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         final Map.Entry<Date, XmlElement> 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<NetconfMess
         return new NetconfDeviceNotification(content, stripped.getKey());
     }
 
+    private static final ThreadLocal<SimpleDateFormat> EVENT_TIME_FORMAT = new ThreadLocal<SimpleDateFormat>() {
+        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<Date, XmlElement> stripNotification(final NetconfMessage message) {
         final XmlElement xmlElement = XmlElement.fromDomDocument(message.getDocument());
@@ -165,17 +174,11 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         }
 
         try {
-            return new AbstractMap.SimpleEntry<>(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);
         }
     }