X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Futil%2FRefreshableThreadObject.java;h=3d6416cd52493f6215f827f1fddb7d5c1b8364ac;hb=7e966914050e66219689001ff4ab601a49eef0ac;hp=6892a4b5ef7ebf42be5d39c496c0a5fd7cb2e2f3;hpb=6261a19e61138e861f5c7eaf37835205f19f1fe0;p=aaf%2Fauthz.git diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java b/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java index 6892a4b5..3d6416cd 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java @@ -54,71 +54,71 @@ import org.onap.aaf.misc.env.LifeCycle; * @param */ public class RefreshableThreadObject> { - private Map objs; - private long refreshed; - private Constructor cnst; - - /** - * The passed in class must implement the constructor - *
-	 *   public MyClass(Env env) {
-	 *     ...
-	 *   }
-	 * 
- * @param clss - * @throws APIException - */ - public RefreshableThreadObject(Class clss) throws APIException { - objs = new ConcurrentHashMap<>(); - try { - cnst = clss.getConstructor(new Class[]{Env.class} ); - } catch (Exception e) { - throw new APIException(e); - } - } - - /** - * Get the "T" class from the current thread - * - * @param env - * @return T - * @throws APIException - */ - public T get(Env env) throws APIException { - Thread t = Thread.currentThread(); - T obj = objs.get(t); - if(obj==null || refreshed>obj.created()) { - try { - obj = cnst.newInstance(new Object[]{env}); - } catch (InvocationTargetException e) { - throw new APIException(e.getTargetException()); - } catch (Exception e) { - throw new APIException(e); - } - T destroyMe = objs.put(t,obj); - if(destroyMe!=null) { - destroyMe.destroy(env); - } - } - return obj; - } - - /** - * Mark the timestamp of refreshed. - * - * @param env - */ - public void refresh(Env env) { - refreshed = System.currentTimeMillis(); - } - - /** - * Remove the object from the Thread instances - * @param env - */ - public void remove(Env env) { - T obj = objs.remove(Thread.currentThread()); - if(obj!=null) - obj.destroy(env); - } + private Map objs; + private long refreshed; + private Constructor cnst; + + /** + * The passed in class must implement the constructor + *
+     *   public MyClass(Env env) {
+     *     ...
+     *   }
+     * 
+ * @param clss + * @throws APIException + */ + public RefreshableThreadObject(Class clss) throws APIException { + objs = new ConcurrentHashMap<>(); + try { + cnst = clss.getConstructor(new Class[]{Env.class} ); + } catch (Exception e) { + throw new APIException(e); + } + } + + /** + * Get the "T" class from the current thread + * + * @param env + * @return T + * @throws APIException + */ + public T get(Env env) throws APIException { + Thread t = Thread.currentThread(); + T obj = objs.get(t); + if (obj==null || refreshed>obj.created()) { + try { + obj = cnst.newInstance(new Object[]{env}); + } catch (InvocationTargetException e) { + throw new APIException(e.getTargetException()); + } catch (Exception e) { + throw new APIException(e); + } + T destroyMe = objs.put(t,obj); + if (destroyMe!=null) { + destroyMe.destroy(env); + } + } + return obj; + } + + /** + * Mark the timestamp of refreshed. + * + * @param env + */ + public void refresh(Env env) { + refreshed = System.currentTimeMillis(); + } + + /** + * Remove the object from the Thread instances + * @param env + */ + public void remove(Env env) { + T obj = objs.remove(Thread.currentThread()); + if (obj!=null) + obj.destroy(env); + } }