1 19 package org.openide.filesystems; 20 21 import java.io.ByteArrayOutputStream ; 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 25 26 43 public class FileLock extends Object { 44 46 49 public static final FileLock NONE = new FileLock() { 50 51 public boolean isValid() { 52 return false; 53 } 54 }; 55 56 57 private boolean locked = true; 58 private Throwable lockedBy; 59 60 public FileLock() { 61 assert (lockedBy = new Throwable ()) != null; 62 } 63 64 67 76 77 81 84 public void releaseLock() { 85 locked = false; 86 } 87 88 91 94 public boolean isValid() { 95 return locked; 96 } 97 98 101 public void finalize() { 102 assert (!isValid()) : assertMessageForInvalidLocks(); 103 releaseLock(); 104 } 105 106 private String assertMessageForInvalidLocks() { 107 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 108 109 if (lockedBy != null) { 110 Logger.getLogger(FileLock.class.getName()).log(Level.WARNING, null, 111 new Exception ("Not released lock for file: " + 112 toString() + 113 " (traped in finalizer)").initCause(lockedBy)); } 115 116 releaseLock(); 117 return bos.toString(); 118 } 119 } 120 | Popular Tags |