I see that Hazelcast 3.12 has introduced the CPSubsystem()
for systems with 3-7 nodes. I understand the reasoning. However, if I am trying to design a solution that can run with anywhere between 1-n nodes, do I need to use different logic to validate if the CPSubsystem is enabled? How do I even check that?
I would have thought/hoped that simply calling
hazelcastInstance.getCPSubsystem().getLock()
would work no matter the number of nodes, but if there are fewer than 3 nodes, it throws an exception. And I can't find any method that allows me to check if the CPSubsystem
is enabled or not.
My current implementation uses the deprecated method getLock()
to get a distributed lock:
LOG.debug("Creating a distributed lock on username for a maximum of 5 minutes {}", username);
ILock usernameLock = hazelcastInstance.getLock(this.getClass().getName() + ":" + username);
try {
if (usernameLock.tryLock (5, TimeUnit.MINUTES)) {
clearUserData(cacheEntryEvent);
}
} catch (InterruptedException e) {
LOG.warn("Exception locking on : {} ", username, e);
LOG.warn("Invoking clearUserData without synchronization : {}", username);
clearUserData(cacheEntryEvent);
} finally {
usernameLock.unlock();
}
How can I get a lock with Hazelcast without knowing this? The hazelcastInstance.getLock()
is marked as deprecated and targeted for removal in HC4.