Reputation: 2797
I am using Hazelcast Imap interface to lock items in a distributed way.Instead of putting item in map I just call lock method which seem to be working but I don't know how to query which items are locked currently since items are not available in the map.Is there a way to query hazelcast about locked keys? Here is the example code: public void testMap_DistributedLock() { final Config hazelcastConfig = new Config(); int numberOfRecords = 100;
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(hazelcastConfig);
//monitorCluster(instance1);
IMap<Integer, Integer> myMap = instance1.getMap("myMap");
System.err.println("starting lock");
int index = 0;
while(index<numberOfRecords){
myMap.lock(index++);
}
System.err.println("After locking index is: " +index);
System.err.println("myMap.size()=" + myMap.size());
}
and output is :
starting lock
After locking index is: 100
myMap.size()=0
PS:Using java7 with Hazelcast 3.6
Upvotes: 1
Views: 633
Reputation: 6094
There is no API like IMap::getLocks but you can iterate through all known locks using IMap::isLocked and collect keys that are still being locked. If you really want some getLocks method please go ahead and file a feature request on github.
Upvotes: 2