use shutdown to clear handle leak
[policy/xacml-pdp.git] / applications / common / src / main / java / org / onap / policy / pdp / xacml / application / common / std / StdOnapPip.java
index ca07f22..5c99932 100644 (file)
@@ -70,6 +70,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
     protected Properties properties;
     protected EntityManager em;
     protected String issuer;
+    protected boolean shutdown = false;
 
     public StdOnapPip() {
         super();
@@ -81,7 +82,14 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
     }
 
     @Override
-    public void configure(String id, Properties properties) throws PIPException {
+    public synchronized void configure(String id, Properties properties) throws PIPException {
+        //
+        // This most likely will never get called since configure is called
+        // upon startup.
+        //
+        if (this.shutdown) {
+            throw new PIPException("Engine is shutdown.");
+        }
         super.configure(id, properties);
         logger.info("Configuring historyDb PIP {}", properties);
         this.properties = properties;
@@ -114,6 +122,15 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
         }
     }
 
+    @Override
+    public synchronized void shutdown() {
+        if (this.em != null) {
+            this.em.close();
+            this.em = null;
+        }
+        this.shutdown = true;
+    }
+
     protected String getAttribute(PIPFinder pipFinder, PIPRequest pipRequest) {
         //
         // Get the actor value