public boolean lock ( String id ) { File file = new File ( directory , String . format ( ".%s.lock" , prefix ) ) ; try { if ( file . createNewFile ( ) ) { try ( FileBuffer buffer = FileBuffer . allocate ( file ) ) { buffer . writeString ( id ) . flush ( ) ; } return true ; } else { try ( FileBuffer buffer = FileBuffer . allocate ( file ) ) { String lock = buffer . readString ( ) ; return lock != null && lock . equals ( id ) ; } } } catch ( IOException e ) { throw new StorageException ( "Failed to acquire storage lock" ) ; } }
Attempts to acquire a lock on the storage directory .