当前位置: 首页>>代码示例>>Java>>正文


Java MutableCacheEntryListenerConfiguration类代码示例

本文整理汇总了Java中javax.cache.configuration.MutableCacheEntryListenerConfiguration的典型用法代码示例。如果您正苦于以下问题:Java MutableCacheEntryListenerConfiguration类的具体用法?Java MutableCacheEntryListenerConfiguration怎么用?Java MutableCacheEntryListenerConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MutableCacheEntryListenerConfiguration类属于javax.cache.configuration包,在下文中一共展示了MutableCacheEntryListenerConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkEvents

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
/**
 * @param cache Cache.
 * @param lsnrFactory Listener factory.
 * @param key Key.
 * @param create {@code True} if listens for create events.
 * @param update {@code True} if listens for update events.
 * @param rmv {@code True} if listens for remove events.
 * @param expire {@code True} if listens for expire events.
 * @throws Exception If failed.
 */
private void checkEvents(
    final IgniteCache<Object, Object> cache,
    final Factory<CacheEntryListener<Object, Object>> lsnrFactory,
    Integer key,
    boolean create,
    boolean update,
    boolean rmv,
    boolean expire) throws Exception {
    CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(
        lsnrFactory,
        null,
        true,
        false
    );

    cache.registerCacheEntryListener(lsnrCfg);

    try {
        checkEvents(cache, lsnrCfg, key, create, update, rmv, expire, true);
    }
    finally {
        cache.deregisterCacheEntryListener(lsnrCfg);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:35,代码来源:IgniteCacheEntryListenerAbstractTest.java

示例2: testTemplateAddsListeners

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
@Test
public void testTemplateAddsListeners() throws Exception {
  CacheManager cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-listeners.xml")
      .toURI(), getClass().getClassLoader());

  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class);
  MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(Test107CacheEntryListener::new, null, false, true);
  configuration.addCacheEntryListenerConfiguration(listenerConfiguration);

  Cache<String, String> cache = cacheManager.createCache("foos", configuration);
  cache.put("Hello", "Bonjour");

  assertThat(Test107CacheEntryListener.seen.size(), Matchers.is(1));
  assertThat(TestCacheEventListener.seen.size(), Matchers.is(1));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:17,代码来源:Eh107XmlIntegrationTest.java

示例3: produces

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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;
}
 
开发者ID:wesleyegberto,项目名称:javaee_projects,代码行数:21,代码来源:CacheProducer.java

示例4: produce

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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;
}
 
开发者ID:wesleyegberto,项目名称:javaee_projects,代码行数:21,代码来源:LimitedCacheExposer.java

示例5: setup

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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);
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:18,代码来源:ListenerICacheTest.java

示例6: extraSetup

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:19,代码来源:AdditionalCacheListenerTest.java

示例7: extraSetup

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:22,代码来源:CacheListenerTest.java

示例8: testDeregistration

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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));
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:25,代码来源:CacheListenerTest.java

示例9: testExpiration

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:35,代码来源:JCacheTest.java

示例10: createEntryListenerConfiguration

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
private CacheEntryListenerConfiguration<Object, Object> createEntryListenerConfiguration() {
    return new MutableCacheEntryListenerConfiguration<>(
        new Factory<CacheEntryListener<Object, Object>>() {
            @Override
            public CacheEntryListener<Object, Object> create() {
                return new JCacheEntryEventListener() {
                    @Override
                    protected void onEvents(Iterable<CacheEntryEvent<?, ?>> events) {
                        for (CacheEntryEvent<?, ?> event : events) {
                            Exchange exchange = getEndpoint().createExchange();
                            Message message = exchange.getIn();
                            message.setHeader(JCacheConstants.EVENT_TYPE, event.getEventType().name());
                            message.setHeader(JCacheConstants.KEY, event.getKey());
                            message.setBody(event.getValue());

                            if (event.isOldValueAvailable()) {
                                message.setHeader(JCacheConstants.OLD_VALUE, event.getOldValue());
                            }

                            try {
                                getProcessor().process(exchange);
                            } catch (Exception e) {
                                LOGGER.error("Error processing event ", e);
                            }
                        }
                    }
                };
            }
        },
        new Factory<CacheEntryEventFilter<Object, Object>>() {
            @Override
            public CacheEntryEventFilter<Object, Object> create() {
                return getJCacheEndpoint().getManager().getEventFilter();
            }
        },
        getJCacheEndpoint().getManager().getConfiguration().isOldValueRequired(),
        getJCacheEndpoint().getManager().getConfiguration().isSynchronous()
    );
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:40,代码来源:JCacheConsumer.java

示例11: registerListeners

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的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;
    }
}
 
开发者ID:sdl,项目名称:dxa-modules,代码行数:30,代码来源:TestCacheListenerExtender.java

示例12: Register

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
public final void Register() throws Exception {

        _listenerConfig = new MutableCacheEntryListenerConfiguration(
                FactoryBuilder.factoryOf(this),
                FactoryBuilder.factoryOf(new EventFilter(_eventType)),
                _isOldValueRequired,
                _isSynchronous
        );

        _cache.registerCacheEntryListener(_listenerConfig);
    }
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:12,代码来源:EventListener.java

示例13: registerCacheListener

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
/**
 * @param cache Cache.
 * @return Event listener.
 */
private AllEventListener<Integer, String> registerCacheListener(IgniteCache<Integer, String> cache) {
    AllEventListener<Integer, String> lsnr = new AllEventListener<>();

    cache.registerCacheEntryListener(
        new MutableCacheEntryListenerConfiguration<>(factoryOf(lsnr), null, true, false));

    return lsnr;
}
 
开发者ID:apache,项目名称:ignite,代码行数:13,代码来源:CacheContinuousQueryLostPartitionTest.java

示例14: createCacheListener

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
/**
 * @param key Key.
 * @param res Result.
 * @param id Listener ID.
 * @return Listener
 */
private CacheEntryListenerConfiguration<Integer, String> createCacheListener(
    Integer key,
    IgniteFuture<String> res,
    int id) {
    return new MutableCacheEntryListenerConfiguration<>(
        factoryOf(new CacheListener(res, id)),
        new SingletonFactory<>(new KeyEventFilter(key, id)), false, true);
}
 
开发者ID:apache,项目名称:ignite,代码行数:15,代码来源:GridCacheContinuousQueryConcurrentTest.java

示例15: checkExpiredEvents

import javax.cache.configuration.MutableCacheEntryListenerConfiguration; //导入依赖的package包/类
/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void checkExpiredEvents(CacheConfiguration<Object, Object> ccfg) throws Exception {
    IgniteCache<Object, Object> cache = ignite(0).createCache(ccfg);

    try {
        evtCntr = new AtomicInteger();

        CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(
            new ExpiredListenerFactory(),
            null,
            true,
            false
        );

        cache.registerCacheEntryListener(lsnrCfg);

        IgniteCache<Object, Object> expiryCache =
            cache.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(MILLISECONDS, 500)));

        expiryCache.put(1, 1);

        for (int i = 0; i < 10; i++)
            cache.get(i);

        boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
            @Override public boolean apply() {
                return evtCntr.get() > 0;
            }
        }, 5000);

        assertTrue(wait);

        U.sleep(100);

        assertEquals(1, evtCntr.get());
    }
    finally {
        ignite(0).destroyCache(cache.getName());
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:44,代码来源:IgniteCacheEntryListenerExpiredEventsTest.java


注:本文中的javax.cache.configuration.MutableCacheEntryListenerConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。