本文整理汇总了Java中javax.cache.configuration.MutableConfiguration.setCacheLoaderFactory方法的典型用法代码示例。如果您正苦于以下问题:Java MutableConfiguration.setCacheLoaderFactory方法的具体用法?Java MutableConfiguration.setCacheLoaderFactory怎么用?Java MutableConfiguration.setCacheLoaderFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.cache.configuration.MutableConfiguration
的用法示例。
在下文中一共展示了MutableConfiguration.setCacheLoaderFactory方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreateCacheConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
Configuration getOrCreateCacheConfiguration() {
if (configuration.getCacheConfiguration() != null) {
return configuration.getCacheConfiguration();
}
MutableConfiguration mutableConfiguration = new MutableConfiguration();
if (configuration.getCacheLoaderFactory() != null) {
mutableConfiguration.setCacheLoaderFactory(configuration.getCacheLoaderFactory());
}
if (configuration.getCacheWriterFactory() != null) {
mutableConfiguration.setCacheWriterFactory(configuration.getCacheWriterFactory());
}
if (configuration.getExpiryPolicyFactory() != null) {
mutableConfiguration.setExpiryPolicyFactory(configuration.getExpiryPolicyFactory());
}
mutableConfiguration.setManagementEnabled(configuration.isManagementEnabled());
mutableConfiguration.setStatisticsEnabled(configuration.isStatisticsEnabled());
mutableConfiguration.setReadThrough(configuration.isReadThrough());
mutableConfiguration.setStoreByValue(configuration.isStoreByValue());
return mutableConfiguration;
}
示例2: testLoaderConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testLoaderConfiguration() throws Exception {
final AtomicBoolean loaderCreated = new AtomicBoolean(false);
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class).setReadThrough(true);
configuration.setCacheLoaderFactory(() -> {
loaderCreated.set(true);
return new TestCacheLoader();
});
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
Cache<String, String> cache = cacheManager.createCache("cache", configuration);
assertThat(loaderCreated.get(), is(true));
cache.putIfAbsent("42", "The Answer");
TestCacheLoader.seen.clear();
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(Collections.singleton("42"), true, future);
future.get();
assertThat(TestCacheLoader.seen, contains("42"));
}
示例3: onBeforeEachTest
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Establish the {@link javax.cache.CacheManager} and {@link javax.cache.Cache} for a test.
*/
@Before
public void onBeforeEachTest() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
cacheLoaderServer = new CacheLoaderServer<String, String>(10000);
cacheLoaderServer.open();
//establish the CacheManager for the tests
cacheManager = Caching.getCachingProvider().getCacheManager();
//establish a CacheLoaderClient that a Cache can use for loading entries
//(via the CacheLoaderServer)
CacheLoaderClient<String, String> cacheLoader =
new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());
//establish a Cache Configuration that uses a CacheLoader (no Read-Through)
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class);
configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
configuration.setReadThrough(false);
//configure the cache
cacheManager.createCache("cache-loader-test", configuration);
cache = cacheManager.getCache("cache-loader-test", String.class, String.class);
}
示例4: onBeforeEachTest
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Establish the {@link CacheManager} and {@link Cache} for a test.
*/
@Before
public void onBeforeEachTest() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
cacheLoaderServer = new CacheLoaderServer<String, String>(10000);
cacheLoaderServer.open();
//establish the CacheManager for the tests
cacheManager = Caching.getCachingProvider().getCacheManager();
//establish a CacheLoaderClient that a Cache can use for loading entries
//(via the CacheLoaderServer)
CacheLoaderClient<String, String> cacheLoader =
new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());
//establish a Cache Configuration that uses a CacheLoader and Read-Through
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class);
configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
configuration.setReadThrough(true);
//configure the cache
cacheManager.createCache("cache-loader-test", configuration);
cache = cacheManager.getCache("cache-loader-test", String.class, String.class);
}
示例5: invokeAllReadThroughEnabledGetOnNonExistentEntry
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeAllReadThroughEnabledGetOnNonExistentEntry() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
// this cacheLoader just returns the key as the value.
RecordingCacheLoader<Integer> recordingCacheLoader = new RecordingCacheLoader<>();
CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicy));
config.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(recordingCacheLoader));
config.setReadThrough(true);
Cache<Integer, Integer> cache = getCacheManager().createCache("test-1", config);
final Integer INITIAL_KEY = 123;
final Integer MAX_KEY_VALUE = INITIAL_KEY + 4;
// set keys to read through
Set<Integer> keys = new HashSet<>();
for (int key = INITIAL_KEY; key <= MAX_KEY_VALUE; key++) {
keys.add(key);
}
// verify read-through of getValue of non-existent entries
cache.invokeAll(keys, new GetEntryProcessor<Integer, Integer>());
assertTrue(expiryPolicy.getCreationCount() >= keys.size());
assertThat(expiryPolicy.getAccessCount(), is(0));
assertThat(expiryPolicy.getUpdatedCount(), is(0));
expiryPolicy.resetCount();
}
示例6: test107LoaderOverriddenByEhcacheTemplateLoaderWriter
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void test107LoaderOverriddenByEhcacheTemplateLoaderWriter() throws Exception {
final AtomicBoolean loaderFactoryInvoked = new AtomicBoolean(false);
final DumbCacheLoader product2CacheLoader = new DumbCacheLoader();
MutableConfiguration<Long, Product> product2Configuration = new MutableConfiguration<>();
product2Configuration.setTypes(Long.class, Product.class).setReadThrough(true);
product2Configuration.setCacheLoaderFactory(() -> {
loaderFactoryInvoked.set(true);
return product2CacheLoader;
});
Cache<Long, Product> productCache2 = cacheManager.createCache("productCache2", product2Configuration);
assertThat(loaderFactoryInvoked.get(), is(false));
Product product = productCache2.get(124L);
assertThat(product.getId(), is(124L));
assertThat(ProductCacheLoaderWriter.seen, hasItem(124L));
assertThat(product2CacheLoader.seen, is(empty()));
CompletionListenerFuture future = new CompletionListenerFuture();
productCache2.loadAll(Collections.singleton(42L), false, future);
future.get();
assertThat(ProductCacheLoaderWriter.seen, hasItem(42L));
assertThat(product2CacheLoader.seen, is(empty()));
}
示例7: jsr107LoaderInitAlways
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void jsr107LoaderInitAlways() {
CacheLoader<Object, Object> loader = mock(CacheLoader.class);
MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>();
RecordingFactory<CacheLoader<Object, Object>> factory = factoryOf(loader);
configuration.setCacheLoaderFactory(factory);
ConfigurationMerger.ConfigHolder<Object, Object> configHolder = merger.mergeConfigurations("cache", configuration);
assertThat(factory.called, is(true));
assertThat(configHolder.cacheResources.getCacheLoaderWriter(), notNullValue());
assertThat(configHolder.useEhcacheLoaderWriter, is(false));
}
示例8: getConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
private MutableConfiguration<Long, String> getConfiguration(final boolean readThrough, final CacheLoader<Long, String> cacheLoader,
final boolean writeThrough, final CacheWriter<Long, String> cacheWriter) {
MutableConfiguration<Long, String> config = new MutableConfiguration<>();
config.setTypes(Long.class, String.class);
config.setReadThrough(readThrough);
config.setCacheLoaderFactory(() -> cacheLoader);
config.setWriteThrough(writeThrough);
config.setCacheWriterFactory(() -> cacheWriter);
return config;
}
示例9: onBeforeEachTest
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Establish the {@link javax.cache.CacheManager} and {@link Cache} for a test.
*/
@Before
public void onBeforeEachTest() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
recordingCacheLoader = new RecordingCacheLoader<String>();
cacheLoaderServer = new CacheLoaderServer<String, String>(10000, recordingCacheLoader);
cacheLoaderServer.open();
// establish and open a CacheWriterServer to handle cache
// cache loading requests from a CacheWriterClient
recordingCacheWriter = new RecordingCacheWriter<>();
cacheWriterServer = new CacheWriterServer<>(10001, recordingCacheWriter);
cacheWriterServer.open();
//establish the CacheManager for the tests
cacheManager = Caching.getCachingProvider().getCacheManager();
//establish a CacheLoaderClient that a Cache can use for loading entries
//(via the CacheLoaderServer)
CacheLoaderClient<String, String> cacheLoader =
new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());
// establish a CacheWriterClient that a Cache can use for writing/deleting entries
// (via the CacheWriterServer)
CacheWriterClient<String, String> cacheWriter = new CacheWriterClient<>(cacheWriterServer.getInetAddress(),
cacheWriterServer.getPort());
//establish a Cache Configuration that uses a CacheLoader and Read-Through
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class);
configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
configuration.setReadThrough(true);
configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(cacheWriter));
configuration.setWriteThrough(true);
//configure the cache
cacheManager.createCache("cache-loader-writer-test", configuration);
cache = cacheManager.getCache("cache-loader-writer-test", String.class, String.class);
}
示例10: onBeforeEachTest
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Establish the {@link javax.cache.CacheManager} and {@link javax.cache.Cache} for a test.
*/
@Before
public void onBeforeEachTest() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
cacheLoaderServer = new CacheLoaderServer<String, String>(10000);
cacheLoaderServer.open();
//establish the CacheManager for the tests
cacheManager = Caching.getCachingProvider().getCacheManager();
//establish a CacheLoaderClient that a Cache can use for loading entries
//(via the CacheLoaderServer)
CacheLoaderClient<String, String> cacheLoader =
new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());
//establish a Cache Configuration that uses a CacheLoader, Read-Through and Expiry
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class);
configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
configuration.setReadThrough(true);
configuration.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnAccessPolicy.class));
//configure the cache
cacheManager.createCache("cache-loader-test", configuration);
cache = cacheManager.getCache("cache-loader-test", String.class, String.class);
}
示例11: invokeGetValueWithReadThroughForNonExistentEntryShouldCallGetExpiryForCreatedEntry
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeGetValueWithReadThroughForNonExistentEntryShouldCallGetExpiryForCreatedEntry() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
// this cacheLoader just returns the key as the value.
RecordingCacheLoader<Integer> recordingCacheLoader = new RecordingCacheLoader<>();
try (CacheLoaderServer<Integer, Integer> cacheLoaderServer = new CacheLoaderServer<>(10000, recordingCacheLoader)) {
cacheLoaderServer.open();
//establish a CacheLoaderClient that a Cache can use for loading entries
//(via the CacheLoaderServer)
CacheLoaderClient<Integer, Integer> cacheLoader =
new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());
CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
expiryPolicyServer.setExpiryPolicy(expiryPolicy);
MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient));
config.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
config.setReadThrough(true);
Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
final Integer key = 123;
final Integer recordingCacheLoaderValue = key;
// verify create when read through is enabled and entry was non-existent in cache.
Integer resultValue = cache.invoke(key, new GetEntryProcessor<Integer, Integer>());
assertEquals(recordingCacheLoaderValue, resultValue);
assertTrue(recordingCacheLoader.hasLoaded(key));
assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(1));
assertThat(expiryPolicy.getAccessCount(), is(0));
assertThat(expiryPolicy.getUpdatedCount(), is(0));
closeTestCache();
}
}
示例12: testInvoke
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testInvoke()
{
final CacheLoader<String, Integer> cacheLoader = new CacheLoader<String, Integer>()
{
@Override
public Integer load(String key)
throws CacheLoaderException
{
return Integer.valueOf(key);
}
@Override
public Map<String, Integer> loadAll(Iterable<? extends String> keys)
throws CacheLoaderException
{
throw new UnsupportedOperationException("Not supported yet.");
}
};
final EntryProcessor<String, Integer, Boolean> entryProcessor = new EntryProcessor<String, Integer, Boolean>()
{
@Override
public Boolean process(MutableEntry<String, Integer> entry, Object... arguments)
throws EntryProcessorException
{
assertTrue(entry.exists());
assertEquals(Integer.valueOf(1), entry.getValue());
entry.setValue(2);
assertEquals(Integer.valueOf(2), entry.getValue());
entry.remove();
assertFalse(entry.exists());
return Boolean.TRUE;
}
};
MutableConfiguration<String, Integer> custom = new MutableConfiguration<>(configuration);
custom.setReadThrough(true);
custom.setCacheLoaderFactory
(
new Factory<CacheLoader<String, Integer>>()
{
@Override
public CacheLoader<String, Integer> create()
{
return cacheLoader;
}
}
);
Cache<String, Integer> invokingCache = cacheManager.createCache("invokingCache", custom);
assertTrue(invokingCache.invoke("1", entryProcessor));
assertFalse(invokingCache.containsKey("1"));
}
示例13: invokeAllReadThroughEnabledGetOnNonExistentEntry
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeAllReadThroughEnabledGetOnNonExistentEntry() throws IOException {
//establish and open a CacheLoaderServer to handle cache
//cache loading requests from a CacheLoaderClient
// this cacheLoader just returns the key as the value.
RecordingCacheLoader<Integer> recordingCacheLoader = new RecordingCacheLoader<>();
try (CacheLoaderServer<Integer, Integer> cacheLoaderServer = new CacheLoaderServer<>(10000, recordingCacheLoader)) {
cacheLoaderServer.open();
//establish a CacheLoaderClient that a Cache can use for loading entries
//(via the CacheLoaderServer)
CacheLoaderClient<Integer, Integer> cacheLoader =
new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());
CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
expiryPolicyServer.setExpiryPolicy(expiryPolicy);
MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient));
config.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
config.setReadThrough(true);
Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
final Integer INITIAL_KEY = 123;
final Integer MAX_KEY_VALUE = INITIAL_KEY + 4;
// set keys to read through
Set<Integer> keys = new HashSet<>();
for (int key = INITIAL_KEY; key <= MAX_KEY_VALUE; key++) {
keys.add(key);
}
// verify read-through of getValue of non-existent entries
cache.invokeAll(keys, new GetEntryProcessor<Integer, Integer>());
assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(keys.size()));
assertThat(expiryPolicy.getAccessCount(), is(0));
assertThat(expiryPolicy.getUpdatedCount(), is(0));
expiryPolicy.resetCount();
closeTestCache();
}
}