本文整理了Java中org.ehcache.Cache.getRuntimeConfiguration()
方法的一些代码示例,展示了Cache.getRuntimeConfiguration()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.getRuntimeConfiguration()
方法的具体详情如下:
包路径:org.ehcache.Cache
类名称:Cache
方法名:getRuntimeConfiguration
[英]Exposes the org.ehcache.config.CacheRuntimeConfiguration associated with this Cache instance.
[中]公开组织。ehcache。配置。与此缓存实例关联的CacheRuntimeConfiguration。
代码示例来源:origin: ehcache/ehcache3
@Override
public Class<K> getKeyType() {
return cache.getRuntimeConfiguration().getKeyType();
}
代码示例来源:origin: ehcache/ehcache3
@Override
public Class<V> getValueType() {
return cache.getRuntimeConfiguration().getValueType();
}
代码示例来源:origin: ehcache/ehcache3
@Override
public <T> T unwrap(Class<T> clazz) {
return Unwrap.unwrap(clazz, this, cache.getRuntimeConfiguration());
}
代码示例来源:origin: ehcache/ehcache3
@Override
public final ClassLoader getClassLoader() {
ClassLoader classLoader = cacheBinding.getCache().getRuntimeConfiguration().getClassLoader();
return classLoader == null ? ClassLoading.getDefaultClassLoader() : classLoader;
}
代码示例来源:origin: ehcache/ehcache3
@SuppressWarnings("unchecked")
@Exposed
public void put(@Named("key") Object key, @Named("value") Object value) {
Object convertedKey = convert(key, cacheBinding.getCache().getRuntimeConfiguration().getKeyType());
Object convertedValue = convert(value, cacheBinding.getCache().getRuntimeConfiguration().getValueType());
cacheBinding.getCache().put(convertedKey, convertedValue);
}
代码示例来源:origin: ehcache/ehcache3
@SuppressWarnings("unchecked")
@Exposed
public Object get(@Named("key") Object key) {
Object convertedKey = convert(key, cacheBinding.getCache().getRuntimeConfiguration().getKeyType());
return cacheBinding.getCache().get(convertedKey);
}
代码示例来源:origin: ehcache/ehcache3
@SuppressWarnings("unchecked")
@Exposed
public void remove(@Named("key") Object key) {
Object convertedKey = convert(key, cacheBinding.getCache().getRuntimeConfiguration().getKeyType());
cacheBinding.getCache().remove(convertedKey);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testCacheConfigUsage() {
Set<EventType> eventTypeSet = new HashSet<>();
eventTypeSet.add(EventType.CREATED);
eventTypeSet.add(EventType.UPDATED);
CacheEventListenerConfigurationBuilder listenerBuilder = CacheEventListenerConfigurationBuilder
.newEventListenerConfiguration(ListenerObject.class, eventTypeSet).unordered().asynchronous();
final CacheManager manager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("foo",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class, heap(10))
.add(listenerBuilder)
.build()).build(true);
final Collection<?> bar = manager.getCache("foo", Object.class, Object.class).getRuntimeConfiguration().getServiceConfigurations();
assertThat(bar.iterator().next().getClass().toString(), is(ListenerObject.object.toString()));
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testNoClassLoaderSpecified() {
Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
caches.put("foo", new BaseCacheConfiguration<>(Object.class, Object.class, null, null, null, ResourcePoolsHelper.createHeapOnlyPools()));
DefaultConfiguration config = new DefaultConfiguration(caches, null);
final Store.Provider storeProvider = mock(Store.Provider.class);
when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1);
final Store mock = mock(Store.class);
final CacheEventDispatcherFactory cenlProvider = mock(CacheEventDispatcherFactory.class);
final CacheEventDispatcher<Object, Object> cenlServiceMock = mock(CacheEventDispatcher.class);
when(cenlProvider.createCacheEventDispatcher(mock)).thenReturn(cenlServiceMock);
final Collection<Service> services = getServices(storeProvider, cenlProvider);
when(storeProvider
.createStore(ArgumentMatchers.<Store.Configuration>any(), ArgumentMatchers.<ServiceConfiguration[]>any())).thenReturn(mock);
EhcacheManager cacheManager = new EhcacheManager(config, services);
cacheManager.init();
assertSame(ClassLoading.getDefaultClassLoader(), cacheManager.getClassLoader());
assertSame(cacheManager.getClassLoader(), cacheManager.getCache("foo", Object.class, Object.class).getRuntimeConfiguration().getClassLoader());
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testMultiThreadedSyncAsyncNotificationsWithOffheap() throws InterruptedException {
AsynchronousListener asyncListener = new AsynchronousListener();
asyncListener.resetLatchCount(100);
CacheConfiguration<Number, Number> cacheConfiguration = newCacheConfigurationBuilder(Number.class, Number.class,
newResourcePoolsBuilder()
.heap(10L, EntryUnit.ENTRIES).offheap(10, MemoryUnit.MB))
.build();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
.build(true);
Cache<Number, Number> cache = cacheManager.getCache("cache", Number.class, Number.class);
cache.getRuntimeConfiguration().registerCacheEventListener(asyncListener, EventOrdering.UNORDERED, EventFiring.ASYNCHRONOUS, EnumSet
.of(EventType.CREATED, EventType.EXPIRED));
cache.getRuntimeConfiguration().registerCacheEventListener(listener1, EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet
.of(EventType.CREATED, EventType.EXPIRED));
Thread[] operators = new Thread[10];
for (int i = 0; i < 10; i++) {
operators[i] = new Thread(new CachePutOperator(cache, i), "CACHE-PUT-OPERATOR_" + i);
operators[i].start();
}
for (int i = 0; i < 10; i++) {
operators[i].join();
}
cacheManager.close();
assertEquals(100, listener1.created.get());
assertEquals(100, asyncListener.created.get());
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testClusteredSharedResourcePoolUpdation() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Updating CLUSTERED resource is not supported");
sharedCache.getRuntimeConfiguration().updateResourcePools(
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool-a"))
.build()
);
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testUpdateResources() throws Exception {
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10L, EntryUnit.ENTRIES).disk(10, MemoryUnit.MB).build()).build();
try (CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(new CacheManagerPersistenceConfiguration(diskPath.newFolder("myData")))
.withCache("cache", cacheConfiguration).build(true)) {
Cache<Long, String> cache = cacheManager.getCache("cache", Long.class, String.class);
ResourcePoolsBuilder poolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder();
poolsBuilder = poolsBuilder.heap(20L, EntryUnit.ENTRIES);
ResourcePools pools = poolsBuilder.build();
cache.getRuntimeConfiguration().updateResourcePools(pools);
assertThat(cache.getRuntimeConfiguration().getResourcePools()
.getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L));
pools = poolsBuilder.build();
cache.getRuntimeConfiguration().updateResourcePools(pools);
assertThat(cache.getRuntimeConfiguration().getResourcePools()
.getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testClusteredDedicatedResourcePoolUpdation() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Updating CLUSTERED resource is not supported");
dedicatedCache.getRuntimeConfiguration().updateResourcePools(
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB))
.build()
);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testUpdateFailureDoesNotUpdate() {
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10L, EntryUnit.ENTRIES).build()).build();
try(CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("cache", cacheConfiguration).build(true)) {
Cache<Long, String> cache = cacheManager.getCache("cache", Long.class, String.class);
ResourcePoolsBuilder poolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder();
poolsBuilder = poolsBuilder.heap(20L, EntryUnit.ENTRIES).disk(10, MemoryUnit.MB);
ResourcePools pools = poolsBuilder.build();
try {
cache.getRuntimeConfiguration().updateResourcePools(pools);
fail("We expect illegal arguments");
} catch (IllegalArgumentException iae) {
// expected
assertThat(iae.getMessage(), is("Pools to be updated cannot contain previously undefined resources pools"));
}
assertThat(cache.getRuntimeConfiguration().getResourcePools()
.getPoolForResource(ResourceType.Core.HEAP).getSize(), is(10L));
}
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testEventOrderForUpdateThatTriggersEviction () {
CacheConfiguration<Long, SerializableObject> cacheConfiguration = newCacheConfigurationBuilder(Long.class, SerializableObject.class,
newResourcePoolsBuilder()
.heap(1L, EntryUnit.ENTRIES).offheap(1l, MemoryUnit.MB).build()).build();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
.build(true);
Cache<Long, SerializableObject> cache = cacheManager.getCache("cache", Long.class, SerializableObject.class);
cache.getRuntimeConfiguration().registerCacheEventListener(listener1, EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet
.of(EventType.EVICTED, EventType.CREATED, EventType.UPDATED, EventType.REMOVED));
SerializableObject object1 = new SerializableObject(0xAAE60); // 700 KB
SerializableObject object2 = new SerializableObject(0xDBBA0); // 900 KB
cache.put(1L, object1);
cache.put(1L, object2);
assertThat(listener1.eventTypeHashMap.get(EventType.EVICTED), lessThan(listener1.eventTypeHashMap.get(EventType.CREATED)));
cacheManager.close();
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void registerListenerAtRuntime() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.heap(10L)))
.build(true);
Cache<Long, String> cache = cacheManager.getCache("cache", Long.class, String.class);
// tag::registerListenerAtRuntime[]
ListenerObject listener = new ListenerObject(); // <1>
cache.getRuntimeConfiguration().registerCacheEventListener(listener, EventOrdering.ORDERED,
EventFiring.ASYNCHRONOUS, EnumSet.of(EventType.CREATED, EventType.REMOVED)); // <2>
cache.put(1L, "one");
cache.put(2L, "two");
cache.remove(1L);
cache.remove(2L);
cache.getRuntimeConfiguration().deregisterCacheEventListener(listener); // <3>
cache.put(1L, "one again");
cache.remove(1L);
// end::registerListenerAtRuntime[]
cacheManager.close();
}
代码示例来源:origin: ehcache/ehcache3
private void performActualTest(Cache<Long, String> testCache) {
final List<Long> expiredKeys = new CopyOnWriteArrayList<>();
testCache.getRuntimeConfiguration().registerCacheEventListener(event -> expiredKeys.add(event.getKey()), EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet.of(EventType.EXPIRED));
testCache.put(1L, "one");
testCache.put(2L, "two");
testCache.put(3L, "three");
testCache.put(4L, "four");
testCache.put(5L, "five");
testCache.put(6L, "six");
testCache.put(7L, "seven");
testCache.get(1L);
testCache.get(2L);
testCache.get(3L);
testCache.get(4L);
testCache.get(5L);
testTimeSource.setTimeMillis(1100);
testCache.get(1L);
testCache.get(2L);
testCache.get(3L);
testCache.get(4L);
testCache.get(5L);
testCache.get(6L);
testCache.get(7L);
assertThat(expiredKeys, containsInAnyOrder(1L, 2L, 3L, 4L, 5L, 6L, 7L));
}
代码示例来源:origin: ehcache/ehcache3
@SuppressWarnings("unchecked")
@Test
public void testAddingCacheLoaderWriterConfigurationAtCacheLevel() {
CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (MyLoader.class);
CacheManager cacheManager = cacheManagerBuilder.build(true);
final Cache<Long, String> cache = cacheManager.createCache("cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100))
.add(new DefaultCacheLoaderWriterConfiguration(klazz))
.build());
Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration()
.getServiceConfigurations();
assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(DefaultCacheLoaderWriterConfiguration.class)));
cacheManager.close();
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testAddingCacheEventListenerConfigurationAtCacheLevel() {
CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheEventListenerConfiguration cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
.newEventListenerConfiguration(ListenerObject.class, EventType.CREATED).unordered().asynchronous().build();
CacheManager cacheManager = cacheManagerBuilder.build(true);
final Cache<Long, String> cache = cacheManager.createCache("cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100))
.add(cacheEventListenerConfiguration)
.build());
Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration()
.getServiceConfigurations();
assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(DefaultCacheEventListenerConfiguration.class)));
cacheManager.close();
}
代码示例来源:origin: ehcache/ehcache3
@SuppressWarnings("unchecked")
@Test
public void testAddingWriteBehindConfigurationAtCacheLevel() {
CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
WriteBehindConfiguration writeBehindConfiguration = WriteBehindConfigurationBuilder.newBatchedWriteBehindConfiguration(Long.MAX_VALUE, SECONDS, 1)
.concurrencyLevel(3)
.queueSize(10)
.build();
Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (SampleLoaderWriter.class);
CacheManager cacheManager = cacheManagerBuilder.build(true);
final Cache<Long, String> cache = cacheManager.createCache("cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100))
.add(writeBehindConfiguration)
.add(new DefaultCacheLoaderWriterConfiguration(klazz))
.build());
Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration()
.getServiceConfigurations();
assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(WriteBehindConfiguration.class)));
cacheManager.close();
}
内容来源于网络,如有侵权,请联系作者删除!