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


Java Cache.addListener方法代码示例

本文整理汇总了Java中org.infinispan.Cache.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.addListener方法的具体用法?Java Cache.addListener怎么用?Java Cache.addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.infinispan.Cache的用法示例。


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

示例1: start

import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public InfinispanEventListener start(InfinispanConsumer consumer) {
    Cache<?, ?> embeddedCache = InfinispanUtil.asEmbedded(consumer.getCache());
    InfinispanConfiguration configuration = consumer.getConfiguration();
    InfinispanEventListener listener;
    if (configuration.hasCustomListener()) {
        listener = configuration.getCustomListener();
        listener.setInfinispanConsumer(consumer);
    } else if (configuration.isClusteredListener()) {
        if (configuration.isSync()) {
            listener = new InfinispanSyncClusteredEventListener(consumer, configuration.getEventTypes());
        } else {
            listener = new InfinispanAsyncClusteredEventListener(consumer, configuration.getEventTypes());
        }
    } else {
        if (configuration.isSync()) {
            listener = new InfinispanSyncLocalEventListener(consumer, configuration.getEventTypes());
        } else {
            listener = new InfinispanAsyncLocalEventListener(consumer, configuration.getEventTypes());
        }
    }
    embeddedCache.addListener(listener);
    return listener;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:InfinispanConsumerEmbeddedHandler.java

示例2: main

import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) {
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Define local cache configuration
   cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
   // Obtain the local cache
   Cache<String, String> cache = cacheManager.getCache("local");
   // Register a listener
   cache.addListener(new MyListener());
   // Store some values
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   cache.put("key1", "newValue");
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
开发者ID:infinispan,项目名称:infinispan-simple-tutorials,代码行数:17,代码来源:InfinispanListen.java

示例3: addListener

import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public void addListener(String containerName, String cacheName,
        IGetUpdates<?, ?> u) throws CacheListenerAddException {
    EmbeddedCacheManager manager = this.cm;
    Cache<Object,Object> c;
    String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
    if (manager == null) {
        return;
    }

    if (!manager.cacheExists(realCacheName)) {
        throw new CacheListenerAddException();
    }
    c = manager.getCache(realCacheName);
    CacheListenerContainer cl = new CacheListenerContainer(u,
            containerName, cacheName);
    c.addListener(cl);
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:19,代码来源:ClusterManager.java

示例4: main

import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
	
     
      // Initialize the cache manager
	DefaultCacheManager cacheManager = new DefaultCacheManager("config/beosbank-infinispan.xml");
      // Obtain the default cache
      Cache<Long, MoneyTransfert> cache = cacheManager.getCache("beosbank-dist");
      
      
	// Obtain the remote cache
	cache.addListener(new DatagridListener());
	// Create a Money Transfer Object from XML Message using BeaoIO API
	try {
		BeosBankCacheUtils.loadEntries(cache,inputFileNames);
		// Inspect the cache .
		System.out.println(cache.size());
		Thread.sleep(2000);
		cache.get(5l);
		System.out.println("Cache content after 2 sec");
		//Current node content
		printCacheContent(cache);
		
		Thread.sleep(1000);
		System.out.println("Cache content after 3 sec");
		printCacheContent(cache);
		
		Thread.sleep(3000);
		System.out.println("Cache content after 6 sec");
		printCacheContent(cache);
		
		// Stop the cache
		cache.stop();

	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:PacktPublishing,项目名称:JBoss-Developers-Guide,代码行数:40,代码来源:ExpirationXmlConfiguration.java

示例5: main

import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
	
      //Configuration
	ConfigurationBuilder builder = new ConfigurationBuilder();
	builder
		.eviction()
		.strategy(EvictionStrategy.LRU)
		.type(EvictionType.COUNT)
		.size(3)
		;
      // Initialize the cache manager
	DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
    // Obtain the default cache
    Cache<Long, MoneyTransfert> cache = cacheManager.getCache("beosbank-dist");
      
	// Obtain the remote cache
	cache.addListener(new DatagridListener());
	// Create a Money Transfer Object from XML Message using BeaoIO API
	try {
		BeosBankCacheUtils.loadEntries(cache,inputFileNames);

		// Inspect the cache .
		System.out.println(cache.size());
		System.out.println(cache.get(3l));
		
		//Current node content
		cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP)
        .entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue().getDescription()));
		
		// Stop the cache
		cache.stop();

	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:PacktPublishing,项目名称:JBoss-Developers-Guide,代码行数:39,代码来源:EvictionDemo.java

示例6: main

import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) {

		String[] inputFileNames = { "data1.xml", "data2.xml", "data3.xml", "data4.xml", "data5.xml" };
		// Create a Money Transfer Object from XML Message using BeaoIO API
		try {
			StreamFactory factory = StreamFactory.newInstance();
			factory.loadResource("mapping.xml");
			Unmarshaller unmarshaller = factory.createUnmarshaller("MoneyTransferStream");

			String record;
			ConfigurationBuilder builder = new ConfigurationBuilder();
			Cache<String, Object> cache = new DefaultCacheManager(builder.build()).getCache();
			
			cache.addListener(new DatagridListener());
			//Read Transactions and put in cache
			for (String inputFile : inputFileNames) {
				record = FileUtils.getContentsAsString(new File(INPUT_DIR + inputFile));
				MoneyTransfert mt = (MoneyTransfert) unmarshaller.unmarshal(record);
				cache.put(mt.getId() + "", mt);
			}

			//Inspect the cache .
			System.out.println(cache.size());
			System.out.println(cache.getStatus());
			System.out.println(cache.get("3"));

			//Stop the cache
			cache.stop();
			System.out.println(cache.getStatus());

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
 
开发者ID:PacktPublishing,项目名称:JBoss-Developers-Guide,代码行数:37,代码来源:EmbeddedCacheListenerDemo.java

示例7: start

import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public void start() {
    if (started.compareAndSet(false, true)) {
        try {
            this.rulesManager = new RulesManager(rulesConfiguration);
            this.dataGridManager = new DataGridManager();
            this.haKieSessionBuilder = new HAKieSessionBuilder(rulesManager, executorService);

            this.dataGridManager.startCacheInfo(nodeName);
            Cache<String, String> infoCache = this.dataGridManager.getReplicatedCache();
            String groupId = infoCache.putIfAbsent(RulesManager.RULES_GROUP_ID, rulesConfiguration.getGroupId());
            String artifactId = infoCache.putIfAbsent(RulesManager.RULES_ARTIFACT_ID, rulesConfiguration.getArtifactId());
            String version = infoCache.putIfAbsent(RulesManager.RULES_VERSION, rulesConfiguration.getVersion());
            this.rulesManager.start(groupId, artifactId, version);
            infoCache.addListener(new UpdateVersionListener(this.router, this.rulesManager));

            rulesUpdateVersion = new RulesUpdateVersionImpl(dataGridManager.getReplicatedCache());


            this.dataGridManager.start(haKieSessionBuilder, nodeName);

            this.dataGridManager.waitForMinimumOwners(1, TimeUnit.MINUTES);

            this.kieSessionSaver = new KieSessionSaver(haKieSessionBuilder, this.dataGridManager.getSessionCache());

            this.dataGridManager.getFactCache().addListener(new FactListenerPost(this.kieSessionSaver));
            this.dataGridManager.getSessionCache().addListener(new SessionListenerPre(this.router));
            this.dataGridManager.getSessionCache().addListener(new SessionListenerPost(this.router));

            putter = new PutterImpl(dataGridManager.getFactCache());
            this.router.start(jmsConfiguration, this);

            if (LOGGER.isDebugEnabled()) LOGGER.debug("Node [{}] finished starting.", this.nodeName);
        } catch (Exception e) {
            started.set(false);
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:redhat-italy,项目名称:hacep,代码行数:40,代码来源:HACEPImpl.java

示例8: InfinispanAsyncMultiMap

import org.infinispan.Cache; //导入方法依赖的package包/类
public InfinispanAsyncMultiMap(Vertx vertx, Cache<MultiMapKey, Object> cache) {
  this.vertx = (VertxInternal) vertx;
  this.cache = cache;
  nearCache = new ConcurrentHashMap<>();
  cache.addListener(new EntryListener());
  taskQueue = new TaskQueue();
}
 
开发者ID:vert-x3,项目名称:vertx-infinispan,代码行数:8,代码来源:InfinispanAsyncMultiMap.java

示例9: main

import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException {
    //Configure Infinispan to use default transport and Kubernetes configuration
    GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().transport()
            .defaultTransport()
            .addProperty("configurationFile", "default-configs/default-jgroups-kubernetes.xml")
            .build();

    //Each node generates events, so we don't want to consume all memory available.
    //Let's limit number of entries to 100 and use sync mode
    ConfigurationBuilder cacheConfiguration = new ConfigurationBuilder();
    cacheConfiguration.clustering().cacheMode(CacheMode.DIST_SYNC);
    cacheConfiguration.eviction().strategy(EvictionStrategy.LRU).size(100);

    DefaultCacheManager cacheManager = new DefaultCacheManager(globalConfig, cacheConfiguration.build());
    Cache<String, String> cache = cacheManager.getCache();
    cache.addListener(new MyListener());

    //Each cluster member will update its own entry in the cache
    String hostname = Inet4Address.getLocalHost().getHostName();
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    scheduler.scheduleAtFixedRate(() -> cache.put(hostname, Instant.now().toString()), 0, 2, TimeUnit.SECONDS);

    try {
        //This container will operate for an hour and then it will die
        TimeUnit.HOURS.sleep(1);
    } catch (InterruptedException e) {
        scheduler.shutdown();
        cacheManager.stop();
    }
}
 
开发者ID:infinispan,项目名称:infinispan-simple-tutorials,代码行数:31,代码来源:InfinispanKubernetes.java

示例10: createCaches

import org.infinispan.Cache; //导入方法依赖的package包/类
private Map<CacheCategory, CacheService> createCaches(CacheInfo cacheInfo) {
	Map<CacheCategory, CacheService> ciCaches = new HashMap<CacheCategory, CacheService>();
	for (Map.Entry<CacheCategory, CacheConfiguration> entry : cacheInfo.getConfiguration().entrySet()) {
		if (entry.getValue() instanceof InfinispanConfiguration) {
			CacheService cacheService;
			CacheCategory category = entry.getKey();
			InfinispanConfiguration config = (InfinispanConfiguration) entry.getValue();
			if (config.isCacheEnabled()) {
				String configurationName = config.getConfigurationName();
				if (null == configurationName) {
					Configuration dcc = manager.getDefaultCacheConfiguration();
					Configuration infinispan = config.getInfinispanConfiguration(
							new ConfigurationBuilder().read(dcc));
					configurationName = "$" + category.getName() + "$" + cacheInfo.getId();
					manager.defineConfiguration(configurationName, infinispan);
				}
				recorder.record("infinispan", "configuration name " + configurationName);
				Cache<String, Object> cache = manager.<String, Object>getCache(configurationName);
				cache.addListener(listener);
				cacheService = new InfinispanCacheService(cache);
			} else {
				cacheService = noCacheFactory.create(null, category);
			}
			ciCaches.put(category, cacheService);
		}
	}
	return ciCaches;
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:29,代码来源:InfinispanCacheFactory.java

示例11: main

import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
	
      //Configuration
	ConfigurationBuilder builder = new ConfigurationBuilder();
	builder
	   .expiration()
	   .maxIdle(3l, TimeUnit.SECONDS)
	   .lifespan(5l, TimeUnit.SECONDS);
	
      // Initialize the cache manager
	DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
      // Obtain the default cache
      Cache<Long, MoneyTransfert> cache = cacheManager.getCache("beosbank-dist");
      
      
	// Obtain the remote cache
	cache.addListener(new DatagridListener());
	// Create a Money Transfer Object from XML Message using BeaoIO API
	try {
		BeosBankCacheUtils.loadEntries(cache,inputFileNames);
		// Inspect the cache .
		System.out.println(cache.size());
		Thread.sleep(2000);
		cache.get(5l);
		System.out.println("Cache content after 2 sec");
		//Current node content
		printCacheContent(cache);
		
		Thread.sleep(1000);
		System.out.println("Cache content after 3 sec");
		printCacheContent(cache);
		
		Thread.sleep(3000);
		System.out.println("Cache content after 6 sec");
		printCacheContent(cache);
		
		// Stop the cache
		cache.stop();

	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:PacktPublishing,项目名称:JBoss-Developers-Guide,代码行数:46,代码来源:ExpirationDemo.java


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