本文整理汇总了Java中org.infinispan.manager.DefaultCacheManager.getCache方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultCacheManager.getCache方法的具体用法?Java DefaultCacheManager.getCache怎么用?Java DefaultCacheManager.getCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.infinispan.manager.DefaultCacheManager
的用法示例。
在下文中一共展示了DefaultCacheManager.getCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
public static void main(String[] args) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.indexing().index(Index.ALL)
.addProperty("default.directory_provider", "ram")
.addProperty("lucene_version", "LUCENE_CURRENT");
// Construct a simple local cache manager with default configuration
DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
// Obtain the default cache
Cache<String, Person> cache = cacheManager.getCache();
// Store some entries
cache.put("person1", new Person("William", "Shakespeare"));
cache.put("person2", new Person("William", "Wordsworth"));
cache.put("person3", new Person("John", "Milton"));
// Obtain a query factory for the cache
QueryFactory queryFactory = Search.getQueryFactory(cache);
// Construct a query
Query query = queryFactory.from(Person.class).having("name").eq("William").toBuilder().build();
// Execute the query
List<Person> matches = query.list();
// List the results
matches.forEach(person -> System.out.printf("Match: %s", person));
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例2: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Setup up a clustered cache manager
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
// Make the default cache a replicated synchronous one
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.REPL_SYNC);
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build(), builder.build());
// Obtain the default cache
Cache<String, String> cache = cacheManager.getCache();
// Store the current node address in some random keys
for(int i=0; i < 10; i++) {
cache.put(UUID.randomUUID().toString(), cacheManager.getNodeAddress());
}
// Display the current cache contents for the whole cluster
cache.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
// Display the current cache contents for this node
cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP)
.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例3: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的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");
// Store some values
int range = 10;
IntStream.range(0, range).boxed().forEach(i -> cache.put(i + "-key", i + "-value"));
// Map and reduce the keys
int result = cache.keySet().stream()
.map((Serializable & Function<String, Integer>) e -> Integer.valueOf(e.substring(0, e.indexOf("-"))))
.collect(CacheCollectors.serializableCollector(() -> Collectors.summingInt(i -> i.intValue())));
System.out.printf("Result = %d\n", result);
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例4: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的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();
}
示例5: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
public static void main(String[] args) {
// Setup up a clustered cache manager
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
// Make the default cache a distributed one
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.DIST_SYNC);
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build(), builder.build());
// Obtain the default cache
Cache<String, String> cache = cacheManager.getCache();
// Create a distributed executor service using the distributed cache to determine the nodes on which to run
DefaultExecutorService executorService = new DefaultExecutorService(cache);
// Submit a job to all nodes
List<Future<Integer>> results = executorService.submitEverywhere((Callable & Serializable) () -> new Random().nextInt());
// Print out the results
results.forEach(s -> {
try {
System.out.printf("%s\n", s.get(100, TimeUnit.MILLISECONDS));
} catch (Exception e) {
}
});
// Shuts down the cache manager and all associated resources
cacheManager.stop();
System.exit(0);
}
示例6: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Setup up a clustered cache manager
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
// Make the default cache a distributed synchronous one
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.DIST_SYNC);
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build(), builder.build());
// Obtain the default cache
Cache<String, String> cache = cacheManager.getCache();
// Store the current node address in some random keys
for(int i=0; i < 10; i++) {
cache.put(UUID.randomUUID().toString(), cacheManager.getNodeAddress());
}
// Display the current cache contents for the whole cluster
cache.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
// Display the current cache contents for this node
cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP)
.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例7: initialize
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
/**
* 초기화
* @param configFile
* @param cacheName
* @param loginCacheName
* @throws IOException
*/
@Override
public void initialize(String configFile, String cacheName, String loginCacheName)
throws IOException {
try {
StringUtils.isNotNull("configFile", configFile);
cacheManager = new DefaultCacheManager(configFile);
this.cacheName = cacheName;
this.loginCacheName = loginCacheName;
cache = cacheManager.getCache(cacheName);
loginCache = cacheManager.getCache(loginCacheName);
waitForConnectionReady();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的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();
}
}
示例9: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的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();
}
}
示例10: init
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
private void init() throws Exception
{
log.info(this + " initializing ...");
//DefaultCacheManager cm = configureProgrammatically();
DefaultCacheManager cm = configureDeclaratively();
Cache sc = cm.getCache("SOURCE-CACHE");
caches.put("SOURCE-CACHE", sc);
Cache dc = cm.getCache("DESTINATION-CACHE");
caches.put("DESTINATION-CACHE", dc);
}
示例11: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Define the default cache to be transactional
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL);
// Construct a local cache manager using the configuration we have defined
DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
// Obtain the default cache
Cache<String, String> cache = cacheManager.getCache();
// Obtain the transaction manager
TransactionManager transactionManager = cache.getAdvancedCache().getTransactionManager();
// Perform some operations within a transaction and commit it
transactionManager.begin();
cache.put("key1", "value1");
cache.put("key2", "value2");
transactionManager.commit();
// Display the current cache contents
System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
// Perform some operations within a transaction and roll it back
transactionManager.begin();
cache.put("key1", "value3");
cache.put("key2", "value4");
transactionManager.rollback();
// Display the current cache contents
System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例12: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的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");
// Store a value
cache.put("key", "value");
// Retrieve the value and print it out
System.out.printf("key = %s\n", cache.get("key"));
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例13: main
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的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();
}
}
示例14: initialize
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
public void initialize(Configuration config) {
GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
global.globalJmxStatistics().allowDuplicateDomains(true);
manager = new DefaultCacheManager(global.build());
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.persistence()
.addStore(SoftIndexFileStoreConfigurationBuilder.class)
.indexLocation(config.getDataDir()+"/index")
.dataLocation(config.getDataDir()+"/data");
manager.defineConfiguration("raccovery-cache", builder.build(global.build()));
cache = manager.getCache("raccovery-cache");
LOG.info("Starting persistence layer");
}
示例15: setUp
import org.infinispan.manager.DefaultCacheManager; //导入方法依赖的package包/类
@Before
public void setUp() {
_cacheMgr = new DefaultCacheManager(new GlobalConfigurationBuilder()
.transport().defaultTransport().build());
_cacheMgr.defineConfiguration("test-cache",
new ConfigurationBuilder().invocationBatching().enable().build());
Cache<String, String> cache = _cacheMgr.getCache("test-cache");
_registry = new InfinispanRegistry(cache);
}