X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fservice%2FAppsCacheServiceImple.java;h=0fb929008945e1bc4093618a294df879adf3a641;hb=aa9b320ff93511280cf51b03d38fb9254af6b530;hp=06adb7f50968b0f87ea5cf7c9d406ecf5c5e39fd;hpb=fe3a67c11b65d7989a6ef648c3f34eee8abe7394;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java index 06adb7f5..0fb92900 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -73,47 +73,46 @@ public class AppsCacheServiceImple implements AppsCacheService { } } - CacheConfiguration appConf = null; - CacheConfiguration analyticsAppConf = null; + CacheConfiguration quickRefreshCacheConf = null; + CacheConfiguration slowRefreshCacheConf = null; private static volatile Map appsMap; - private static volatile Map anlyticsAppsMap; + private static volatile Map uebAppsMap; @PostConstruct public void init() { - appConf = new CacheConfiguration(0, 10); - analyticsAppConf = new CacheConfiguration(0, 3600); + quickRefreshCacheConf = new CacheConfiguration(0, 120); + slowRefreshCacheConf = new CacheConfiguration(0, 3600); - this.refreshAppsMap(appConf); + this.refreshAppsMap(quickRefreshCacheConf); } - private Map refreshAppsMap(CacheConfiguration conf) { + private void refreshAppsMap(CacheConfiguration conf) { long now = System.currentTimeMillis(); if(noNeedToUpdate(now, conf)) - return null; + return; synchronized (this) { if(noNeedToUpdate(now, conf)) - return null; + return; List allApps = appsService.getAppsFullList(); Map newAppsMap = new HashMap(); for (EPApp app : allApps) { newAppsMap.put(app.getId(), app); } - Map newAnalyticsAppsMap = new HashMap(); + Map newUebAppsMap = new HashMap(); for (EPApp app : allApps) { - newAnalyticsAppsMap.put(app.getUebKey(), app); + newUebAppsMap.put(app.getUebKey(), app); } // Switch cache with the new one. appsMap = newAppsMap; - anlyticsAppsMap = newAnalyticsAppsMap; + uebAppsMap = newUebAppsMap; conf.updateTime = now; } - return appsMap; } private boolean noNeedToUpdate(long now, CacheConfiguration conf) { @@ -127,7 +126,7 @@ public class AppsCacheServiceImple implements AppsCacheService { @Override public String getAppEndpoint(Long appId) { - refreshAppsMap(appConf); + refreshAppsMap(quickRefreshCacheConf); EPApp app = appsMap.get(appId); if(app != null) return app.getAppRestEndpoint(); @@ -136,7 +135,7 @@ public class AppsCacheServiceImple implements AppsCacheService { @Override public EPApp getApp(Long appId) { - refreshAppsMap(appConf); + refreshAppsMap(quickRefreshCacheConf); EPApp app = appsMap.get(appId); if(app != null) return app; @@ -144,9 +143,14 @@ public class AppsCacheServiceImple implements AppsCacheService { } @Override - public EPApp getAppForAnalytics(String appKey) { - refreshAppsMap(analyticsAppConf); - EPApp app = anlyticsAppsMap.get(appKey); + public EPApp getAppFromUeb(String appKey) { + return getAppFromUeb(appKey,0); + } + + @Override + public EPApp getAppFromUeb(String appKey, Integer quickCacheRefresh) { + refreshAppsMap(quickCacheRefresh == 1 ? quickRefreshCacheConf:slowRefreshCacheConf); + EPApp app = uebAppsMap.get(appKey); if(app != null) return app; return null;