@Override public void leave() { channel.close(); channel = null; cacheManager.stop(); }
@Override protected void doStop() throws Exception { manager.stop(); }
@Override public void stop() { logger.info("stop() invoked"); this.cacheManager.stop(); this.cacheManager = null; }
@Override public void closeRepository() { logger.info("closeRepository()"); this.cacheManager.stop(); this.cacheManager = null; maxCommittedTxId = -1; }
@Override public synchronized void deleted(String pid) { ServiceRegistration<EmbeddedCacheManager> serviceRegistration = managedRegistrations.remove(pid); if (serviceRegistration != null) { try { serviceRegistration.unregister(); } catch (Exception e) { } } DefaultCacheManager cacheManager = cacheManagers.remove(pid); if (cacheManager != null) { try { cacheManager.stop(); } catch (Exception e) { } } }
public void stop() { logger.info("Stopping the ClusterManager"); if (this.cm != null) { logger.info("Found a valid ClusterManager, now let it be stopped"); this.cm.stop(); this.cm = null; } if (this.gossiper != null) { this.gossiper.stop(); this.gossiper = null; } }
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(); }
@Override public void run() { if (cache != null) { cache.stop(); cache = null; } if (cacheManager != null) { cacheManager.stop(); cacheManager = null; } cachedDataTableModel.reset(); configFileContents.setText(""); configFileContents.repaint(); configFileName.setText(""); configFileName.repaint(); moveCacheToState(ComponentStatus.TERMINATED); } });
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(e -> Integer.valueOf(e.substring(0, e.indexOf("-")))) .collect(() -> Collectors.summingInt(i -> i.intValue())); System.out.printf("Result = %d\n", result); // Stop the cache manager and release all resources cacheManager.stop(); }
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); }
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(); }
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(); }
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(); }
} catch (InterruptedException e) { scheduler.shutdown(); cacheManager.stop();
public static void main(String[] args) { // Construct a local cache manager with default configuration DefaultCacheManager cacheManager = new DefaultCacheManager(); // Obtain a multimap cache manager from the regular cache manager MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cacheManager); // Define de multimap cache configuration, as a regular cache multimapCacheManager.defineConfiguration("multimap", new ConfigurationBuilder().build()); // Get the MultimapCache MultimapCache<String, String> multimap = multimapCacheManager.get("multimap"); // Store multiple values in a key CompletableFuture.allOf( multimap.put("key", "value1"), multimap.put("key", "value2"), multimap.put("key", "value3")) .whenComplete((nil, ex) -> { // Retrieve the values multimap.get("key").whenComplete((values, ex2) -> { // Print them out System.out.println(values); // Stop the cache manager and release all resources cacheManager.stop(); }); }); }
cacheManager.stop();
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(); }
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(); }
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(); }