Created
September 27, 2023 16:19
-
-
Save andyuk1986/6b7547313f9a1ca30223b62c3e75748a to your computer and use it in GitHub Desktop.
Near cache example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConfigurationBuilder builder = new ConfigurationBuilder(); | |
builder.addServer() | |
.host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT).security().authentication().username("admin").password("password") | |
.connectionPool().maxActive(1).exhaustedAction(ExhaustedAction.WAIT) | |
.marshaller(new GenericJBossMarshaller()); | |
builder.remoteCache("anna").nearCacheMode(NearCacheMode.INVALIDATED) | |
.nearCacheMaxEntries(2); | |
.nearCacheUseBloomFilter(true); | |
ConfigurationBuilder builder1 = new ConfigurationBuilder(); | |
builder1.addServer() | |
.host("127.0.0.1").port(11322).security().authentication().username("admin").password("password") | |
.connectionPool().maxActive(1).exhaustedAction(ExhaustedAction.WAIT) | |
.marshaller(new GenericJBossMarshaller()); | |
builder1.remoteCache("anna").nearCacheMode(NearCacheMode.INVALIDATED) | |
.nearCacheMaxEntries(2); | |
.nearCacheUseBloomFilter(true); | |
// Connect to the server. | |
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build()); | |
RemoteCacheManager cacheManager1 = new RemoteCacheManager(builder1.build()); | |
RemoteCache<String, String> cache = cacheManager.getCache("anna"); | |
cache.put("K", "V"); | |
System.out.println("Cluster1: " + cache.get("K") ); | |
RemoteCache<String, String> cache1 = cacheManager1.getCache("anna"); | |
System.out.println("Cluster2 before replace: " + cache1.get("K")); | |
cache1.replace("K", "V1"); | |
// cache1.remove("K"); | |
System.out.println("Cluster2 after:" + cache1.get("K")); | |
Thread.sleep(10000); | |
System.out.println("Cluster1 after:" + cache.get("K")); | |
cacheManager.stop(); | |
cacheManager1.stop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment