Project

General

Profile

« Previous | Next » 

Revision 8b9e2e71

Added by Andreas Kohlbecker over 5 years ago

ref #7729 setting maxEntriesLocalHeap for the cdmDefaultCache and activating ehcache jmx management beans for the CdmTransientEntityCacher

View differences:

cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmTransientEntityCacher.java
8 8
 */
9 9
package eu.etaxonomy.cdm.cache;
10 10

  
11
import java.lang.management.ManagementFactory;
11 12
import java.util.ArrayList;
12 13
import java.util.Collection;
13 14
import java.util.HashMap;
......
15 16
import java.util.Map;
16 17
import java.util.UUID;
17 18

  
19
import javax.management.MBeanServer;
20

  
18 21
import org.apache.log4j.Logger;
19 22

  
20 23
import eu.etaxonomy.cdm.api.cache.CdmCacher;
......
27 30
import net.sf.ehcache.Status;
28 31
import net.sf.ehcache.config.CacheConfiguration;
29 32
import net.sf.ehcache.config.SizeOfPolicyConfiguration;
33
import net.sf.ehcache.management.ManagementService;
30 34
import net.sf.ehcache.statistics.LiveCacheStatistics;
31 35

  
32 36
/**
......
64 68
    //map for volatile entities (id=0)
65 69
    private final Map<UUID, CdmBase> newEntitiesMap = new HashMap<>();
66 70

  
71
    private static volatile boolean managementBeansConfigured = false;
72

  
67 73
// ********************* CONSTRUCTOR **********************************/
68 74

  
69 75
    public CdmTransientEntityCacher(String cacheId) {
......
71 77

  
72 78
        cache = new Cache(getEntityCacheConfiguration(cacheId));
73 79

  
74
        CacheManager.create().removeCache(cache.getName());
75
        CacheManager.create().addCache(cache);
80
        createCacheManager().removeCache(cache.getName());
81
        createCacheManager().addCache(cache);
76 82

  
77 83
        cacheLoader = new CacheLoader(this);
78 84
    }
......
124 130
     * @return
125 131
     */
126 132
    private Cache getCache() {
127
        return  CacheManager.create().getCache(cacheId);
133
        return  createCacheManager().getCache(cacheId);
134
    }
135

  
136
    /**
137
     * @return
138
     */
139
    protected CacheManager createCacheManager() {
140

  
141
        CacheManager cacheManager = CacheManager.create();
142

  
143
        if(!managementBeansConfigured){
144
            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
145
            boolean registerCacheManager = false;
146
            boolean registerCaches = true;
147
            boolean registerCacheConfigurations = false;
148
            boolean registerCacheStatistics = true;
149
            ManagementService.registerMBeans(cacheManager, mBeanServer, registerCacheManager, registerCaches, registerCacheConfigurations, registerCacheStatistics);
150
            managementBeansConfigured = true;
151
        }
152

  
153
        return cacheManager;
128 154
    }
129 155

  
130 156
    public <T extends Object> T load(T obj, boolean update) {
......
316 342
    }
317 343

  
318 344
    public void dispose() {
319
        CacheManager.create().removeCache(cache.getName());
345
        createCacheManager().removeCache(cache.getName());
320 346
        cache.dispose();
321 347
        newEntitiesMap.clear();
322

  
323 348
    }
324 349

  
325 350

  
cdmlib-remote/src/test/resources/eu/etaxonomy/cdm/remote/ehcache.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<ehcache>
2
<ehcache
3 3
  <!--
4 4
    This configuration is loaded by the default cache configuration. An in only to be used in specific 
5 5
    Test contexts.
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/cache/CdmCacher.java
28 28
    @Autowired
29 29
    public CacheManager cacheManager;
30 30

  
31
    public static final String DEFAULT_CACHE_NAME = "defaultCache"; //TODO compare with CacheConfiguration where the name for the default cache is 'default', Why another name here?
31
    public static final String DEFAULT_CACHE_NAME = "cdmDefaultCache"; //TODO compare with CacheConfiguration where the name for the default cache is 'default', Why another name here?
32 32

  
33 33
    /**
34 34
     * Constructor which initialises a singleton {@link net.sf.ehcache.CacheManager}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/config/EhCacheConfiguration.java
64 64

  
65 65

  
66 66
    /**
67
     * Returns the default cache configuration.
67
     * Returns the default cache configuration for the cache
68
     * named {@link CdmCacher#DEFAULT_CACHE_NAME "cdmDefaultCache"}
68 69
     *
69 70
     * @return
70 71
     */
......
77 78

  
78 79
        CacheConfiguration cc = new CacheConfiguration(CdmCacher.DEFAULT_CACHE_NAME, 500)
79 80
                .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
81
                .maxEntriesLocalHeap(10) // avoid ehache consuming too much heap
80 82
                .eternal(false)
81 83
                // default ttl and tti set to 2 hours
82 84
                .timeToLiveSeconds(60*60*2)

Also available in: Unified diff