[英]infinispan embedded cache with two process same machine
I am new to infinispan and I am trying to start from very basic.After going through the documentation about embedded cache that lives in the same JVM process as the running program, I am trying to see how it works. 我是infinispan的新手,我试图从非常基础开始。在查看了与正在运行的程序存在于同一JVM进程中的嵌入式缓存的文档之后,我试图了解它是如何工作的。
Here is my code. 这是我的代码。
public class CacheClient {
public static void main(String[] args) {
CacheClient cc = new CacheClient();
cc.start();
}
public void start() {
boolean run = true;
EmbeddedCacheManager manager = **createCacheManagerProgrammatically**();
manager.start();
Cache<Object, Object> cache = manager.getCache("dist");
Scanner sc = new Scanner(System.in);
while (run) {
System.out.println("Enter the command:");
String command = sc.next();
switch (command) {
case "add":
System.out.println("Enter the key:");
int i = sc.nextInt();
cache.put(Integer.valueOf(i), Integer.valueOf(i));
break;
case "list":
System.out.println("The keys:");
Set<Object> keySet = cache.keySet();
Iterator<Object> iter = keySet.iterator();
while (iter.hasNext()) {
System.out.println((Integer) iter.next());
}
break;
default:
run = false;
break;
}
}
sc.close();
manager.stop();
}
private EmbeddedCacheManager **createCacheManagerProgrammatically**() {
System.out
.println("Starting a cache manager with a programmatic configuration");
EmbeddedCacheManager cacheManager = new DefaultCacheManager(
GlobalConfigurationBuilder
.defaultClusteredBuilder()
.transport()
.defaultTransport()
.clusterName("dist_cluster")
.addProperty("configurationFile",
"jgroups.xml")
.build(), new ConfigurationBuilder().clustering()
.cacheMode(CacheMode.REPL_SYNC).build());
cacheManager.defineConfiguration("dist", new ConfigurationBuilder()
.clustering().cacheMode(CacheMode.REPL_SYNC).hash()
.numOwners(2).build());
return cacheManager;
}
}
From the above code my expectation is that suppose I run this program first and start adding integers to cache using add command, then when I run the same program again (another process) then the moment I use the list command, I should see the contents immediately. 从上面的代码我的期望是假设我首先运行这个程序并开始使用add命令添加整数到缓存,然后当我再次运行相同的程序(另一个进程)然后我使用list命令的那一刻,我应该看到内容立即。 But I am not able to see any content when I use list in the 2nd process.
但是当我在第二个进程中使用list时,我无法看到任何内容。
1) Is this how Embedded cache supposed to work? 1)嵌入式缓存应该如何工作?
Is my expectation correct? 我的期望是否正确?
If so, then what am I missing? 如果是这样,那么我错过了什么?
Please correct my mistakes and point me to a tutorial that explains clearly how it works. 请纠正我的错误并指出我的教程,清楚地解释它是如何工作的。 I tried to go through the tutorial from Infinispan documentation.
我尝试从Infinispan文档中学习教程。 But I think it's not very clear there.
但我认为那里不是很清楚。 Any help is highly appreciated.
任何帮助都非常感谢。
I finally figured out. 我终于想通了。 Please set System.setProperty("java.net.preferIPv4Stack", "true");
请设置System.setProperty(“java.net.preferIPv4Stack”,“true”);
and the above code will work. 以上代码将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.