java - Hazelcast - strategy/algorithm for associating lock keys with map values for lock monitoring? -


i have requirement not find solution using hazelcast imap , ilock constructs.

i need keep track of locks acquired on distributed map ( locks acquired after succesfull imap.trylock(k key) call) . every acquired lock must associated/paired custom object in map tracking. (these custom objects contain application specific locker info monitoring purposes.) want , when lock acquired, associated custom object related lock must automatically put map atomically. , when lock released, associated custom object related lock must automatically evicted atomically .

in other words, want keep track of locker info non released locks correctly.

my first attempt/tendency implement lock utility method below:

public boolean trylockutilmethod(string key, long maxtimetowaitforthelockinmilis) {         boolean islockacquired = false;         try {             islockacquired = imap.trylock(key, maxtimetowaitforthelockinmilis, timeunit.milliseconds);         } catch (exception e) {             ...         }          if (islockacquired) {             putlockinfotomapafterlockacquire(key);          }     } 

and unlock utility method below:

public void unlockutilmethod(string key) {              boolean isunlocksuccess = false;              try {                 imap.unlock(key);                 isunlocksuccess = true;             } catch (illegalmonitorstateexception e) {                 // current thread not hold lock                 ...             } catch (exception ex) {                 ...             }              if (isunlocksuccess) {                 removelockinfoafterunlocksuccess(key);             }         } 

apparently approach prone errors because lock acquire/release operations , subsequent map put (in sample code putlockinfotomapafterlockacquire method) / remove (in sample code removelockinfoafterunlocksuccess method) operations not atomic...

i not figure out solution using hazelcast concurrent constructs.

what correct way keep lock related info , ensure synch locks? did not have similar requirement before?

any guidance appreciated

afaik there no direct support on api level traversing or getting info locks obtained imap interface.so think way of doing correct. , syncing lock info , lock can use hazelcast transactions.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -