本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
示例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();
}
}
示例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;
}
示例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();
}
}