IllegalStateException for distributed system in Infinispan -
i have been trying implement distributed system store data in node command. idea use keyaffinityservice find key associated local node , each time before put command done, store key refer same local node , use grouping api use key store value in local node. code have following:
simplecache.java:
import java.util.*; import java.util.concurrent.*; import org.infinispan.cache; import org.infinispan.affinity.*; import org.infinispan.manager.*; //used store key local node class locaddr{ static string nut; static string sim;} public class simplecache { public void start() throws exception { embeddedcachemanager manager = new defaultcachemanager("democluster.xml"); cache<string, string> cache = manager.getcache(); string command = ""; int ticketid = 1; scanner scan = new scanner(system.in); cache.start(); manager.start(); // create affinity service find key manager keyaffinityservice keyaffinityservice = keyaffinityservicefactory.newlocalkeyaffinityservice( cache, (keygenerator)new rndkeygenerator(), executors.newsinglethreadexecutor(), 100); //find key associated local node locaddr.nut = objects.tostring(keyaffinityservice.getkeyforaddress(manager.getaddress())); log("start of program....."); log("input 1 of following commands:"); log("book"); log("pay"); log("list"); log("locaddr"); log("quit"); while (true){ command = scan.nextline(); if (command.equals("book")) { log("enter name "); string name = scan.nextline(); locaddr.sim = objects.tostring(keyaffinityservice.getcollocatedkey(locaddr.nut)); cache.put(integer.tostring(ticketid)+manager.getaddress().tostring(),name); log("booked ticket " + name); ticketid++; } else if (command.equals("pay")) { log("enter ticket number "); string id = scan.nextline(); log("display ticket:"+cache.get(id)); string ticket = cache.remove(id); log("checked out ticket " + ticket); } else if (command.equals("list")) { set <string> set = cache.keyset(); (string ticket: set) { log(ticket + " " + cache.get(ticket)); } } else if (command.equals("quit")) { cache.clear(); cache.stop(); manager.stop(); keyaffinityservice.stop(); log("bye"); break; } else if (command.equals("locaddr")) { log("local key manager is: "+locaddr.nut); log("manager address is: " + manager.getaddress()); } else { log("unknown command " + command); } } } public static void main(string[] args) throws exception{ new simplecache().start(); } public static void log(string s){ system.out.println(s); } }
democluster.xml:
<infinispan xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="urn:infinispan:config:6.0 http://www.infinispan.org/schemas/infinispan-config-6.0.xsd" xmlns="urn:infinispan:config:6.0"> <global> <transport> <properties> <property name="configurationfile" value="jgroups-tcp.xml" /> </properties> </transport> </global> <default> <clustering mode="distributed" > <sync/> <hash numowners="1" numsegments="100" capacityfactor="1"> <groups enabled="true"> <grouper class="kxgrouper"/> </groups> </hash> </clustering> </default> </infinispan>
kxgrouper.java:
import org.infinispan.distribution.group.grouper; public class kxgrouper implements grouper<string> { public string computegroup(string key, string group) { string g = locaddr.sim; return g; } public class<string> getkeytype() { return string.class; } }
my implementation based in simple cache implementation example of infinispan. having 2 main issues:
1. when run code in separate jvms, work when "book" command (which invokes collocated key command , cache put command), error says node no longer part of cluster. error looks this:
exception in thread "main" java.lang.illegalstateexception: address sri-pc-4630 no longer in cluster @ org.infinispan.affinity.keyaffinityserviceimpl.getkeyforaddress(keyaffinityserviceimpl.java:107) @ org.infinispan.affinity.keyaffinityserviceimpl.getcollocatedkey(keyaffinityserviceimpl.java:91) @ simplecache.start(simplecache.java:77) @ simplecache.main(simplecache.java:125) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ com.intellij.rt.execution.application.appmain.main(appmain.java:120)
where "address sri-pc-4630" address of manager in jvm running. have been looking online solution issue no 1 seems have similar problem.
2. if running , "book" , have key/value stored in local node, cannot access other node.
i have been trying fix no avail , advice or recommendation appreciated.
Comments
Post a Comment