/* (non-Javadoc) * @see org.sakaiproject.sitestats.api.event.EventRegistry#getEventName(java.lang.String) */ public String getEventName(String eventId) { Locale currentUserLocale = getCurrentUserLocale(); EventLocaleKey key = new EventLocaleKey(eventId, currentUserLocale.toString()); if (eventNamesCache.containsKey(key.toString())) { return (String) eventNamesCache.get(key.toString()); } else { String eventName = null; try { String prefix = eventIdToEPPrefix.get(eventId); Statisticable s = M_epm.getProviderByPrefixAndCapability(prefix, Statisticable.class); Map<String, String> eventIdNamesMap = s.getEventNames(currentUserLocale); if (eventIdNamesMap != null) { for (String thisEventId : eventIdNamesMap.keySet()) { EventLocaleKey thisCacheKey = new EventLocaleKey(thisEventId, currentUserLocale.toString()); String thisEventName = eventIdNamesMap.get(thisEventId); eventNamesCache.put(thisCacheKey.toString(), thisEventName); if (thisEventId.equals(eventId)) { eventName = thisEventName; } } LOG.debug( "Cached event names for EB prefix '" + prefix + "', locale: " + currentUserLocale); } } catch (Exception e) { eventName = null; } return eventName; } }
/** Process event registry expired notifications */ public void update(Observable obs, Object obj) { if (NOTIF_EVENT_REGISTRY_EXPIRED.equals(obj)) { eventRegistryCache.remove(CACHENAME_EVENTREGISTRY); eventIdToolMap = null; toolEventIds = null; anonymousToolEventIds = null; LOG.debug("EventRegistry expired. Reloading..."); } }
/** Get the merged Event Registry. */ @SuppressWarnings("unchecked") private List<ToolInfo> getMergedEventRegistry() { if (eventRegistryCache.containsKey(CACHENAME_EVENTREGISTRY)) { return (List<ToolInfo>) eventRegistryCache.get(CACHENAME_EVENTREGISTRY); } else { // First: use file Event Registry List<ToolInfo> eventRegistry = fileEventRegistry.getEventRegistry(); // Second: add EntityBroker Event Registry, // replacing events for tools found on this Registry // (but keeping the anonymous flag for events in both Registries) eventRegistry = EventUtil.addToEventRegistry( entityBrokerEventRegistry.getEventRegistry(), true, eventRegistry); // Cache Event Registry eventRegistryCache.put(CACHENAME_EVENTREGISTRY, eventRegistry); LOG.debug("Cached EventRegistry."); return eventRegistry; } }
@Override public String getStatus() { // MIRRORS the OLD status report final StringBuilder buf = new StringBuilder(); buf.append("** Memory report\n"); buf.append("freeMemory: ").append(Runtime.getRuntime().freeMemory()); buf.append(" totalMemory: "); buf.append(Runtime.getRuntime().totalMemory()); buf.append(" maxMemory: "); buf.append(Runtime.getRuntime().maxMemory()); buf.append("\n\n"); String[] allCacheNames = cacheManager.getCacheNames(); Arrays.sort(allCacheNames); ArrayList<Ehcache> caches = new ArrayList<Ehcache>(allCacheNames.length); for (String cacheName : allCacheNames) { Ehcache cache = cacheManager.getCache(cacheName); caches.add(cache); } // summary (cache descriptions) for (Ehcache cache : caches) { Cache c = new EhcacheCache(cache); buf.append(c.getDescription()).append("\n"); } // extended report // TODO probably should remove this buf.append("\n** Extended Cache Report\n"); for (Ehcache cache : caches) { buf.append(cache.toString()); buf.append("\n"); } // config report buf.append("\n** Current Cache Configurations\n"); // determine whether to use old or new form keys boolean legacyKeys = true; // set true for a 2.9/BasicMemoryService compatible set of keys String maxKey = "maxEntries"; String ttlKey = "timeToLive"; String ttiKey = "timeToIdle"; String eteKey = "eternal"; //noinspection ConstantConditions if (legacyKeys) { maxKey = "maxElementsInMemory"; ttlKey = "timeToLiveSeconds"; ttiKey = "timeToIdleSeconds"; } // DEFAULT cache config CacheConfiguration defaults = cacheManager.getConfiguration().getDefaultCacheConfiguration(); long maxEntriesDefault = defaults.getMaxEntriesLocalHeap(); long ttlSecsDefault = defaults.getTimeToLiveSeconds(); long ttiSecsDefault = defaults.getTimeToIdleSeconds(); boolean eternalDefault = defaults.isEternal(); buf.append("# DEFAULTS: ") .append(maxKey) .append("=") .append(maxEntriesDefault) .append(",") .append(ttlKey) .append("=") .append(ttlSecsDefault) .append(",") .append(ttiKey) .append("=") .append(ttiSecsDefault) .append(",") .append(eteKey) .append("=") .append(eternalDefault) .append("\n"); // new: timeToLive=600,timeToIdle=360,maxEntries=5000,eternal=false // old: timeToLiveSeconds=3600,timeToIdleSeconds=900,maxElementsInMemory=20000,eternal=false for (Ehcache cache : caches) { long maxEntries = cache.getCacheConfiguration().getMaxEntriesLocalHeap(); long ttlSecs = cache.getCacheConfiguration().getTimeToLiveSeconds(); long ttiSecs = cache.getCacheConfiguration().getTimeToIdleSeconds(); boolean eternal = cache.getCacheConfiguration().isEternal(); if (maxEntries == maxEntriesDefault && ttlSecs == ttlSecsDefault && ttiSecs == ttiSecsDefault && eternal == eternalDefault) { // Cache ONLY uses the defaults buf.append("# memory.").append(cache.getName()).append(" *ALL DEFAULTS*\n"); } else { // NOT only defaults cache, show the settings that differ from the defaults buf.append("memory.").append(cache.getName()).append("="); boolean first = true; if (maxEntries != maxEntriesDefault) { //noinspection ConstantConditions first = addKeyValueToConfig(buf, maxKey, maxEntries, first); } if (ttlSecs != ttlSecsDefault) { first = addKeyValueToConfig(buf, ttlKey, ttlSecs, first); } if (ttiSecs != ttiSecsDefault) { first = addKeyValueToConfig(buf, ttiKey, ttiSecs, first); } if (eternal != eternalDefault) { addKeyValueToConfig(buf, eteKey, eternal, first); } buf.append("\n"); // TODO remove the overflow to disk check //noinspection deprecation if (cache.getCacheConfiguration().isOverflowToDisk()) { // overflowToDisk. maxEntriesLocalDisk buf.append("# NOTE: ") .append(cache.getName()) .append(" is configured for Overflow(disk), ") .append(cache.getCacheConfiguration().getMaxEntriesLocalDisk()) .append(" entries\n"); } } } final String rv = buf.toString(); log.info(rv); return rv; }