
org.ehcache.jsr107.Eh107Configuration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache-107 Show documentation
Show all versions of ehcache-107 Show documentation
The JSR-107 compatibility module of Ehcache 3
The newest version!
/*
* Copyright Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ehcache.jsr107;
import org.ehcache.config.Builder;
import org.ehcache.config.CacheConfiguration;
import org.ehcache.impl.config.copy.DefaultCopierConfiguration;
import org.ehcache.javadoc.PublicApi;
import javax.cache.configuration.CacheEntryListenerConfiguration;
import javax.cache.configuration.Configuration;
import static org.ehcache.core.spi.service.ServiceUtils.findAmongst;
/**
* Abstract {@code Configuration} implementation that enables building a JSR-107 compatible configuration from
* a native Ehcache {@link CacheConfiguration}.
*
* @param the key type
* @param the value type
*/
@PublicApi
public abstract class Eh107Configuration implements Configuration {
private static final long serialVersionUID = 7324956960962454439L;
/**
* Creates a new JSR-107 {@code Configuration} from the provided {@link CacheConfiguration}.
*
* @param ehcacheConfig the native Ehcache configuration
* @param the key type
* @param the value type
*
* @return a JSR-107 configuration
*/
public static Configuration fromEhcacheCacheConfiguration(CacheConfiguration ehcacheConfig) {
return new Eh107ConfigurationWrapper<>(ehcacheConfig);
}
/**
* Creates a new JSR-107 {@code Configuration} from the provided {@link CacheConfiguration} obtained through a
* {@link Builder}.
*
* @param ehcacheConfigBuilder the native Ehcache configuration through a builder
* @param the key type
* @param the value type
*
* @return a JSR-107 configuration
*/
public static Configuration fromEhcacheCacheConfiguration(Builder extends CacheConfiguration> ehcacheConfigBuilder) {
return new Eh107ConfigurationWrapper<>(ehcacheConfigBuilder.build());
}
/**
* Enables to unwrap the underlying configuration.
*
* @param clazz the unwrap target class
* @param the unwrap target type
*
* @return unwrapped type
*
* @throws IllegalArgumentException if the type cannot be unwrapped in the target type
*/
public abstract T unwrap(Class clazz);
abstract boolean isReadThrough();
abstract boolean isWriteThrough();
abstract boolean isStatisticsEnabled();
abstract void setStatisticsEnabled(boolean enabled);
abstract boolean isManagementEnabled();
abstract void setManagementEnabled(boolean enabled);
abstract void addCacheEntryListenerConfiguration(CacheEntryListenerConfiguration cacheEntryListenerConfiguration);
abstract void removeCacheEntryListenerConfiguration(CacheEntryListenerConfiguration cacheEntryListenerConfiguration);
static class Eh107ConfigurationWrapper implements Configuration {
private static final long serialVersionUID = -142083549674760400L;
private final transient CacheConfiguration cacheConfiguration;
private Eh107ConfigurationWrapper(CacheConfiguration cacheConfiguration) {
this.cacheConfiguration = cacheConfiguration;
}
CacheConfiguration getCacheConfiguration() {
return cacheConfiguration;
}
@Override
public Class getKeyType() {
return cacheConfiguration.getKeyType();
}
@Override
public Class getValueType() {
return cacheConfiguration.getValueType();
}
@Override
public boolean isStoreByValue() {
return !findAmongst(DefaultCopierConfiguration.class, cacheConfiguration.getServiceConfigurations()).isEmpty();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy