BUG-2459: Fix netconf-monitoring not reusing JAXB context 73/13373/2
authorRobert Varga <rovarga@cisco.com>
Thu, 4 Dec 2014 16:22:16 +0000 (17:22 +0100)
committerRobert Varga <rovarga@cisco.com>
Thu, 4 Dec 2014 20:04:40 +0000 (20:04 +0000)
JAXBContext can be freely reused, so cache it, as it has significant
footprint in testing tool.

Change-Id: If2f53b9dfd4a1d30390580fd800aa2f5eb4e2b72
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializer.java

index 45f02af..e80e3f8 100644 (file)
@@ -16,12 +16,20 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 public class JaxBSerializer {
+    private static final JAXBContext JAXB_CONTEXT;
+
+    static {
+        try {
+            JAXB_CONTEXT = JAXBContext.newInstance(NetconfState.class);
+        } catch (JAXBException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
 
     public Element toXml(final NetconfState monitoringModel) {
         final DOMResult res;
         try {
-            final JAXBContext jaxbContext = JAXBContext.newInstance(NetconfState.class);
-            final Marshaller marshaller = jaxbContext.createMarshaller();
+            final Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
 
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);