Reputation: 97
There are two nodes in hazelcast cluster. i am trying to get cache from map which may be store on second node.In case of network failure it will go into wait loop while getting cache from map. Is there any way to detect immediate network failure while getting cache from map instead of waiting . I have tried tryLock before calling get ,which return immediate true or false but not sure it will work in all cases.
Upvotes: 0
Views: 481
Reputation: 591
What IMap.tryLock
does is to invoke a LockOperation with 0 timeout, so that if there is a network partition it will return right away.
You can achieve similar scenario using IMap.getAsync(key)
which returns ICompletableFuture
object.
Then use ICompletableFuture.get(timeout, timeUnit)
to set a timeout for getting entry from map.
Network partitions are detected via heartbeats. When a member doesn't send heartbeats for a certain timeout, it is considered dead. So there is no immediate way to detect network partitions but you can configure the behavior via hazelcast.heartbeat.interval.seconds
and hazelcast.max.no.heartbeat.seconds
properties. (see System Properties in Hazelcast Docs)
Upvotes: 1