Lines 18-28
Link Here
|
18 |
*/ |
18 |
*/ |
19 |
package org.openide.filesystems; |
19 |
package org.openide.filesystems; |
20 |
|
20 |
|
21 |
import java.io.ByteArrayOutputStream; |
|
|
22 |
import java.util.logging.Level; |
23 |
import java.util.logging.Logger; |
24 |
|
21 |
|
25 |
|
|
|
26 |
/** Represents an acquired lock on a <code>FileObject</code>. |
22 |
/** Represents an acquired lock on a <code>FileObject</code>. |
27 |
* Typical usage includes locking the file in the editor on first |
23 |
* Typical usage includes locking the file in the editor on first |
28 |
* modification, and then using this object to ensure exclusive access when |
24 |
* modification, and then using this object to ensure exclusive access when |
Lines 55-64
Link Here
|
55 |
|
51 |
|
56 |
/** Determines if lock is locked or if it was released. */ |
52 |
/** Determines if lock is locked or if it was released. */ |
57 |
private boolean locked = true; |
53 |
private boolean locked = true; |
58 |
private Throwable lockedBy; |
|
|
59 |
|
54 |
|
60 |
public FileLock() { |
55 |
public FileLock() { |
61 |
assert (lockedBy = new Throwable()) != null; |
|
|
62 |
} |
56 |
} |
63 |
|
57 |
|
64 |
// =============================================================================== |
58 |
// =============================================================================== |
Lines 94-119
Link Here
|
94 |
public boolean isValid() { |
88 |
public boolean isValid() { |
95 |
return locked; |
89 |
return locked; |
96 |
} |
90 |
} |
97 |
|
|
|
98 |
/** Finalize this object. Calls {@link #releaseLock} to release the lock if the program |
99 |
* for some reason failed to. |
100 |
*/ |
101 |
public void finalize() { |
102 |
assert (!isValid()) : assertMessageForInvalidLocks(); |
103 |
releaseLock(); |
104 |
} |
91 |
} |
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));//NOI18N |
114 |
} |
115 |
|
116 |
releaseLock(); |
117 |
return bos.toString(); |
118 |
} |
119 |
} |