use shutdown to clear handle leak
[policy/xacml-pdp.git] / applications / common / src / main / java / org / onap / policy / pdp / xacml / application / common / std / StdXacmlApplicationServiceProvider.java
index 9a8b63f..ba562b8 100644 (file)
@@ -283,6 +283,13 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
             PDPEngineFactory factory = getPdpEngineFactory();
             PDPEngine engine = factory.newEngine(properties);
             if (engine != null) {
+                //
+                // If there is a previous engine have it shutdown.
+                //
+                this.destroyEngine();
+                //
+                // Save it off
+                //
                 this.pdpEngine = engine;
             }
         } catch (FactoryException e) {
@@ -290,6 +297,18 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
         }
     }
 
+    protected synchronized void destroyEngine() {
+        if (this.pdpEngine == null) {
+            return;
+        }
+        try {
+            this.pdpEngine.shutdown();
+        } catch (Exception e) {
+            LOGGER.warn("Exception thrown when destroying XACML PDP engine.", e);
+        }
+        this.pdpEngine = null;
+    }
+
     /**
      * Make a decision call.
      *