Search in sources :

Example 1 with PersistentCacheManager

use of org.ehcache.PersistentCacheManager in project cxf by apache.

the class EHCacheXKMSClientCache method close.

public synchronized void close() {
    if (cacheManager.getStatus() == Status.AVAILABLE) {
        cacheManager.removeCache(cacheKey);
        cacheManager.close();
        if (!persistent && cacheManager instanceof PersistentCacheManager) {
            try {
                ((PersistentCacheManager) cacheManager).destroy();
            } catch (CachePersistenceException e) {
                LOG.debug("Error in shutting down persistent cache", e);
            }
            // destroy above
            if (diskstorePath != null) {
                File file = diskstorePath.toFile();
                if (file.exists() && file.canWrite()) {
                    file.delete();
                }
            }
        }
        if (bus != null) {
            bus.getExtension(BusLifeCycleManager.class).unregisterLifeCycleListener(this);
        }
    }
}
Also used : PersistentCacheManager(org.ehcache.PersistentCacheManager) BusLifeCycleManager(org.apache.cxf.buslifecycle.BusLifeCycleManager) CachePersistenceException(org.ehcache.CachePersistenceException) File(java.io.File)

Example 2 with PersistentCacheManager

use of org.ehcache.PersistentCacheManager in project CzechIdMng by bcvsolutions.

the class ClusteredEhCacheConfiguration method ehCacheManager.

/**
 * Defines clustered {@link CacheManager} using Terracotta server.
 *
 * @param terracotaUrl a list of IP addresses with ports (IP_ADDR:PORT)
 * @param terracotaResourceName name of server resource to connect
 * @param terracotaResourcePoolName name od server resource pool name
 * @param terracotaResourcePoolSize size of server resource pool in MB
 * @param idMCacheConfigurations a list of {@link IdMCacheConfiguration} defined in container
 * @return CacheManager with distributed capabilities
 */
@Bean
@Qualifier("jCacheManager")
@ConditionalOnProperty(value = TERRACOTA_URL_PROPERTY)
@ConditionalOnMissingBean
public CacheManager ehCacheManager(@Value("${" + TERRACOTA_URL_PROPERTY + "}") String terracotaUrl, @Value("${" + TERRACOTA_RESOURCE_NAME_PROPERTY + "}") String terracotaResourceName, @Value("${" + TERRACOTA_RESOURCE_POOL_NAME_PROPERTY + "}") String terracotaResourcePoolName, @Value("${" + TERRACOTA_RESOURCE_POOL_SIZE_PROPERTY + "}") int terracotaResourcePoolSize, @Autowired List<IdMCacheConfiguration> idMCacheConfigurations) {
    CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder().with(ClusteringServiceConfigurationBuilder.cluster(parseServerAddresses(terracotaUrl), "default").autoCreate(server -> server.defaultServerResource(terracotaResourceName).resourcePool(terracotaResourcePoolName, terracotaResourcePoolSize, MemoryUnit.MB, terracotaResourceName))).withSerializer(CacheObjectWrapper.class, CacheWrapperSerializer.class).withSerializer(SerializableCacheObjectWrapper.class, SerializableCacheWrapperSerializer.class);
    PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
    // create caches using IdMCacheConfiguration instances
    if (!CollectionUtils.isEmpty(idMCacheConfigurations)) {
        for (IdMCacheConfiguration config : idMCacheConfigurations) {
            cacheManager.createCache(config.getCacheName(), toConcreteConfiguration(config, terracotaResourcePoolName));
        }
    }
    // get CacheManager (Jcache) with above updated configuration
    final EhcacheCachingProvider ehcacheCachingProvider = (EhcacheCachingProvider) Caching.getCachingProvider();
    return ehcacheCachingProvider.getCacheManager(ehcacheCachingProvider.getDefaultURI(), cacheManager.getRuntimeConfiguration());
}
Also used : Arrays(java.util.Arrays) ExpiryPolicyBuilder(org.ehcache.config.builders.ExpiryPolicyBuilder) ResourcePoolsBuilder(org.ehcache.config.builders.ResourcePoolsBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) CacheConfiguration(org.ehcache.config.CacheConfiguration) Value(org.springframework.beans.factory.annotation.Value) ClusteringServiceConfigurationBuilder(org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Order(org.springframework.core.annotation.Order) MemoryUnit(org.ehcache.config.units.MemoryUnit) SerializableCacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.SerializableCacheObjectWrapper) CacheManagerBuilder(org.ehcache.config.builders.CacheManagerBuilder) Caching(javax.cache.Caching) IdMCacheConfiguration(eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration) PersistentCacheManager(org.ehcache.PersistentCacheManager) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ClusteredResourcePoolBuilder(org.ehcache.clustered.client.config.builders.ClusteredResourcePoolBuilder) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) CacheConfigurationBuilder(org.ehcache.config.builders.CacheConfigurationBuilder) CollectionUtils(org.springframework.util.CollectionUtils) CacheManager(javax.cache.CacheManager) Bean(org.springframework.context.annotation.Bean) CacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.CacheObjectWrapper) SerializableCacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.SerializableCacheObjectWrapper) CacheObjectWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.CacheObjectWrapper) PersistentCacheManager(org.ehcache.PersistentCacheManager) IdMCacheConfiguration(eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

PersistentCacheManager (org.ehcache.PersistentCacheManager)2 IdMCacheConfiguration (eu.bcvsolutions.idm.core.api.config.cache.IdMCacheConfiguration)1 CacheObjectWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.CacheObjectWrapper)1 SerializableCacheObjectWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.SerializableCacheObjectWrapper)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CacheManager (javax.cache.CacheManager)1 Caching (javax.cache.Caching)1 BusLifeCycleManager (org.apache.cxf.buslifecycle.BusLifeCycleManager)1 CachePersistenceException (org.ehcache.CachePersistenceException)1 ClusteredResourcePoolBuilder (org.ehcache.clustered.client.config.builders.ClusteredResourcePoolBuilder)1 ClusteringServiceConfigurationBuilder (org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder)1 CacheConfiguration (org.ehcache.config.CacheConfiguration)1 CacheConfigurationBuilder (org.ehcache.config.builders.CacheConfigurationBuilder)1 CacheManagerBuilder (org.ehcache.config.builders.CacheManagerBuilder)1 ExpiryPolicyBuilder (org.ehcache.config.builders.ExpiryPolicyBuilder)1 ResourcePoolsBuilder (org.ehcache.config.builders.ResourcePoolsBuilder)1