X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fpersist%2FPersist.java;h=d2e01215dec8d12726a4fa3b45c20977a54fe1f6;hb=deb396a3d53a84b2eb5a46d40122b4902d72c601;hp=472bb52967af86156dfeb5e686349f03e17d96a2;hpb=7e966914050e66219689001ff4ab601a49eef0ac;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/Persist.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/Persist.java index 472bb529..d2e01215 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/Persist.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/persist/Persist.java @@ -7,9 +7,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.cadi.Access; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.Access.Level; -import org.onap.aaf.cadi.client.Holder; +import org.onap.aaf.cadi.util.Holder; import org.onap.aaf.cadi.client.Result; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.util.Chrono; @@ -55,12 +55,12 @@ public abstract class Persist> extends PersistFile { // store all the directories to review // No Concurrent HashSet, or at least, it is all implemented with HashMap in older versions private static Queue> allPersists = new ConcurrentLinkedQueue>(); - + private Map tmap; protected RosettaEnv env; private RosettaDF df; - + public Persist(Access access, RosettaEnv env, Class cls, String sub_dir) throws CadiException, APIException { super(access, sub_dir); this.env = env; @@ -74,11 +74,11 @@ public abstract class Persist> extends PersistFile { } allPersists.add(this); } - + public void close() { allPersists.remove(this); } - + protected abstract CT newCacheable(T t, long expires_secsFrom1970, byte[] hash, Path path) throws APIException, IOException; public RosettaDF getDF() { @@ -113,7 +113,7 @@ public abstract class Persist> extends PersistFile { access.log(e,"Reading Token from",key); } } // if not read, then ct still==null - + // If not in memory, or on disk, get from Remote... IF reloadable (meaning, isn't hitting too often, etc). if (ct==null || ct.checkReloadable()) { // Load from external (if makes sense) @@ -133,7 +133,7 @@ public abstract class Persist> extends PersistFile { return Result.err(rtp); } } - + if (ct!=null) { tmap.put(key, ct); } @@ -149,39 +149,39 @@ public abstract class Persist> extends PersistFile { writeDisk(df, ct.get(), ct.getHash(), key, ct.expires()); tmap.put(key,ct); } - + public void delete(String key) { tmap.remove(key); deleteFromDisk(key); } public interface Loader { - Result load(String key) throws APIException, CadiException, LocatorException; + Result load(String key) throws APIException, CadiException, LocatorException; } /** * Clean will examine resources, and remove those that have expired. - * + * * If "highs" have been exceeded, then we'll expire 10% more the next time. This will adjust after each run * without checking contents more than once, making a good average "high" in the minimum speed. - * + * * @author Jonathan * */ private static final class Clean extends TimerTask { private final Access access; private long hourly; - + public Clean(Access access) { this.access = access; hourly=0; } - + private static class Metrics { public int mexists = 0, dexists=0; public int mremoved = 0, dremoved=0; } - + public void run() { final long now = System.currentTimeMillis(); final long dayFromNow = now + ONE_DAY; @@ -203,7 +203,7 @@ public abstract class Persist> extends PersistFile { p.clearCount(); } } else if (Files.exists(p.path())) { - + } } // Clear disk @@ -246,7 +246,7 @@ public abstract class Persist> extends PersistFile { sb.append(e.getMessage()); ++metrics.dremoved; } - + } return FileVisitResult.CONTINUE; } @@ -262,14 +262,14 @@ public abstract class Persist> extends PersistFile { access.log(Level.DEBUG, sb); return FileVisitResult.CONTINUE; } - + }); } catch (IOException e) { access.log(e, "Exception while cleaning Persistance"); } - + } - + // We want to print some activity of Persistence Check at least hourly, even if no activity has occurred, but not litter the log if nothing is happening boolean go=false; Level level=Level.WARN; @@ -279,9 +279,9 @@ public abstract class Persist> extends PersistFile { } else if (access.willLog(Level.WARN)) { go = metrics.mremoved>0 || metrics.dremoved>0 || --hourly <= 0; } - + if (go) { - access.printf(level, "Persist Cache: removed %d of %d items from memory and %d of %d from disk", + access.printf(level, "Persist Cache: removed %d of %d items from memory and %d of %d from disk", metrics.mremoved, metrics.mexists, metrics.dremoved, metrics.dexists); hourly = 3600000/CLEAN_CHECK; } @@ -296,6 +296,6 @@ public abstract class Persist> extends PersistFile { close(); // can call twice. } - + }