CachedElement.java - Sonar Fixes
[appc.git] / appc-core / appc-common-bundle / src / main / java / org / onap / appc / pool / CachedElement.java
index e9b2ffe..c070a17 100644 (file)
@@ -6,6 +6,8 @@
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
+ * Modifications Copyright (C) 2019 IBM
+ * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -23,6 +25,9 @@
 
 package org.onap.appc.pool;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
 import java.io.Closeable;
 import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
@@ -42,6 +47,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 public class CachedElement<T extends Closeable>
         implements Closeable, InvocationHandler, CacheManagement {
+        private static final EELFLogger LOG = EELFManager.getInstance().getLogger(CachedElement.class);
 
     /**
      * The pool that is managing this cached element
@@ -85,7 +91,7 @@ public class CachedElement<T extends Closeable>
         CachedElement<T> ce = new CachedElement<>(pool, element);
         boolean found = false;
         for (Class<?> intf : interfaces) {
-            if (intf.getName().equals(CacheManagement.class.getName())) {
+            if (intf.isAssignableFrom(CacheManagement.class)) {
                 found = true;
                 break;
             }
@@ -116,7 +122,7 @@ public class CachedElement<T extends Closeable>
         try {
             pool.release((T) this);
         } catch (PoolDrainedException e) {
-            e.printStackTrace();
+            LOG.error("Pool is empty", e);
         }
     }
 
@@ -175,10 +181,8 @@ public class CachedElement<T extends Closeable>
 
         switch (method.getName()) {
             case "close":
-                if (released.compareAndSet(false, true)) {
-                    if (!pool.isDrained()) {
-                        pool.release((T) proxy);
-                    }
+                if (released.compareAndSet(false, true) && !pool.isDrained()) {
+                    pool.release((T) proxy);
                 }
                 break;
             case "equals":