java - How to show all structure names in hazelcast 3.x -
i found a similar question, it's 2 years ago , previous version, not works in hz 3.x.so, question how achieve in hz 3.x ?
like app1 open lock 1, app2 open lock 2, how can know lock taken ?
found way many tricks,works service
run svr first, run cli , test.
public class playhz { @test public void test() throws executionexception, interruptedexception { hazelcastinstance hz = hazelcast.newhazelcastinstance(); iexecutorservice executor = hz.getexecutorservice("gather"); map<member, future<list<string>>> futures = executor.submittoallmembers(new locknamegather()); thread.sleep(1000); system.out.println("found in member"); (map.entry<member, future<list<string>>> entry : futures.entryset()) { system.out.printf("%s -> %s\n", entry.getkey(), entry.getvalue().get()); } } @test public void svr() throws interruptedexception { hazelcastinstance hz = hazelcast.newhazelcastinstance(); thread.sleep(integer.max_value); } @test public void cli() throws interruptedexception { hazelcastinstance hz = hazelcast.newhazelcastinstance(); (int = 0; < 100; i++) { ilock lock = hz.getlock("lock" + i); lock.lock(); } thread.sleep(integer.max_value); } private static class locknamegather implements callable<list<string>>, hazelcastinstanceaware, serializable { transient hazelcastinstance hz; transient nodeengineimpl node; @override public list<string> call() throws exception { node = ((hazelcastinstanceimpl) hz).node.getnodeengine(); lockservice svc = node.getservice(lockservice.service_name); return svc.getalllocks() .stream() .map(lockresource::getkey) .map(d -> node.getserializationservice().createobjectdatainput(d)) .map((r) -> { try { return r.readutf(); } catch (ioexception e) { throw new runtimeexception(e); } }).collect(collectors.tolist()); } @override public void sethazelcastinstance(hazelcastinstance hazelcastinstance) { hz = hazelcastinstance; } } }
Comments
Post a Comment