From c3211cc708a609682de0d146758c4ea59a6007f2 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 20 Dec 2012 09:10:22 +0100 Subject: [PATCH] OO-449: refactor the cache manager to be simpler --- .../cache/_i18n/LocalStrings_da.properties | 2 +- .../cache/_i18n/LocalStrings_de.properties | 2 +- .../cache/_i18n/LocalStrings_el.properties | 2 +- .../cache/_i18n/LocalStrings_en.properties | 2 +- .../cache/_i18n/LocalStrings_es.properties | 2 +- .../cache/_i18n/LocalStrings_fa.properties | 2 +- .../cache/_i18n/LocalStrings_fr.properties | 2 +- .../cache/_i18n/LocalStrings_it.properties | 2 +- .../cache/_i18n/LocalStrings_jp.properties | 2 +- .../cache/_i18n/LocalStrings_nl_NL.properties | 2 +- .../cache/_i18n/LocalStrings_pt_BR.properties | 2 +- .../cache/_i18n/LocalStrings_pt_PT.properties | 2 +- .../cache/_i18n/LocalStrings_ru.properties | 2 +- .../cache/_i18n/LocalStrings_sq.properties | 2 +- .../cache/_i18n/LocalStrings_zh_TW.properties | 2 +- .../CollaborationToolsFactory.java | 2 +- .../calendar/ICalFileCalendarManager.java | 2 +- .../jms/ClusterAdminControllerCluster.java | 6 +- .../commons/servlets/WebDAVManagerImpl.java | 2 +- .../modules/glossary/GlossaryItemManager.java | 8 +- .../mapper/manager/MapperServiceImpl.java | 6 +- .../org/olat/core/util/cache/CacheConfig.java | 99 +++++--------- .../olat/core/util/cache/CacheWrapper.java | 24 ++-- .../infinispan/InfinispanCacheWrapper.java | 124 ++++-------------- .../cache/infinispan/InfinispanCacher.java | 59 ++++++--- .../org/olat/core/util/coordinate/Cacher.java | 4 +- .../core/util/session/UserSessionManager.java | 6 +- .../java/org/olat/course/CourseFactory.java | 2 +- .../NewCachePersistingAssessmentManager.java | 29 ++-- .../service/ProjectBrokerManagerImpl.java | 2 +- .../org/olat/ims/qti/process/QTIHelper.java | 2 +- .../manager/InstantMessagingServiceImpl.java | 3 +- src/main/java/org/olat/login/LoginModule.java | 2 +- .../manager/OpenMeetingsManagerImpl.java | 11 +- .../modules/webFeed/dispatching/Path.java | 2 +- .../webFeed/managers/FeedManagerImpl.java | 2 +- .../org/olat/modules/wiki/WikiManager.java | 9 +- src/main/resources/infinispan-config.xml | 14 +- .../org/olat/core/_spring/olatcoreconfig.xml | 75 +++-------- 39 files changed, 187 insertions(+), 338 deletions(-) diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_da.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_da.properties index 8c3124eca07..9e73321e0a6 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_da.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_da.properties @@ -7,5 +7,5 @@ cache.mcexp=Miss (exp) cache.mcnotfound=Miss (ikke fundet) cache.name=Navn cache.quickcount=~ elementer -caches.title=Oversigt over EHCache (easy hibernate caches) +caches.title=Oversigt over Cache confirm.emptycache=Vil du slette alt i denne cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_de.properties index 4e38aae4242..eee0b21646a 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_de.properties @@ -11,5 +11,5 @@ cache.quickcount=~ Elemente cache.tti=Time to idle (sec) cache.ttl=Time to live (sec) cache.clustered=Clustered -caches.title=\u00DCbersicht der EHCaches (easy hibernate Caches) +caches.title=\u00DCbersicht der Caches confirm.emptycache=Wollen Sie alle Eintr\u00E4ge dieses Cache l\u00F6schen? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_el.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_el.properties index 84fc1b97952..eb915de4c55 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_el.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_el.properties @@ -10,5 +10,5 @@ cache.name=\u038C\u03BD\u03BF\u03BC\u03B1 cache.quickcount=~ \u03A3\u03C4\u03BF\u03B9\u03C7\u03B5\u03AF\u03B1 cache.tti=\u03A7\u03C1\u03CC\u03BD\u03BF\u03C2 \u0391\u03B4\u03C1\u03AC\u03BD\u03B5\u03B9\u03B1\u03C2 (\u03B4\u03B5\u03C5\u03C4.) cache.ttl=\u03A7\u03C1\u03CC\u03BD\u03BF\u03C2 \u0396\u03C9\u03AE\u03C2 (\u03B4\u03B5\u03C5\u03C4.) -caches.title=\u0395\u03C0\u03B9\u03C3\u03BA\u03CC\u03C0\u03B7\u03C3\u03B7 \u03C4\u03BF\u03C5 EHCache (easy hibernate caches) +caches.title=\u0395\u03C0\u03B9\u03C3\u03BA\u03CC\u03C0\u03B7\u03C3\u03B7 \u03C4\u03BF\u03C5 Cache confirm.emptycache=\u0398\u03AD\u03BB\u03B5\u03C4\u03B5 \u03BD\u03B1 \u03B4\u03B9\u03B1\u03B3\u03C1\u03AC\u03C8\u03B5\u03C4\u03B5 \u03CC\u03BB\u03B5\u03C2 \u03C4\u03B9\u03C2 \u03BA\u03B1\u03C4\u03B1\u03C7\u03C9\u03C1\u03AE\u03C3\u03B5\u03B9\u03C2 \u03C3\u03C4\u03B7\u03BD cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_en.properties index 0c70a38b5b4..02b7861cd5e 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_en.properties @@ -10,5 +10,5 @@ cache.name=Name cache.quickcount=~ Elements cache.tti=Time to idle (sec) cache.ttl=Time to live (sec) -caches.title=Overview of EHCache (easy hibernate caches) +caches.title=Overview of caches confirm.emptycache=Do you really want to delete all entries in this cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_es.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_es.properties index 3be6a7b9fb3..bfe0c33c145 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_es.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_es.properties @@ -10,5 +10,5 @@ cache.name=Nombre cache.quickcount=~ Elementos cache.tti=Tiempo hasta idle (sec) cache.ttl=Tiempo hasta live (sec) -caches.title=Visi\u00F3n general de EHCache (easy hibernate caches) +caches.title=Visi\u00F3n general de caches confirm.emptycache=\u00BFDesea eliminar todas las entradas de esta cach\u00E9? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fa.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fa.properties index ab10ac357bd..cc214e219b8 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fa.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fa.properties @@ -7,5 +7,5 @@ cache.mcexp=Miss (exp) cache.mcnotfound=Miss (notfnd) cache.name=Name cache.quickcount=~ Elements -caches.title=Overview of EHCache (easy hibernate caches) +caches.title=Overview of caches confirm.emptycache=Do you want to delete all entries in this cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fr.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fr.properties index 970b39ceb30..c507966831c 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fr.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_fr.properties @@ -10,5 +10,5 @@ cache.name=Nom cache.quickcount=~ \u00E9l\u00E9ments cache.tti=Time to idle (sec) cache.ttl=Time to live (sec) -caches.title=Aper\u00E7u des EHcaches (easy hibernate caches) +caches.title=Aper\u00E7u des caches confirm.emptycache=Voulez-vous effacer tous le contenu de ce cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_it.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_it.properties index da87e856248..c5ea7139a87 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_it.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_it.properties @@ -10,5 +10,5 @@ cache.name=Nome cache.quickcount=~ Elementi cache.tti=Time to idle (sec) cache.ttl=Time to live (sec) -caches.title=Visone d'insieme delle EHcaches (easy hibernate Caches) +caches.title=Visone d'insieme delle caches confirm.emptycache=Vuole eliminare tutte le entrate di questa cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_jp.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_jp.properties index 15716f68fc3..955db63acc6 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_jp.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_jp.properties @@ -8,5 +8,5 @@ cache.name=\u540D\u79F0 cache.quickcount=~ \u30A8\u30EC\u30E1\u30F3\u30C8 cache.tti=\u30A2\u30A4\u30C9\u30EB\u6642\u9593 (\u79D2) cache.ttl=\u6709\u52B9\u671F\u9593 (\u79D2) -caches.title=EHCache (easy hibernate caches) \u306E\u6982\u8981 +caches.title=Caches \u306E\u6982\u8981 confirm.emptycache=\u672C\u5F53\u306B\u3053\u306E\u30AD\u30E3\u30C3\u30B7\u30E5\u5185\u306E\u3059\u3079\u3066\u306E\u30A8\u30F3\u30C8\u30EA\u3092\u524A\u9664\u3057\u3066\u3082\u3088\u308D\u3057\u3044\u3067\u3059\u304B? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_nl_NL.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_nl_NL.properties index fab2445c596..7b86cbe10cb 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_nl_NL.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_nl_NL.properties @@ -10,5 +10,5 @@ cache.name=Name cache.quickcount=~ Elements cache.tti=Time to idle (sec) cache.ttl=Time to live (sec) -caches.title=Overzicht van EHCache (easy hibernate caches) +caches.title=Overzicht van caches confirm.emptycache=Weet u zeker dat u alle bijdragen uit deze cache wilt verwijderen? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_BR.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_BR.properties index 98063f3703b..ddc26aa2314 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_BR.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_BR.properties @@ -10,5 +10,5 @@ cache.name=Nome cache.quickcount=~ Elementos cache.tti=Tempo para dormir (sec) cache.ttl=Tempo para ativar (sec) -caches.title=Vis\u00E3o geral de EHCache (easy hibernate caches) +caches.title=Vis\u00E3o geral de caches confirm.emptycache=Voc\u00EA quer apagar todos os itens neste cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_PT.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_PT.properties index e74c1cebe64..7d641b1afe1 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_PT.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_pt_PT.properties @@ -7,5 +7,5 @@ cache.mcexp=Falta (exp) cache.mcnotfound=Falta (notfnd) cache.name=Nome cache.quickcount=~ Elementos -caches.title=Vis\u00E3o geral de EHCache (easy hibernate caches) +caches.title=Vis\u00E3o geral de caches confirm.emptycache=Voc\u00EA quer apagar todos os itens neste cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_ru.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_ru.properties index 33ddf610cf4..33a9d93e889 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_ru.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_ru.properties @@ -10,5 +10,5 @@ cache.name=\u0418\u043C\u044F cache.quickcount=~ \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432 cache.tti=\u0412\u0440\u0435\u043C\u044F \u0434\u043E idle (\u0441\u0435\u043A) cache.ttl=\u0412\u0440\u0435\u043C\u044F live (\u0441\u0435\u043A) -caches.title=\u041E\u0431\u0437\u043E\u0440 EH-\u041A\u044D\u0448-\u043F\u0430\u043C\u044F\u0442\u0438 (EHCaches - easy hibernate Caches) +caches.title=\u041E\u0431\u0437\u043E\u0440 \u041A\u044D\u0448-\u043F\u0430\u043C\u044F\u0442\u0438 confirm.emptycache=\u0425\u043E\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u0432\u0441\u0435 \u0437\u0430\u043F\u0438\u0441\u0438 \u043A\u044D\u0448? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_sq.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_sq.properties index da8b9954562..79bba585849 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_sq.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_sq.properties @@ -10,5 +10,5 @@ cache.name=Emri cache.quickcount=~ Elemente cache.tti=Koha p\u00EBr amulluar (sek) cache.ttl=Koha p\u00EBr t\u00EB gjall\u00EBruar (sek) -caches.title=Mbishikimi i EHCache (easy hibernate caches) +caches.title=Mbishikimi i caches confirm.emptycache=A doni t'i fshini t\u00EB gjitha t\u00EB hyrat n\u00EB k\u00EBt\u00EB cache? diff --git a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_zh_TW.properties b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_zh_TW.properties index aacc1559a36..667cdbb2bd2 100644 --- a/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_zh_TW.properties +++ b/src/main/java/org/olat/admin/cache/_i18n/LocalStrings_zh_TW.properties @@ -10,5 +10,5 @@ cache.name=\u540D\u7A31 cache.quickcount=~ \u5143\u7D20 cache.tti=\u9592\u7F6E\u6642\u9593(\u79D2) cache.ttl=\u5B58\u6D3B\u6642\u9593(\u79D2) -caches.title=EHCache (easy hibernate caches) \u6982\u89C0 +caches.title=Caches \u6982\u89C0 confirm.emptycache=\u60A8\u771F\u7684\u8981\u522A\u9664\u9019\u500B\u5FEB\u53D6\u7684\u6240\u6709\u9805\u76EE\u55CE\uFF1F diff --git a/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java b/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java index 8b50c8af3ff..e45c33162b4 100644 --- a/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java +++ b/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java @@ -82,7 +82,7 @@ public class CollaborationToolsFactory { public CollaborationTools execute() { if (cache == null) { - cache = coordinatorManager.getCoordinator().getCacher().getOrCreateCache(CollaborationToolsFactory.class, "tools"); + cache = coordinatorManager.getCoordinator().getCacher().getCache(CollaborationToolsFactory.class.getSimpleName(), "tools"); } CollaborationTools collabTools = (CollaborationTools) cache.get(cacheKey); if (collabTools != null) { diff --git a/src/main/java/org/olat/commons/calendar/ICalFileCalendarManager.java b/src/main/java/org/olat/commons/calendar/ICalFileCalendarManager.java index 70c587d289f..e4456565773 100644 --- a/src/main/java/org/olat/commons/calendar/ICalFileCalendarManager.java +++ b/src/main/java/org/olat/commons/calendar/ICalFileCalendarManager.java @@ -140,7 +140,7 @@ public class ICalFileCalendarManager extends BasicManager implements CalendarMan //made in module System.setProperty("ical4j.unfolding.relaxed", "true"); // initialize tiemzone tz = ((CalendarModule)CoreSpringFactory.getBean("calendarModule")).getDefaultTimeZone(); - calendarCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(this.getClass(), "calendar"); + calendarCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(CalendarManager.class.getSimpleName(), "calendar"); UserDeletionManager.getInstance().registerDeletableUserData(this); } diff --git a/src/main/java/org/olat/commons/coordinate/cluster/jms/ClusterAdminControllerCluster.java b/src/main/java/org/olat/commons/coordinate/cluster/jms/ClusterAdminControllerCluster.java index df1ec280b10..42e7742c04b 100644 --- a/src/main/java/org/olat/commons/coordinate/cluster/jms/ClusterAdminControllerCluster.java +++ b/src/main/java/org/olat/commons/coordinate/cluster/jms/ClusterAdminControllerCluster.java @@ -261,13 +261,13 @@ public class ClusterAdminControllerCluster extends BasicController { double avgmilis = avg / 1000000; getWindowControl().setInfo("sending "+cnt+" messages took "+inmilis+" ms, avg per messages was "+avg+" ns = "+avgmilis+" ms"); } else if (source == testCachePut) { - CacheWrapper cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(this.getClass(), "cachetest"); + CacheWrapper cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest"); // we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes. cw.update("akey", "hello"); updateCacheInfo(); } else if (source == testCachePut2) { // we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes. - CacheWrapper cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(this.getClass(), "cachetest"); + CacheWrapper cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest"); cw.update("akey", "world"); updateCacheInfo(); } else if (source == testSFUPerf) { @@ -361,7 +361,7 @@ public class ClusterAdminControllerCluster extends BasicController { } void updateCacheInfo() { - CacheWrapper cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(this.getClass(), "cachetest"); + CacheWrapper cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest"); Object val = cw.get("akey"); cachetest.contextPut("cacheval", val==null? "-null-": val); // org.olat.commons.coordinate.cluster.jms.ClusterAdminController:cachetest::0@subcachetypetest::123 diff --git a/src/main/java/org/olat/commons/servlets/WebDAVManagerImpl.java b/src/main/java/org/olat/commons/servlets/WebDAVManagerImpl.java index ff12210aa46..c9cfeaf7aad 100644 --- a/src/main/java/org/olat/commons/servlets/WebDAVManagerImpl.java +++ b/src/main/java/org/olat/commons/servlets/WebDAVManagerImpl.java @@ -108,7 +108,7 @@ public class WebDAVManagerImpl extends WebDAVManager { if (timedSessionCache == null) { synchronized (this) { - timedSessionCache = coordinatorManager.getCoordinator().getCacher().getOrCreateCache(this.getClass(), "webdav"); + timedSessionCache = coordinatorManager.getCoordinator().getCacher().getCache(WebDAVManager.class.getSimpleName(), "webdav"); } } diff --git a/src/main/java/org/olat/core/commons/modules/glossary/GlossaryItemManager.java b/src/main/java/org/olat/core/commons/modules/glossary/GlossaryItemManager.java index 07810f8949a..dbc0b755a0c 100644 --- a/src/main/java/org/olat/core/commons/modules/glossary/GlossaryItemManager.java +++ b/src/main/java/org/olat/core/commons/modules/glossary/GlossaryItemManager.java @@ -238,13 +238,7 @@ public class GlossaryItemManager extends BasicManager { public ArrayList<GlossaryItem> getGlossaryItemListByVFSItem(final VFSContainer glossaryFolder){ final String glossaryKey = ((LocalFolderImpl)glossaryFolder).getBasefile().toString(); if (glossaryCache == null) { - coordinatorManager.getCoordinator().getSyncer().doInSync(glossaryEventBus, new SyncerExecutor() { - public void execute() { - if (glossaryCache == null) { - glossaryCache = coordinatorManager.getCoordinator().getCacher().getOrCreateCache(this.getClass(), "glossary"); - } - } - }); + glossaryCache = coordinatorManager.getCoordinator().getCacher().getCache(GlossaryItemManager.class.getSimpleName(), "glossary"); } //try to load from cache ArrayList<GlossaryItem> glossaryItemList = (ArrayList<GlossaryItem>) glossaryCache.get(glossaryKey); diff --git a/src/main/java/org/olat/core/dispatcher/mapper/manager/MapperServiceImpl.java b/src/main/java/org/olat/core/dispatcher/mapper/manager/MapperServiceImpl.java index e20f94c10c1..9b74bd66360 100644 --- a/src/main/java/org/olat/core/dispatcher/mapper/manager/MapperServiceImpl.java +++ b/src/main/java/org/olat/core/dispatcher/mapper/manager/MapperServiceImpl.java @@ -54,13 +54,13 @@ public class MapperServiceImpl implements MapperService { private Map<Mapper,String> mapperToMapperId = new HashMap<Mapper, String>(); private Map<String,List<String>> sessionIdToMapperIds = new HashMap<String,List<String>>(); - private CacheWrapper mapperCache; + private CacheWrapper<String, Serializable> mapperCache; @Autowired private MapperDAO mapperDao; - private CacheWrapper getMapperCache() { + private CacheWrapper<String, Serializable> getMapperCache() { if (mapperCache == null) { OLATResourceable ores = OresHelper.createOLATResourceableType(Mapper.class); CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() { @@ -68,7 +68,7 @@ public class MapperServiceImpl implements MapperService { public void execute() { if (mapperCache == null) { Coordinator coordinator = CoordinatorManager.getInstance().getCoordinator(); - mapperCache = coordinator.getCacher().getOrCreateCache(MapperService.class, "mapper"); + mapperCache = coordinator.getCacher().getCache(MapperService.class.getSimpleName(), "mapper"); } } }); diff --git a/src/main/java/org/olat/core/util/cache/CacheConfig.java b/src/main/java/org/olat/core/util/cache/CacheConfig.java index 6f3ce43df0d..ba7ab132d3b 100644 --- a/src/main/java/org/olat/core/util/cache/CacheConfig.java +++ b/src/main/java/org/olat/core/util/cache/CacheConfig.java @@ -25,10 +25,6 @@ */ package org.olat.core.util.cache; -import java.util.Map; - -import org.olat.core.id.OLATResourceable; -import org.olat.core.util.resource.OresHelper; /** * Description:<br> @@ -53,29 +49,9 @@ public class CacheConfig { private int timeToLive = 120; private int timeToIdle = 120; private int diskExpiryThreadIntervalSeconds = 120; - - private Map<String, CacheConfig> childrenConfig; - - public CacheConfig() { - // used by spring - } - /* - * for cloning - */ - private CacheConfig(CacheConfig config) { - this.maxElementsInMemory = config.maxElementsInMemory; - //this.memoryStoreEvictionPolicy = config.memoryStoreEvictionPolicy; - this.overflowToDisk = config.overflowToDisk; - this.diskPersistent = config.diskPersistent; - this.diskStorePath = config.diskStorePath; - this.eternal = config.eternal; - this.timeToLive = config.timeToLive; - this.timeToIdle = config.timeToIdle; - this.diskExpiryThreadIntervalSeconds = config.diskExpiryThreadIntervalSeconds; - - // no need to deep clone, since read-only config. - this.childrenConfig = config.childrenConfig; + public int getMaxElementsInMemory() { + return maxElementsInMemory; } /** @@ -95,6 +71,10 @@ public class CacheConfig { /*public void setMemoryStoreEvictionPolicy(MemoryStoreEvictionPolicy memoryStoreEvictionPolicy) { this.memoryStoreEvictionPolicy = memoryStoreEvictionPolicy; }*/ + + public boolean isOverflowToDisk() { + return overflowToDisk; + } /** * Set whether elements can overflow to disk when the in-memory cache @@ -103,6 +83,10 @@ public class CacheConfig { public void setOverflowToDisk(boolean overflowToDisk) { this.overflowToDisk = overflowToDisk; } + + public String getDiskStorePath() { + return diskStorePath; + } /** * Set the location of temporary files for the disk store of this cache. @@ -112,6 +96,14 @@ public class CacheConfig { this.diskStorePath = diskStorePath; } + public boolean isDiskPersistent() { + return diskPersistent; + } + + public boolean isEternal() { + return eternal; + } + /** * Set whether elements are considered as eternal. If "true", timeouts * are ignored and the element is never expired. Default is "false". @@ -119,6 +111,10 @@ public class CacheConfig { public void setEternal(boolean eternal) { this.eternal = eternal; } + + public int getTimeToLive() { + return timeToLive; + } /** * Set t he time in seconds to live for an element before it expires, @@ -128,6 +124,10 @@ public class CacheConfig { public void setTimeToLive(int timeToLive) { this.timeToLive = timeToLive; } + + public int getTimeToIdle() { + return timeToIdle; + } /** * Set the time in seconds to idle for an element before it expires, that is, @@ -145,6 +145,10 @@ public class CacheConfig { public void setDiskPersistent(boolean diskPersistent) { this.diskPersistent = diskPersistent; } + + public int getDiskExpiryThreadIntervalSeconds() { + return diskExpiryThreadIntervalSeconds; + } /** * Set the number of seconds between runs of the disk expiry thread. @@ -153,47 +157,4 @@ public class CacheConfig { public void setDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds) { this.diskExpiryThreadIntervalSeconds = diskExpiryThreadIntervalSeconds; } - - /** - * [used by spring] - * @param childrenConfig - */ - public void setChildrenConfig(Map<String, CacheConfig> childrenConfig) { - this.childrenConfig = childrenConfig; - } - - public CacheConfig createConfigFor(OLATResourceable ores) { - // we will first try to use the type together with the key for the lookup. if that fails, we lookup the config for the type. - // if that fails again (= no entries for that type in the spring .xml file) -> - // we take a current config (child inherit from the parent if no config is set) - CacheConfig cc = null; - if (childrenConfig == null) { - cc = this; - } else { // children are configured - cc = childrenConfig.get(OresHelper.createStringRepresenting(ores)); - if (cc == null) { - cc = childrenConfig.get(ores.getResourceableTypeName()); - } - // fallback to current config - if (cc == null) { - cc = this; - } - } - // clone the config, so that it is independent. - return new CacheConfig(cc); - } - - /** - * Return Cache-name for given class and name - * @param ownerClass - * @param name Cache-name - * @return - */ - public static String getCacheName(Class<?> ownerClass, String name) { - String cacheName = ownerClass.getName(); - if (name != null) { - cacheName = cacheName +"_"+name; - } - return cacheName; - } } diff --git a/src/main/java/org/olat/core/util/cache/CacheWrapper.java b/src/main/java/org/olat/core/util/cache/CacheWrapper.java index 8c02401dd17..17e3697c8cd 100644 --- a/src/main/java/org/olat/core/util/cache/CacheWrapper.java +++ b/src/main/java/org/olat/core/util/cache/CacheWrapper.java @@ -26,8 +26,7 @@ package org.olat.core.util.cache; import java.io.Serializable; - -import org.olat.core.id.OLATResourceable; +import java.util.List; /** @@ -90,20 +89,25 @@ public interface CacheWrapper<U, V extends Serializable> { */ public V put(U key, V value); + /** + * In the case of distributed cache, the list can be partial and + * you must carefully setup your cache. + * @return + */ + public List<U> getKeys(); + /** * removes a value from the cache. this method is thread-safe * @param key */ public void remove(U key); - public int size(); - /** - * this method is thread safe. - * creates a child cachewrapper that represents the cachewrapper for the given olatresourceable within this parent cachewrapper(the 'this' object) - * @param ores the olat resourceable - * @return the cachewrapper + * Return the size of the cache, in the case of a distributed + * cache, read carefully the documentation of the implementation + * of the cache. + * @return */ - public <W, X extends Serializable> CacheWrapper<W, Serializable> getOrCreateChildCacheWrapper(OLATResourceable ores); - + public int size(); + } diff --git a/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacheWrapper.java b/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacheWrapper.java index 42d12f2a9d0..641edcebbc9 100644 --- a/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacheWrapper.java +++ b/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacheWrapper.java @@ -26,23 +26,13 @@ package org.olat.core.util.cache.infinispan; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import org.infinispan.Cache; import org.infinispan.CacheException; -import org.infinispan.configuration.cache.Configuration; -import org.infinispan.configuration.cache.ConfigurationBuilder; -import org.infinispan.eviction.EvictionStrategy; -import org.infinispan.manager.EmbeddedCacheManager; -import org.infinispan.transaction.TransactionMode; -import org.olat.core.id.OLATResourceable; import org.olat.core.logging.OLATRuntimeException; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; -import org.olat.core.util.cache.CacheConfig; import org.olat.core.util.cache.CacheWrapper; -import org.olat.core.util.resource.OresHelper; /** * Description:<br> @@ -52,82 +42,15 @@ import org.olat.core.util.resource.OresHelper; * Initial Date: 03.10.2007 <br> * @author Felix Jost, http://www.goodsolutions.ch */ -public class InfinispanCacheWrapper implements CacheWrapper<Object,Serializable> { - private static final OLog log = Tracing.createLoggerFor(InfinispanCacheWrapper.class); - - private final String cacheName; // the fully qualified name of the cache - private final CacheConfig config; - private final EmbeddedCacheManager cachemanager; - - private Cache<Object,Serializable> cache; - private Map<String, CacheWrapper<Object, Serializable>> children = null; - - - /** - * @param cache - */ - protected InfinispanCacheWrapper(String cacheName, CacheConfig config, EmbeddedCacheManager cachemanager) { - this.cachemanager = cachemanager; - this.cacheName = cacheName; - this.config = config; - try { - // now we need a cache which has appropriate (by configuration) values for cache configs such as ttl, tti, max elements and so on. - // next line needed since cache can also be initialized through ehcache.xml - if(!cachemanager.cacheExists(cacheName)) { - Configuration conf = cachemanager.getCacheConfiguration(cacheName); - if(conf == null) { - ConfigurationBuilder builder = new ConfigurationBuilder(); - builder.eviction().strategy(EvictionStrategy.LRU); - builder.eviction().maxEntries(10000); - builder.expiration().maxIdle(900000); - builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); - builder.dataContainer().storeAsBinary().storeValuesAsBinary(false); - Configuration configurationOverride = builder.build(); - cachemanager.defineConfiguration(cacheName, configurationOverride); - } - } - cache = cachemanager.getCache(cacheName); - } catch (Exception e) { - log.error("", e); - } - } - - /** - * creates a new child instance. must be overridden by subclasses - * @param childName - * @param config - * @return - */ - protected CacheWrapper<Object,Serializable> createChildCacheWrapper(String childName, CacheConfig aconfig) { - return new InfinispanCacheWrapper(childName, aconfig, cachemanager); - } +public class InfinispanCacheWrapper<U,V extends Serializable> implements CacheWrapper<U,V> { + + private Cache<U,V> cache; /** - * - * @return the map with the children or null + * @param cache */ - protected Map<String, CacheWrapper<Object,Serializable>> getChildren() { - return children; - } - - @Override - public <W, X extends Serializable> CacheWrapper<W, Serializable> getOrCreateChildCacheWrapper(OLATResourceable ores) { - String childName = OresHelper.createStringRepresenting(ores).replace(":", "_"); - String fullcacheName = cacheName + "@" + childName; - synchronized(this) {//cluster_ok by definition of this class as used in single vm - CacheWrapper cwChild = null; - if (children == null) { - children = new HashMap<String, CacheWrapper<Object,Serializable>>(); - } else { - cwChild = children.get(childName); - } - - if (cwChild == null) { // not found yet - cwChild = createChildCacheWrapper(fullcacheName, config.createConfigFor(ores)); - children.put(childName, cwChild); - } - return cwChild; - } + protected InfinispanCacheWrapper(Cache<U,V> cache) { + this.cache = cache; } @Override @@ -135,24 +58,30 @@ public class InfinispanCacheWrapper implements CacheWrapper<Object,Serializable> return cache.size(); } + @Override + public List<U> getKeys() { + return new ArrayList<U>(cache.keySet()); + } + @Override public boolean containsKey(Object key) { return cache.containsKey(key); } // ---- cache get, set, remove - public Serializable get(Object key) { - Object elem; + @Override + public V get(U key) { + V elem; try { synchronized (cache) {//cluster_ok by definition of this class as used in single vm elem = cache.get(key); } } catch (IllegalStateException e) { - throw new OLATRuntimeException("cache state error for cache "+cacheName, e); + throw new OLATRuntimeException("cache state error for cache " + cache.getName(), e); } catch (CacheException e) { - throw new OLATRuntimeException("cache error for cache "+cacheName, e); + throw new OLATRuntimeException("cache error for cache " + cache.getName(), e); } - return (Serializable)elem; + return elem; } @Override @@ -163,8 +92,8 @@ public class InfinispanCacheWrapper implements CacheWrapper<Object,Serializable> } @Override - public Serializable update(Object key, Serializable value) { - Serializable reloaded; + public V update(U key, V value) { + V reloaded; synchronized (cache) { if(cache.containsKey(key)) { reloaded = cache.replace(key, value); @@ -176,16 +105,11 @@ public class InfinispanCacheWrapper implements CacheWrapper<Object,Serializable> } @Override - public Serializable put(Object key, Serializable value) { - Serializable reloaded; + public V put(U key, V value) { + V reloaded; synchronized (cache) { reloaded = cache.put(key, value); } return reloaded; } - - protected String getCacheName() { - return cacheName; - } - -} +} \ No newline at end of file diff --git a/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacher.java b/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacher.java index 9389b8bcbb4..8f3a537c9e6 100644 --- a/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacher.java +++ b/src/main/java/org/olat/core/util/cache/infinispan/InfinispanCacher.java @@ -25,13 +25,18 @@ */ package org.olat.core.util.cache.infinispan; +import java.io.Serializable; +import java.util.Map; + +import org.infinispan.Cache; +import org.infinispan.configuration.cache.Configuration; +import org.infinispan.configuration.cache.ConfigurationBuilder; +import org.infinispan.eviction.EvictionStrategy; import org.infinispan.manager.EmbeddedCacheManager; -import org.olat.core.id.OLATResourceable; -import org.olat.core.logging.AssertException; +import org.infinispan.transaction.TransactionMode; import org.olat.core.util.cache.CacheConfig; import org.olat.core.util.cache.CacheWrapper; import org.olat.core.util.coordinate.Cacher; -import org.olat.core.util.resource.OresHelper; /** * Description:<br> @@ -43,36 +48,56 @@ import org.olat.core.util.resource.OresHelper; */ public class InfinispanCacher implements Cacher { - private InfinispanCacheWrapper rootCacheWrapperImpl; private EmbeddedCacheManager cacheManager; - private CacheConfig rootConfig; + private Map<String, CacheConfig> configs; public InfinispanCacher(EmbeddedCacheManager cacheManager) { this.cacheManager = cacheManager; } - public void init() { - if (rootConfig == null) { - throw new AssertException("rootConfig property must not be null!"); - } - rootCacheWrapperImpl = new InfinispanCacheWrapper(this.getClass().getSimpleName(), rootConfig, cacheManager); - } - @Override public EmbeddedCacheManager getCacheContainer() { return cacheManager; } - public CacheWrapper getOrCreateCache(Class<?> ownerClass, String name) { - OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck(CacheConfig.getCacheName(ownerClass, name), new Long(0)); - return rootCacheWrapperImpl.getOrCreateChildCacheWrapper(ores); + @Override + public <U, V extends Serializable> CacheWrapper<U, V> getCache(String type, String name) { + String cacheName = type + "@" + name; + if(!cacheManager.cacheExists(cacheName)) { + createInfinispanConfiguration(type, cacheName); + } + + Cache<U, V> cache = cacheManager.getCache(cacheName); + return new InfinispanCacheWrapper<U,V>(cache); + } + + private void createInfinispanConfiguration(String type, String cacheName) { + Configuration conf = cacheManager.getCacheConfiguration(type); + if(conf == null) { + int maxEntries = 10000; + long maxIdle = 900000l; + + CacheConfig oConfig = configs.get(type); + if(oConfig != null) { + maxEntries = oConfig.getMaxElementsInMemory(); + maxIdle = oConfig.getTimeToIdle(); + } + ConfigurationBuilder builder = new ConfigurationBuilder(); + builder.eviction().strategy(EvictionStrategy.LRU); + builder.eviction().maxEntries(maxEntries); + builder.expiration().maxIdle(maxIdle); + builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); + builder.dataContainer().storeAsBinary().storeValuesAsBinary(false); + Configuration configurationOverride = builder.build(); + cacheManager.defineConfiguration(cacheName, configurationOverride); + } } /** * [used by spring] * @param rootConfig */ - public void setRootConfig(CacheConfig rootConfig) { - this.rootConfig = rootConfig; + public void setCacheConfig(Map<String,CacheConfig> configs) { + this.configs = configs; } } diff --git a/src/main/java/org/olat/core/util/coordinate/Cacher.java b/src/main/java/org/olat/core/util/coordinate/Cacher.java index 176ab325706..1d151dd2868 100644 --- a/src/main/java/org/olat/core/util/coordinate/Cacher.java +++ b/src/main/java/org/olat/core/util/coordinate/Cacher.java @@ -25,6 +25,8 @@ */ package org.olat.core.util.coordinate; +import java.io.Serializable; + import org.infinispan.manager.EmbeddedCacheManager; import org.olat.core.util.cache.CacheWrapper; @@ -63,7 +65,7 @@ public interface Cacher { * @param name an optional name to be able to create more than one cache for the same coOwnerClass * @return the CacheWrapper to use for caching and/or for creating subcaches */ - public CacheWrapper getOrCreateCache(Class<?> coOwnerClass, String name); + public <U, V extends Serializable> CacheWrapper<U, V> getCache(String type, String name); public EmbeddedCacheManager getCacheContainer(); diff --git a/src/main/java/org/olat/core/util/session/UserSessionManager.java b/src/main/java/org/olat/core/util/session/UserSessionManager.java index a1c9a72d9be..4c25e2186de 100644 --- a/src/main/java/org/olat/core/util/session/UserSessionManager.java +++ b/src/main/java/org/olat/core/util/session/UserSessionManager.java @@ -96,7 +96,7 @@ public class UserSessionManager implements GenericEventListener { @PostConstruct public void initBean() { coordinator.getCoordinator().getEventBus().registerFor(this, null, ORES_USERSESSION); - userSessionCache = coordinator.getCoordinator().getCacher().getOrCreateCache(UserSessionManager.class, "usersession"); + userSessionCache = coordinator.getCoordinator().getCacher().getCache(UserSessionManager.class.getSimpleName(), "usersession"); } /** @@ -208,6 +208,10 @@ public class UserSessionManager implements GenericEventListener { return userSessionCache.size(); } + public Collection<Long> getUsersOnline() { + return userSessionCache.getKeys(); + } + /** * @return The number of users currently logged in using a WebDAV client. * Note that currently this only returns the users from this VM as diff --git a/src/main/java/org/olat/course/CourseFactory.java b/src/main/java/org/olat/course/CourseFactory.java index 4a9bb169bdb..9dd80f31052 100644 --- a/src/main/java/org/olat/course/CourseFactory.java +++ b/src/main/java/org/olat/course/CourseFactory.java @@ -163,7 +163,7 @@ public class CourseFactory extends BasicManager { */ private CourseFactory(CoordinatorManager coordinatorManager, RepositoryManager repositoryManager, OLATResourceManager olatResourceManager, BaseSecurity securityManager, ReferenceManager referenceManager, GlossaryManager glossaryManager) { - loadedCourses = coordinatorManager.getCoordinator().getCacher().getOrCreateCache(CourseFactory.class, "courses"); + loadedCourses = coordinatorManager.getCoordinator().getCacher().getCache(CourseFactory.class.getSimpleName(), "courses"); CourseFactory.repositoryManager = repositoryManager; CourseFactory.olatResourceManager = olatResourceManager; CourseFactory.securityManager = securityManager; diff --git a/src/main/java/org/olat/course/assessment/NewCachePersistingAssessmentManager.java b/src/main/java/org/olat/course/assessment/NewCachePersistingAssessmentManager.java index 55b3f05a0d0..d0de0f878d1 100644 --- a/src/main/java/org/olat/course/assessment/NewCachePersistingAssessmentManager.java +++ b/src/main/java/org/olat/course/assessment/NewCachePersistingAssessmentManager.java @@ -118,12 +118,9 @@ public class NewCachePersistingAssessmentManager extends BasicManager implements // Float and Integer are immutable objects, we can reuse them. private static final Float FLOAT_ZERO = new Float(0); private static final Integer INTEGER_ZERO = new Integer(0); - - // one cache entry point to generate subcaches for all assessmentmanager instances - private static CacheWrapper assessmentMainCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(NewCachePersistingAssessmentManager.class, null); // the cache per assessment manager instance (=per course) - private CacheWrapper courseCache; + private CacheWrapper<Long,HashMap<String, Serializable>> courseCache; private OLATResourceable ores; // we cannot store the ref to cpm here, since at the time where the assessmentManager is initialized, the given course is not fully initialized yet. @@ -147,7 +144,9 @@ public class NewCachePersistingAssessmentManager extends BasicManager implements */ private NewCachePersistingAssessmentManager(ICourse course) { this.ores = course; - courseCache = assessmentMainCache.getOrCreateChildCacheWrapper(course); + String cacheName = "Course@" + course.getResourceableId(); + courseCache = CoordinatorManager.getInstance().getCoordinator().getCacher() + .getCache(AssessmentManager.class.getSimpleName(), cacheName); } /** * @param identity the identity for which to properties are to be loaded. @@ -236,10 +235,10 @@ public class NewCachePersistingAssessmentManager extends BasicManager implements * @return a Map containing nodeident+"_"+ e.g. PASSED as key, Boolean (for PASSED), Float (for SCORE), or Integer (for ATTEMPTS) as values */ private Map<String, Serializable> getOrLoadScorePassedAttemptsMap(Identity identity, List<Property> properties, boolean prepareForNewData) { - CacheWrapper cw = getCacheWrapperFor(identity); - synchronized(cw) { // o_clusterOK by:fj : we sync on the cache to protect access within the monitor "one user in a course". + + synchronized(courseCache) { // o_clusterOK by:fj : we sync on the cache to protect access within the monitor "one user in a course". // a user is only active on one node at the same time. - Map<String, Serializable> m = (Map<String, Serializable>) cw.get(identity.getKey()); + HashMap<String, Serializable> m = courseCache.get(identity.getKey()); if (m == null) { // cache entry (=all data of the given identity in this course) has expired or has never been stored yet into the cache. // or has been invalidated (in cluster mode when puts occurred from an other node for the same cache) @@ -264,28 +263,20 @@ public class NewCachePersistingAssessmentManager extends BasicManager implements // we use a putSilent here (no invalidation notifications to other cluster nodes), since // we did not generate new data, but simply asked to reload it. if (prepareForNewData) { - cw.update(identity.getKey(), (Serializable) m); + courseCache.update(identity.getKey(), m); } else { - cw.put(identity.getKey(), (Serializable) m); + courseCache.put(identity.getKey(), m); } } else { // still in cache. if (prepareForNewData) { // but we need to notify that data has changed: we reput the data into the cache - a little hacky yes - cw.update(identity.getKey(), (Serializable) m); + courseCache.update(identity.getKey(), m); } } return m; } } - private CacheWrapper getCacheWrapperFor(Identity identity) { - // the ores is only for within the cache - //OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck("Identity", identity.getKey()); - //CacheWrapper cw = courseCache.getOrCreateChildCacheWrapper(ores); - return courseCache; - } - - // package local for perf. reasons, threadsafe. /** * puts a property into the cache. diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java index 2dafda73bfa..9daaa73ecdd 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java @@ -88,7 +88,7 @@ public class ProjectBrokerManagerImpl extends BasicManager implements ProjectBro protected ProjectBrokerManagerImpl() { // cache name should not be too long e.g. 'projectbroker' is too long, use 'pb' instead. - projectCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(ProjectBrokerManagerImpl.class, "pb"); + projectCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(ProjectBrokerManager.class.getSimpleName(), "pb"); CoreSpringFactory.getImpl(BusinessGroupService.class).registerDeletableGroupDataListener(this); logDebug("ProjectBrokerManagerImpl created"); } diff --git a/src/main/java/org/olat/ims/qti/process/QTIHelper.java b/src/main/java/org/olat/ims/qti/process/QTIHelper.java index ad3f5de01de..dbcfdaa58e2 100644 --- a/src/main/java/org/olat/ims/qti/process/QTIHelper.java +++ b/src/main/java/org/olat/ims/qti/process/QTIHelper.java @@ -78,7 +78,7 @@ public class QTIHelper { // logging private static final Logger log = Logger.getLogger(QTIHelper.class); - private static CacheWrapper ehCachLoadedQTIDocs = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(QTIHelper.class, "QTI_xml_Documents"); + private static CacheWrapper ehCachLoadedQTIDocs = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(QTIHelper.class.getSimpleName(), "QTI_xml_Documents"); /** * */ diff --git a/src/main/java/org/olat/instantMessaging/manager/InstantMessagingServiceImpl.java b/src/main/java/org/olat/instantMessaging/manager/InstantMessagingServiceImpl.java index 818c308802c..e653add9bfe 100644 --- a/src/main/java/org/olat/instantMessaging/manager/InstantMessagingServiceImpl.java +++ b/src/main/java/org/olat/instantMessaging/manager/InstantMessagingServiceImpl.java @@ -21,6 +21,7 @@ package org.olat.instantMessaging.manager; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.List; import org.olat.basesecurity.BaseSecurity; @@ -205,7 +206,7 @@ public class InstantMessagingServiceImpl extends BasicManager implements Instant @Override public List<Buddy> getOnlineBuddies() { - List<Long> ids = sessionManager.getAuthenticatedIdentityKey(); + Collection<Long> ids = sessionManager.getUsersOnline(); List<IdentityShort> contacts = securityManager.loadIdentityShortByKeys(ids); List<Buddy> buddies = new ArrayList<Buddy>(contacts.size()); for(IdentityShort contact:contacts) { diff --git a/src/main/java/org/olat/login/LoginModule.java b/src/main/java/org/olat/login/LoginModule.java index 5f55b2bf2f2..16162ab0933 100644 --- a/src/main/java/org/olat/login/LoginModule.java +++ b/src/main/java/org/olat/login/LoginModule.java @@ -231,7 +231,7 @@ public class LoginModule extends AbstractOLATModule { } // configure timed cache default params: refresh 1 minute, timeout according to configuration - failedLoginCache = coordinatorManager.getCoordinator().getCacher().getOrCreateCache(this.getClass(), "blockafterfailedattempts"); + failedLoginCache = coordinatorManager.getCoordinator().getCacher().getCache(LoginModule.class.getSimpleName(), "blockafterfailedattempts"); } diff --git a/src/main/java/org/olat/modules/openmeetings/manager/OpenMeetingsManagerImpl.java b/src/main/java/org/olat/modules/openmeetings/manager/OpenMeetingsManagerImpl.java index 9441a127a2d..8c95a5c14b4 100644 --- a/src/main/java/org/olat/modules/openmeetings/manager/OpenMeetingsManagerImpl.java +++ b/src/main/java/org/olat/modules/openmeetings/manager/OpenMeetingsManagerImpl.java @@ -20,7 +20,6 @@ package org.olat.modules.openmeetings.manager; import java.io.File; -import java.io.Serializable; import java.net.ConnectException; import java.util.ArrayList; import java.util.Collections; @@ -116,7 +115,7 @@ public class OpenMeetingsManagerImpl implements OpenMeetingsManager, UserDataDel @Autowired private RepositoryManager repositoryManager; - private CacheWrapper sessionCache; + private CacheWrapper<String,Long> sessionCache; private OpenMeetingsLanguages languagesMapping; @PostConstruct @@ -126,7 +125,7 @@ public class OpenMeetingsManagerImpl implements OpenMeetingsManager, UserDataDel languagesMapping = new OpenMeetingsLanguages(); languagesMapping.read(); - sessionCache = coordinator.getCoordinator().getCacher().getOrCreateCache(OpenMeetingsManager.class, "session"); + sessionCache = coordinator.getCoordinator().getCacher().getCache(OpenMeetingsManager.class.getSimpleName(), "session"); } @Override @@ -309,11 +308,7 @@ public class OpenMeetingsManagerImpl implements OpenMeetingsManager, UserDataDel @Override public Long getIdentityKey(String token) { - Serializable obj = sessionCache.get(token); - if(obj instanceof Long) { - return (Long)obj; - } - return null; + return sessionCache.get(token); } @Override diff --git a/src/main/java/org/olat/modules/webFeed/dispatching/Path.java b/src/main/java/org/olat/modules/webFeed/dispatching/Path.java index cc4540b2403..fb750a44ef7 100644 --- a/src/main/java/org/olat/modules/webFeed/dispatching/Path.java +++ b/src/main/java/org/olat/modules/webFeed/dispatching/Path.java @@ -54,7 +54,7 @@ import org.olat.repository.RepositoryManager; */ public class Path { // Not private for better performance (apperently) - protected static final CacheWrapper validatedUriCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(Path.class, + protected static final CacheWrapper<String,Boolean> validatedUriCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(Path.class.getSimpleName(), "feed"); // Instance variables diff --git a/src/main/java/org/olat/modules/webFeed/managers/FeedManagerImpl.java b/src/main/java/org/olat/modules/webFeed/managers/FeedManagerImpl.java index 4aa588550fe..35d29327b0d 100644 --- a/src/main/java/org/olat/modules/webFeed/managers/FeedManagerImpl.java +++ b/src/main/java/org/olat/modules/webFeed/managers/FeedManagerImpl.java @@ -192,7 +192,7 @@ public class FeedManagerImpl extends FeedManager { @SuppressWarnings("synthetic-access") public void execute() { if (feedCache == null) { - feedCache = coordinator.getCacher().getOrCreateCache(FeedManagerImpl.class, "feed"); + feedCache = coordinator.getCacher().getCache(FeedManager.class.getSimpleName(), "feed"); } } }); diff --git a/src/main/java/org/olat/modules/wiki/WikiManager.java b/src/main/java/org/olat/modules/wiki/WikiManager.java index c1423b7288c..b0008c08754 100644 --- a/src/main/java/org/olat/modules/wiki/WikiManager.java +++ b/src/main/java/org/olat/modules/wiki/WikiManager.java @@ -239,14 +239,7 @@ public class WikiManager extends BasicManager { final String wikiKey = OresHelper.createStringRepresenting(ores); //cluster_OK by guido if (wikiCache == null) { - - coordinator.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() { - public void execute() { - if (wikiCache == null) { - wikiCache = coordinator.getCoordinator().getCacher().getOrCreateCache(this.getClass(), "wiki"); - } - } - }); + wikiCache = coordinator.getCoordinator().getCacher().getCache(WikiManager.class.getSimpleName(), "wiki"); } Wiki wiki = (Wiki) wikiCache.get(wikiKey); if (wiki != null) { diff --git a/src/main/resources/infinispan-config.xml b/src/main/resources/infinispan-config.xml index e3eadb716a7..b5c66454f20 100644 --- a/src/main/resources/infinispan-config.xml +++ b/src/main/resources/infinispan-config.xml @@ -8,28 +8,22 @@ <default> <!-- Used to register JMX statistics in any available MBean server --> - <jmxStatistics enabled="false"/> + <jmxStatistics enabled="true"/> </default> - <namedCache name="InfinispanCacher@org.olat.core.dispatcher.mapper.MapperService_mapper__0"> + <namedCache name="MapperService@mapper"> <eviction maxEntries="1000" strategy="LRU"/> <expiration maxIdle="300000" wakeUpInterval="5000"/> <transaction transactionMode="NON_TRANSACTIONAL" /> </namedCache> - <namedCache name="InfinispanCacher@org.olat.modules.openmeetings.manager.OpenMeetingsManager_session__0"> - <eviction maxEntries="1000" strategy="LRU"/> - <expiration maxIdle="900000" wakeUpInterval="5000"/> - <transaction transactionMode="NON_TRANSACTIONAL" /> - </namedCache> - - <namedCache name="InfinispanCacher@org.olat.commons.servlets.RSSServlet_rssdocs__0"> + <namedCache name="OpenMeetingsManager@session"> <eviction maxEntries="1000" strategy="LRU"/> <expiration maxIdle="900000" wakeUpInterval="5000"/> <transaction transactionMode="NON_TRANSACTIONAL" /> </namedCache> - <namedCache name="InfinispanCacher@org.olat.core.util.session.UserSessionManager_usersession__0"> + <namedCache name="UserSessionManager@usersession"> <eviction strategy="NONE"/> <expiration lifespan="-1" maxIdle="-1"/> <transaction transactionMode="TRANSACTIONAL" /> diff --git a/src/main/resources/serviceconfig/org/olat/core/_spring/olatcoreconfig.xml b/src/main/resources/serviceconfig/org/olat/core/_spring/olatcoreconfig.xml index b08e4d2e179..84a7d6c3ab9 100644 --- a/src/main/resources/serviceconfig/org/olat/core/_spring/olatcoreconfig.xml +++ b/src/main/resources/serviceconfig/org/olat/core/_spring/olatcoreconfig.xml @@ -51,44 +51,32 @@ <property name="jndiName" value="${infinispan.jndi}"/> </bean> -<bean id="infinispanCacher" class="org.olat.core.util.cache.infinispan.InfinispanCacher" init-method="init"> +<bean id="infinispanCacher" class="org.olat.core.util.cache.infinispan.InfinispanCacher"> <constructor-arg index="0" ref="infinispanCacheManager"/> - <property name="rootConfig"> - <bean class="org.olat.core.util.cache.CacheConfig"> - <property name="childrenConfig"> - <map> - <entry key="org.olat.login.LoginModule_blockafterfailedattempts" value-ref="org.olat.login.LoginModule_blockafterfailedattempts" /> - <entry key="org.olat.commons.servlets.RSSServlet_rssdocs" value-ref="org.olat.commons.servlets.RSSServlet_rssdocs"/> - <entry key="org.olat.ims.qti.process.QTIHelper_QTI_xml_Documents" value-ref="org.olat.ims.qti.process.QTIHelper_QTI_xml_Documents"/> - <entry key="org.olat.modules.wiki.WikiManager_wiki" value-ref="org.olat.modules.wiki.WikiManager_wiki"/> - <entry key="org.olat.commons.calendar.ICalFileCalendarManager_calendar" value-ref="org.olat.commons.calendar.ICalFileCalendarManager_calendar" /> - <entry key="org.olat.course.CourseFactory_courses" value-ref="org.olat.course.CourseFactory_courses" /> - <entry key="org.olat.collaboration.CollaborationToolsFactory_tools" value-ref="org.olat.collaboration.CollaborationToolsFactory_tools" /> - <entry key="org.olat.course.assessment.NewCachePersistingAssessmentManager" value-ref="org.olat.course.assessment.NewCachePersistingAssessmentManager" /> - <entry key="org.olat.core.util.UserSession" value-ref="org.olat.core.util.UserSession" /> - <entry key="org.olat.core.modules.glossary.GlossaryItemManager_glossary" value-ref="org.olat.core.modules.glossary.GlossaryItemManager_glossary"/> - <entry key="org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerImpl_pb" value-ref="org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerImpl_pb"/> - <entry key="org.olat.commons.servlets.WebDAVManagerImpl_webdav" value-ref="org.olat.commons.servlets.WebDAVManagerImpl_webdav" /> - </map> - </property> - </bean> + <property name="cacheConfig"> + <map> + <entry key="LoginModule" value-ref="org.olat.login.LoginModule_blockafterfailedattempts" /> + <entry key="QTIHelper" value-ref="org.olat.ims.qti.process.QTIHelper_QTI_xml_Documents"/> + <entry key="WikiManager" value-ref="org.olat.modules.wiki.WikiManager_wiki"/> + <entry key="CalendarManager" value-ref="org.olat.commons.calendar.ICalFileCalendarManager_calendar" /> + <entry key="CourseFactory" value-ref="org.olat.course.CourseFactory_courses" /> + <entry key="CollaborationToolsFactory" value-ref="org.olat.collaboration.CollaborationToolsFactory_tools" /> + <entry key="AssessmentManager" value-ref="org.olat.course.assessment.NewCachePersistingAssessmentManager" /> + <entry key="GlossaryItemManager" value-ref="org.olat.core.modules.glossary.GlossaryItemManager_glossary"/> + <entry key="ProjectBrokerManager" value-ref="org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerImpl_pb"/> + <entry key="WebDAVManager" value-ref="org.olat.commons.servlets.WebDAVManagerImpl_webdav" /> + </map> </property> </bean> <!-- cache beans --> - +<!-- MapperService, UserSessionManager, OpenMeetingsManager, FeedManager --> <bean id="org.olat.login.LoginModule_blockafterfailedattempts" class="org.olat.core.util.cache.CacheConfig" > <property name="timeToLive" value="300" /> <property name="timeToIdle" value="0" /> <property name="maxElementsInMemory" value="1000" /> </bean> - -<bean id="org.olat.commons.servlets.RSSServlet_rssdocs" class="org.olat.core.util.cache.CacheConfig"> - <property name="timeToLive" value="190" /> - <property name="timeToIdle" value="0" /> - <property name="maxElementsInMemory" value="200" /> -</bean> <bean id="org.olat.ims.qti.process.QTIHelper_QTI_xml_Documents" class="org.olat.core.util.cache.CacheConfig"> <property name="timeToLive" value="3600" /> <property name="timeToIdle" value="1800" /> @@ -130,37 +118,10 @@ <property name="timeToIdle" value="300" /> <property name="maxElementsInMemory" value="200" /> </bean> - -<!-- caching for the olat course. a cache is segemented as follows: first per course, then per identity --> <bean id="org.olat.course.assessment.NewCachePersistingAssessmentManager" class="org.olat.core.util.cache.CacheConfig"> - <property name="timeToLive" value="1" /> - <property name="timeToIdle" value="1" /> - <property name="maxElementsInMemory" value="1" /> - <property name="childrenConfig"> - <map> - <entry key="CourseModule"> - <bean class="org.olat.core.util.cache.CacheConfig"> - <property name="childrenConfig"> - <map> - <entry key="Identity"> - <bean class="org.olat.core.util.cache.CacheConfig"> - <property name="timeToLive" value="0" /> - <property name="timeToIdle" value="60" /> - <property name="maxElementsInMemory" value="1000" /> - </bean> - </entry> - </map> - </property> - </bean> - </entry> - </map> - </property> -</bean> - -<bean id="org.olat.core.util.UserSession" class="org.olat.core.util.cache.CacheConfig"> - <property name="timeToLive" value="3600" /> - <property name="timeToIdle" value="3600" /> - <property name="maxElementsInMemory" value="2000" /> + <property name="timeToLive" value="0" /> + <property name="timeToIdle" value="60" /> + <property name="maxElementsInMemory" value="20000" /> </bean> <!-- end cache beans --> -- GitLab