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=759a8c8bb2b4d838233156ae2adfe4bfed04e7b0;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=56cd54e5e9414fe9c0a9aed29279bcec4d942bad;hpb=ceda6e8bc270202bcb24340b86617110289c902e;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 56cd54e5..759a8c8b 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); + } }