Create replicated cache at runtime

I want to create replicated cache at runtime without configuration.xml
When I use next configuration for cache:

<cache name="pcid"
       maxEntriesLocalHeap="10000"
       maxElementsOnDisk="0"
       overflowToDisk="false"
       eternal="false"
       timeToIdleSeconds="600"
       memoryStoreEvictionPolicy="LRU">
       <cacheEventListenerFactory
               class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
               properties="replicateAsynchronously=false"/>
    <!-- RMI Cache bootstrap -->
    <bootstrapCacheLoaderFactory
            class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
            properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
            propertySeparator="," />
</cache>

all work perfectly.

If I create cache manually:

RMICacheReplicatorFactory factory = new RMICacheReplicatorFactory();
Properties properties = new Properties();
properties.put("replicateAsynchronously","false");
CacheEventListener listener = factory.createCacheEventListener(properties);

RMIBootstrapCacheLoaderFactory bootstrapCacheLoaderFactory = new RMIBootstrapCacheLoaderFactory();
Properties properties2 = new Properties();
properties2.put("bootstrapAsynchronously", "true");
properties2.put("maximumChunkSizeBytes", "5000000");
RMIBootstrapCacheLoader rmiBootstrapCacheLoader = bootstrapCacheLoaderFactory.createBootstrapCacheLoader(properties2);

Cache cache = new Cache(
        "xxx",
        1000,
        MemoryStoreEvictionPolicy.LRU,
        false,
        null,
        false,
        180,
        0,
        false,
        0,
        null);
cache.getCacheEventNotificationService().registerListener(listener);
cache.setBootstrapCacheLoader(rmiBootstrapCacheLoader);
manager.addCache(cache);

then replication doesn’t work

P.S. EhCache 2.10.2

Source: java

Leave a Reply