本文整理匯總了Java中org.infinispan.manager.DefaultCacheManager.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultCacheManager.stop方法的具體用法?Java DefaultCacheManager.stop怎麽用?Java DefaultCacheManager.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.infinispan.manager.DefaultCacheManager
的用法示例。
在下文中一共展示了DefaultCacheManager.stop方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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();
}
示例8: main
import org.infinispan.manager.DefaultCacheManager; //導入方法依賴的package包/類
public static void main(String[] args) {
// Setup up a clustered cache manager
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build());
ClusterExecutor clusterExecutor = cacheManager.executor();
clusterExecutor.submitConsumer(cm -> new Random().nextInt(), (address, intValue, exception) ->
System.out.printf("%s\n", intValue));
// Shuts down the cache manager and all associated resources
cacheManager.stop();
}
示例9: 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();
}
示例10: 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();
}
}
示例11: 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();
// Create the counter configuration builder
CounterManagerConfigurationBuilder builder = global.addModule(CounterManagerConfigurationBuilder.class);
// Create 3 counters.
// The first counter is bounded to 10 (upper-bound).
builder.addStrongCounter().name("counter-1").upperBound(10).initialValue(1);
// The second counter is unbounded
builder.addStrongCounter().name("counter-2").initialValue(2);
// And finally, the third counter is a weak counter.
builder.addWeakCounter().name("counter-3").initialValue(3);
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build());
// Retrieve the CounterManager from the CacheManager. Each CacheManager has it own CounterManager
CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(cacheManager);
// StrongCounter provides the higher consistency. Its value is known during the increment/decrement and it may be bounded.
// Bounded counters are aimed for uses cases where a limit is needed.
StrongCounter counter1 = counterManager.getStrongCounter("counter-1");
// All methods returns a CompletableFuture. So you can do other work while the counter value is being computed.
counter1.getValue().thenAccept(value -> System.out.println("Counter-1 initial value is " + value)).get();
// Try to add more than the upper-bound
counter1.addAndGet(10).handle((value, throwable) -> {
// Value is null since the counter is bounded and we can add 10 to it.
System.out.println("Counter-1 Exception is " + throwable.getMessage());
return 0;
}).get();
// Check the counter value. It should be the upper-bound (10)
counter1.getValue().thenAccept(value -> System.out.println("Counter-1 value is " + value)).get();
//Decrement the value. Should be 9.
counter1.decrementAndGet().handle((value, throwable) -> {
// No exception this time.
System.out.println("Counter-1 new value is " + value);
return value;
}).get();
// Similar to counter-1, counter-2 is a strong counter but it is unbounded. It will never throw the CounterOutOfBoundsException
StrongCounter counter2 = counterManager.getStrongCounter("counter-2");
// All counters allow a listener to be registered.
// The handle can be used to remove the listener
counter2.addListener(event -> System.out
.println("Counter-2 event: oldValue=" + event.getOldValue() + " newValue=" + event.getNewValue()));
// Adding MAX_VALUE won't throws an exception. But the all the increments won't have any effect since we can store
//any value larger the MAX_VALUE
counter2.addAndGet(Long.MAX_VALUE).thenAccept(aLong -> System.out.println("Counter-2 value is " + aLong)).get();
// Conditional operations are allowed in strong counters
counter2.compareAndSet(Long.MAX_VALUE, 0)
.thenAccept(aBoolean -> System.out.println("Counter-2 CAS result is " + aBoolean)).get();
counter2.getValue().thenAccept(value -> System.out.println("Counter-2 value is " + value)).get();
// Reset the counter to its initial value (2)
counter2.reset().get();
counter2.getValue().thenAccept(value -> System.out.println("Counter-2 initial value is " + value)).get();
// Retrieve counter-3
WeakCounter counter3 = counterManager.getWeakCounter("counter-3");
// Weak counter doesn't have its value available during updates. This makes the increment faster than the StrongCounter
// Its value is computed lazily and stored locally.
// Its main use case is for uses-case where faster increments are needed.
counter3.add(5).thenAccept(aVoid -> System.out.println("Adding 5 to counter-3 completed!")).get();
// Check the counter value.
System.out.println("Counter-3 value is " + counter3.getValue());
// Stop the cache manager and release all resources
cacheManager.stop();
}