public static String refreshLock ( EntityManager em , long type , String key , String note ) { EntityTransaction tx = null ; /* refresh the existing lock if it matches the key. */ try { tx = em . getTransaction ( ) ; tx . begin ( ) ; GlobalInterlock lock = _findAndRefreshLock ( em , type ) ; if ( lock == null ) { throw new GlobalInterlockException ( "No lock of type " + type + " exists for key " + key + "." ) ; } String ref = Long . toHexString ( lock . lockTime ) ; if ( ref . equalsIgnoreCase ( key ) ) { lock . lockTime = System . currentTimeMillis ( ) ; lock . note = note ; em . merge ( lock ) ; em . flush ( ) ; tx . commit ( ) ; return Long . toHexString ( lock . lockTime ) ; } throw new GlobalInterlockException ( "This process doesn't own the type " + type + " lock having key " + key + "." ) ; } finally { if ( tx != null && tx . isActive ( ) ) { tx . rollback ( ) ; } } }
Refreshes a global lock of the indicated type if the supplied key is a match for the lock .