本文整理汇总了Java中javax.cache.configuration.FactoryBuilder.factoryOf方法的典型用法代码示例。如果您正苦于以下问题:Java FactoryBuilder.factoryOf方法的具体用法?Java FactoryBuilder.factoryOf怎么用?Java FactoryBuilder.factoryOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.cache.configuration.FactoryBuilder
的用法示例。
在下文中一共展示了FactoryBuilder.factoryOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: produces
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Produces
@CustomCache
public Cache<Integer, Person> produces() {
CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<Integer, Person> cache = manager.getCache(CACHE_NAME, Integer.class, Person.class);
if(cache == null) {
MutableConfiguration<Integer, Person> configuration = new MutableConfiguration<>();
configuration.setTypes(Integer.class, Person.class);
configuration.setStatisticsEnabled(true);
cache = manager.createCache(CACHE_NAME, configuration);
CacheEntryListenerConfiguration<Integer, Person> listenersConfiguration
= new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(CacheModificationListener.class), null, false, true);
cache.registerCacheEntryListener(listenersConfiguration);
}
return cache;
}
示例2: produce
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Produces
@LimitedCache
public Cache<Integer, Person> produce() {
CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<Integer, Person> cache = manager.getCache(CACHE_NAME, Integer.class, Person.class);
if(cache == null) {
MutableConfiguration<Integer, Person> configuration = new MutableConfiguration<>();
configuration.setTypes(Integer.class, Person.class);
configuration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));
cache = manager.createCache(CACHE_NAME, configuration);
CacheEntryListenerConfiguration<Integer, Person> listenersConfiguration = new MutableCacheEntryListenerConfiguration<>(
FactoryBuilder.factoryOf(CacheModificationListener.class), null, false, true);
cache.registerCacheEntryListener(listenersConfiguration);
}
return cache;
}
示例3: setup
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Setup
public void setup() {
results = targetInstance.getList(name);
listeners = targetInstance.getList(name + "listeners");
cache = CacheUtils.getCache(targetInstance, name);
listener = new ICacheEntryListener<Integer, Long>();
filter = new ICacheEntryEventFilter<Integer, Long>();
threadsRemaining.set(threadCount);
CacheEntryListenerConfiguration<Integer, Long> config = new MutableCacheEntryListenerConfiguration<Integer, Long>(
FactoryBuilder.factoryOf(listener),
FactoryBuilder.factoryOf(filter),
false, syncEvents);
cache.registerCacheEntryListener(config);
}
示例4: extraSetup
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Override
protected MutableConfiguration<Integer, String> extraSetup(MutableConfiguration<Integer, String> cfg) {
// cfg.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 5)));
cacheEntryListenerServer = new CacheEntryListenerServer<>(10011, Integer.class, String.class);
try {
cacheEntryListenerServer.open();
} catch (IOException e) {
throw new RuntimeException(e);
}
listener = new RecordingListener<>();
cacheEntryListenerServer.addCacheEventListener(listener);
CacheEntryListenerClient<Integer, String> clientListener =
new CacheEntryListenerClient<>(cacheEntryListenerServer.getInetAddress(), cacheEntryListenerServer.getPort());
boolean _isSynchronous = false;
listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(
FactoryBuilder.factoryOf(clientListener), null, true, _isSynchronous);
return cfg.addCacheEntryListenerConfiguration(listenerConfiguration);
}
示例5: extraSetup
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Override
protected MutableConfiguration<Long, String> extraSetup(MutableConfiguration<Long, String> configuration) {
cacheEntryListenerServer = new CacheEntryListenerServer<Long, String>(10011, Long.class, String.class);
try {
cacheEntryListenerServer.open();
} catch (IOException e) {
e.printStackTrace();
}
//establish and open a CacheEntryListenerServer to handle cache
//cache entry events from a CacheEntryListenerClient
listener = new MyCacheEntryListener<Long, String>();
cacheEntryListenerServer.addCacheEventListener(listener);
//establish a CacheEntryListenerClient that a Cache can use for CacheEntryListening
//(via the CacheEntryListenerServer)
CacheEntryListenerClient<Long, String> clientListener =
new CacheEntryListenerClient<>(cacheEntryListenerServer.getInetAddress(), cacheEntryListenerServer.getPort());
listenerConfiguration = new MutableCacheEntryListenerConfiguration<Long, String>(FactoryBuilder.factoryOf(clientListener), null, true, true);
return configuration.addCacheEntryListenerConfiguration(listenerConfiguration);
}
示例6: testDeregistration
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Test
public void testDeregistration() {
assertEquals(1, getConfigurationCacheEntryListenerConfigurationSize(cache));
MyCacheEntryListener secondListener = new MyCacheEntryListener<Long, String>();
MutableCacheEntryListenerConfiguration<Long,
String> secondListenerConfiguration = new
MutableCacheEntryListenerConfiguration(FactoryBuilder.factoryOf(secondListener), null, false, true);
cache.registerCacheEntryListener(secondListenerConfiguration);
assertEquals(2, getConfigurationCacheEntryListenerConfigurationSize(cache));
cache.deregisterCacheEntryListener(secondListenerConfiguration);
assertEquals(1, getConfigurationCacheEntryListenerConfigurationSize(cache));
//no effect if called after it has been removed
cache.deregisterCacheEntryListener(secondListenerConfiguration);
assertEquals(1, getConfigurationCacheEntryListenerConfigurationSize(cache));
//Deregister the listener registered at configuration time
cache.deregisterCacheEntryListener(listenerConfiguration);
assertEquals(0, getConfigurationCacheEntryListenerConfigurationSize(cache));
}
示例7: testExpiration
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Test
public void testExpiration() throws InterruptedException, IllegalArgumentException, URISyntaxException, FailedToStartRedisException, IOException {
RedisProcess runner = new RedisRunner()
.nosave()
.randomDir()
.port(6311)
.run();
MutableConfiguration<String, String> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
config.setStoreByValue(true);
URI configUri = getClass().getResource("redisson-jcache.json").toURI();
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager(configUri, null)
.createCache("test", config);
CountDownLatch latch = new CountDownLatch(1);
String key = "123";
ExpiredListener clientListener = new ExpiredListener(latch, key, "90");
MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration =
new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(clientListener), null, true, true);
cache.registerCacheEntryListener(listenerConfiguration);
cache.put(key, "90");
Assert.assertNotNull(cache.get(key));
latch.await();
Assert.assertNull(cache.get(key));
cache.close();
runner.stop();
}
示例8: registerListeners
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
public static void registerListeners() throws ClassNotFoundException {
if (isDone) {
return;
}
ApplicationContext context = ApplicationContextHolder.getContext();
NamedCacheProvider cacheProvider = context.getBean(NamedCacheProvider.class);
if (cacheProvider.isCacheEnabled()) {
// first let's ensure that we process at least well-known DXA caches
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AssignableTypeFilter(SimpleCacheWrapper.class));
for (BeanDefinition beanDefinition : scanner.findCandidateComponents("com.sdl")) {
Class<?> aClass = forName(beanDefinition.getBeanClassName(), getDefaultClassLoader());
SimpleCacheWrapper cacheWrapper = (SimpleCacheWrapper) context.getBean(aClass);
cacheWrapper.getCache();
}
// now let's add out listeners
MutableCacheEntryListenerConfiguration<Object, Object> listenerConfiguration =
new MutableCacheEntryListenerConfiguration<>(
FactoryBuilder.factoryOf(new NeverCacheListener<>()),
FactoryBuilder.factoryOf(new OnlyCreatedFilter<>()),
false, true);
//noinspection unchecked
cacheProvider.getOwnCaches().forEach(cache -> cache.registerCacheEntryListener(listenerConfiguration));
isDone = true;
}
}
示例9: Register
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
public final void Register() throws Exception {
_listenerConfig = new MutableCacheEntryListenerConfiguration(
FactoryBuilder.factoryOf(this),
FactoryBuilder.factoryOf(new EventFilter(_eventType)),
_isOldValueRequired,
_isSynchronous
);
_cache.registerCacheEntryListener(_listenerConfig);
}
示例10: prepare
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Prepare(global = false)
public void prepare() {
cache = cacheManager.getCache(name);
listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, Long>(
FactoryBuilder.factoryOf(listener),
FactoryBuilder.factoryOf(filter),
false, syncEvents);
}
示例11: extraSetup
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Override
protected MutableConfiguration<Integer, Integer> extraSetup(MutableConfiguration<Integer, Integer> configuration) {
listener = new CacheTestSupport.MyCacheEntryListener<Integer, Integer>();
//establish a CacheEntryListenerClient that a Cache can use for CacheEntryListening
//(via the CacheEntryListenerServer)
listenerConfiguration =
new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(cacheEntryListerClient), null, true, true);
cacheEntryListenerServer.addCacheEventListener(listener);
return configuration.addCacheEntryListenerConfiguration(listenerConfiguration);
}
示例12: testDynamicRegistration
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
@Test
public void testDynamicRegistration() {
assertEquals(1, getConfigurationCacheEntryListenerConfigurationSize(cache));
MyCacheEntryListener secondListener = new MyCacheEntryListener<Long, String>();
MutableCacheEntryListenerConfiguration<Long,
String> listenerConfiguration = new
MutableCacheEntryListenerConfiguration(FactoryBuilder.factoryOf(secondListener), null, false, true);
cache.registerCacheEntryListener(listenerConfiguration);
assertEquals(2,getConfigurationCacheEntryListenerConfigurationSize(cache));
CompleteConfiguration<Long, String> cacheConfig = (CompleteConfiguration)cache.getConfiguration(CompleteConfiguration.class);
for (CacheEntryListenerConfiguration<Long, String> config : cacheConfig.getCacheEntryListenerConfigurations()) {
config.hashCode();
config.isOldValueRequired();
config.isSynchronous();
}
//Can only register the same configuration once
try {
cache.registerCacheEntryListener(listenerConfiguration);
fail();
} catch (IllegalArgumentException e) {
//expected
}
}
示例13: noOpFilterFactory
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected Factory<? extends CacheEntryEventFilter<QueryTestKey, QueryTestValue>> noOpFilterFactory() {
return FactoryBuilder.factoryOf(NoopAsyncFilter.class);
}
示例14: getStoreFactory
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public Factory<? extends CacheStore<Object, Object>> getStoreFactory() {
return FactoryBuilder.factoryOf(MapCacheStore.class);
}
示例15: loadCache
import javax.cache.configuration.FactoryBuilder; //导入方法依赖的package包/类
/**
* @param cacheMode Cache mode.
* @param atomicityMode Atomicity mode.
* @throws Exception If failed.
*/
private void loadCache(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
int keys = 100;
boolean loc = cacheMode == LOCAL;
Map<Integer, Integer> data1 = generateDataMap(keys);
Map<Integer, Integer> data2 = generateDataMap(keys);
Factory<? extends CacheStore<Integer, Integer>> fctr1 =
FactoryBuilder.factoryOf(new MapBasedStore<>(data1));
Factory<? extends CacheStore<Integer, Integer>> fctr2 =
FactoryBuilder.factoryOf(new MapBasedStore<>(data2));
CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 1, false)
.setCacheStoreFactory(fctr1);
CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 1, false)
.setCacheStoreFactory(fctr2);
Ignite node = startGrids(loc ? 1 : 4);
node.createCaches(F.asList(ccfg1, ccfg2));
IgniteCache<Integer, Integer> cache1 = node.cache(CACHE1);
IgniteCache<Integer, Integer> cache2 = node.cache(CACHE2);
cache1.loadCache(null);
checkCacheData(data1, CACHE1);
assertEquals(0, cache2.size());
cache2.loadCache(null);
checkCacheData(data2, CACHE2);
}