X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cass%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2FCached.java;h=a3fe17571b8e8780679dd3902e23e97d8fa11d99;hb=6dd9704640eb8cc8d6b4ccd266e40a3f6f589e75;hp=5605d6535a77e3779dca55b941a92cd26abd9d70;hpb=d8ea11a483d65947152a411f10de44bc4c467ba2;p=aaf%2Fauthz.git diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java index 5605d653..a3fe1757 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java @@ -9,9 +9,9 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -40,7 +40,7 @@ import org.onap.aaf.misc.env.Trans; public class Cached extends Cache { // Java does not allow creation of Arrays with Generics in them... protected final CIDAO info; - + private static Timer infoTimer; private Object cache[]; public final int segSize; @@ -73,7 +73,7 @@ public class Cached extends Cache data) { @SuppressWarnings("unchecked") Map map = ((Map)cache[cacheIdx(key)]); @@ -105,21 +105,21 @@ public class Cached extends Cache { public abstract Result> get(); }; - + // TODO utilize Segmented Caches, and fold "get" into "reads" @SuppressWarnings("unchecked") public Result> get(TRANS trans, String key, Getter getter) { List ld = null; Result> rld = null; - + int cacheIdx = cacheIdx(key); Map map = ((Map)cache[cacheIdx]); - + // Check for saved element in cache Dated cached = map.get(key); // Note: These Segment Timestamps are kept up to date with DB Date dbStamp = info.get(trans, name,cacheIdx); - + // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax) if (cached!=null && dbStamp!=null && dbStamp.before(cached.timestamp)) { ld = (List)cached.data; @@ -139,7 +139,7 @@ public class Cached extends Cache ... dao) { - for (CachedDAO d : dao) { + for (CachedDAO d : dao) { for (int i=0;i extends Cache void startRefresh(AuthzEnv env, CIDAO cidao) { if (infoTimer==null) { infoTimer = new Timer("CachedDAO Info Refresh Timer"); - int minRefresh = 10*1000*60; // 10 mins Integer.parseInt(env.getProperty(CACHE_MIN_REFRESH_INTERVAL,"2000")); // 2 second minimum refresh + int minRefresh = 10*1000*60; // 10 mins Integer.parseInt(env.getProperty(CACHE_MIN_REFRESH_INTERVAL,"2000")); // 2 second minimum refresh infoTimer.schedule(new Refresh(env,cidao, minRefresh), 1000, minRefresh); // note: Refresh from DB immediately } } - + public static void stopTimer() { Cache.stopTimer(); if (infoTimer!=null) { @@ -162,21 +162,21 @@ public class Cached extends Cache cidao; private int minRefresh; private long lastRun; - + public Refresh(AuthzEnv env, CIDAO cidao, int minRefresh) { this.env = env; this.cidao = cidao; this.minRefresh = minRefresh; lastRun = System.currentTimeMillis()-MAXREFRESH-1000; } - + @Override public void run() { // Evaluate whether to refresh based on transaction rate