Ce contenu n'est pas disponible dans la langue sélectionnée.
5.2.2. Using the ConfigurationBuilder API
5.2.2.1. Programmatically Create a CacheManager and Replicated Cache Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Programmatic configuration in JBoss Data Grid almost exclusively involves the ConfigurationBuilder API and the CacheManager.
Procedure 5.1. Steps for Programmatic Configuration in JBoss Data Grid
- Create a CacheManager as a starting point in an XML file. If required, this CacheManager can be programmed in runtime to the specification that meets the requirements of the use case. The following is an example of how to create a CacheManager:
EmbeddedCacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache defaultCache = manager.getCache();
EmbeddedCacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache defaultCache = manager.getCache();
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create a new synchronously replicated cache programmatically.
- Create a new configuration object instance using the ConfigurationBuilder helper object:
Configuration c = new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC).build();
Configuration c = new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC).build();
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Set the cache mode to synchronous replication:
String newCacheName = "repl";
String newCacheName = "repl";
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Define or register the configuration with a manager:
manager.defineConfiguration(newCacheName, c); Cache<String, String> cache = manager.getCache(newCacheName);
manager.defineConfiguration(newCacheName, c); Cache<String, String> cache = manager.getCache(newCacheName);
Copy to Clipboard Copied! Toggle word wrap Toggle overflow