Red Hat JBoss Data Grid's replicated mode ensures that every entry is replicated on every node in the data grid.
This mode offers security against data loss due to node failures and excellent data availability. These benefits are at the cost of limiting the storage capacity to the amount of storage available on the node with the least memory.
Programmatic Configuration:
Use the following code snippet to programmatically configure the cache for replication mode (either synchronous or asynchronous):
private static EmbeddedCacheManager createCacheManagerProgramatically() {
return new DefaultCacheManager(
new GlobalConfigurationBuilder()
.transport().addProperty("configurationFile", "jgroups.xml")
.build(),
new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.REPL_SYNC)
.build()
);
}
private static EmbeddedCacheManager createCacheManagerProgramatically() {
return new DefaultCacheManager(
new GlobalConfigurationBuilder()
.transport().addProperty("configurationFile", "jgroups.xml")
.build(),
new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.REPL_SYNC)
.build()
);
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Declarative Configuration:
Edit the infinispan-replication.xml file to include the following XML code to declaratively configure the cache for replication mode (either synchronous or asynchronous):
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Use the following code to initialize and return a DefaultCacheManager with the XML configuration file:
private static EmbeddedCacheManager createCacheManagerFromXml() throws IOException {
return new DefaultCacheManager("infinispan-replication.xml");}
private static EmbeddedCacheManager createCacheManagerFromXml() throws IOException {
return new DefaultCacheManager("infinispan-replication.xml");}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Note
JBoss EAP includes its own underlying JMX. This can cause a collision when using the sample code with JBoss EAP and display an error such as org.infinispan.jmx.JmxDomainConflictException: Domain already registered org.infinispan.
To avoid this, configure global configuration as follows:
GlobalConfiguration glob = new GlobalConfigurationBuilder()
.clusteredDefault()
.globalJmxStatistics()
.allowDuplicateDomains(true)
.enable()
.build();
GlobalConfiguration glob = new GlobalConfigurationBuilder()
.clusteredDefault()
.globalJmxStatistics()
.allowDuplicateDomains(true)
.enable()
.build();
Copy to ClipboardCopied!Toggle word wrapToggle overflow
We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.
About Red Hat
We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.