author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 18574 | 4aeaeb541678 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18574
diff
changeset
|
2 |
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.nio.channels; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
||
30 |
/** |
|
31 |
* A token representing a lock on a region of a file. |
|
32 |
* |
|
33 |
* <p> A file-lock object is created each time a lock is acquired on a file via |
|
34 |
* one of the {@link FileChannel#lock(long,long,boolean) lock} or {@link |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
35 |
* FileChannel#tryLock(long,long,boolean) tryLock} methods of the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
36 |
* {@link FileChannel} class, or the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
37 |
* AsynchronousFileChannel#lock(long,long,boolean,Object,CompletionHandler) lock} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
38 |
* or {@link AsynchronousFileChannel#tryLock(long,long,boolean) tryLock} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
39 |
* methods of the {@link AsynchronousFileChannel} class. |
2 | 40 |
* |
41 |
* <p> A file-lock object is initially valid. It remains valid until the lock |
|
42 |
* is released by invoking the {@link #release release} method, by closing the |
|
43 |
* channel that was used to acquire it, or by the termination of the Java |
|
44 |
* virtual machine, whichever comes first. The validity of a lock may be |
|
45 |
* tested by invoking its {@link #isValid isValid} method. |
|
46 |
* |
|
47 |
* <p> A file lock is either <i>exclusive</i> or <i>shared</i>. A shared lock |
|
48 |
* prevents other concurrently-running programs from acquiring an overlapping |
|
49 |
* exclusive lock, but does allow them to acquire overlapping shared locks. An |
|
50 |
* exclusive lock prevents other programs from acquiring an overlapping lock of |
|
51 |
* either type. Once it is released, a lock has no further effect on the locks |
|
52 |
* that may be acquired by other programs. |
|
53 |
* |
|
54 |
* <p> Whether a lock is exclusive or shared may be determined by invoking its |
|
55 |
* {@link #isShared isShared} method. Some platforms do not support shared |
|
56 |
* locks, in which case a request for a shared lock is automatically converted |
|
57 |
* into a request for an exclusive lock. |
|
58 |
* |
|
59 |
* <p> The locks held on a particular file by a single Java virtual machine do |
|
60 |
* not overlap. The {@link #overlaps overlaps} method may be used to test |
|
61 |
* whether a candidate lock range overlaps an existing lock. |
|
62 |
* |
|
63 |
* <p> A file-lock object records the file channel upon whose file the lock is |
|
64 |
* held, the type and validity of the lock, and the position and size of the |
|
65 |
* locked region. Only the validity of a lock is subject to change over time; |
|
66 |
* all other aspects of a lock's state are immutable. |
|
67 |
* |
|
68 |
* <p> File locks are held on behalf of the entire Java virtual machine. |
|
69 |
* They are not suitable for controlling access to a file by multiple |
|
70 |
* threads within the same virtual machine. |
|
71 |
* |
|
72 |
* <p> File-lock objects are safe for use by multiple concurrent threads. |
|
73 |
* |
|
74 |
* |
|
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18164
diff
changeset
|
75 |
* <a name="pdep"></a><h2> Platform dependencies </h2> |
2 | 76 |
* |
77 |
* <p> This file-locking API is intended to map directly to the native locking |
|
78 |
* facility of the underlying operating system. Thus the locks held on a file |
|
79 |
* should be visible to all programs that have access to the file, regardless |
|
80 |
* of the language in which those programs are written. |
|
81 |
* |
|
82 |
* <p> Whether or not a lock actually prevents another program from accessing |
|
83 |
* the content of the locked region is system-dependent and therefore |
|
84 |
* unspecified. The native file-locking facilities of some systems are merely |
|
85 |
* <i>advisory</i>, meaning that programs must cooperatively observe a known |
|
86 |
* locking protocol in order to guarantee data integrity. On other systems |
|
87 |
* native file locks are <i>mandatory</i>, meaning that if one program locks a |
|
88 |
* region of a file then other programs are actually prevented from accessing |
|
89 |
* that region in a way that would violate the lock. On yet other systems, |
|
90 |
* whether native file locks are advisory or mandatory is configurable on a |
|
91 |
* per-file basis. To ensure consistent and correct behavior across platforms, |
|
92 |
* it is strongly recommended that the locks provided by this API be used as if |
|
93 |
* they were advisory locks. |
|
94 |
* |
|
95 |
* <p> On some systems, acquiring a mandatory lock on a region of a file |
|
96 |
* prevents that region from being {@link java.nio.channels.FileChannel#map |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
97 |
* <i>mapped into memory</i>}, and vice versa. Programs that combine |
2 | 98 |
* locking and mapping should be prepared for this combination to fail. |
99 |
* |
|
100 |
* <p> On some systems, closing a channel releases all locks held by the Java |
|
101 |
* virtual machine on the underlying file regardless of whether the locks were |
|
102 |
* acquired via that channel or via another channel open on the same file. It |
|
103 |
* is strongly recommended that, within a program, a unique channel be used to |
|
104 |
* acquire all locks on any given file. |
|
105 |
* |
|
106 |
* <p> Some network filesystems permit file locking to be used with |
|
107 |
* memory-mapped files only when the locked regions are page-aligned and a |
|
108 |
* whole multiple of the underlying hardware's page size. Some network |
|
109 |
* filesystems do not implement file locks on regions that extend past a |
|
110 |
* certain position, often 2<sup>30</sup> or 2<sup>31</sup>. In general, great |
|
111 |
* care should be taken when locking files that reside on network filesystems. |
|
112 |
* |
|
113 |
* |
|
114 |
* @author Mark Reinhold |
|
115 |
* @author JSR-51 Expert Group |
|
116 |
* @since 1.4 |
|
117 |
*/ |
|
118 |
||
5972
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
119 |
public abstract class FileLock implements AutoCloseable { |
2 | 120 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
121 |
private final Channel channel; |
2 | 122 |
private final long position; |
123 |
private final long size; |
|
124 |
private final boolean shared; |
|
125 |
||
126 |
/** |
|
18164 | 127 |
* Initializes a new instance of this class. |
2 | 128 |
* |
129 |
* @param channel |
|
130 |
* The file channel upon whose file this lock is held |
|
131 |
* |
|
132 |
* @param position |
|
133 |
* The position within the file at which the locked region starts; |
|
134 |
* must be non-negative |
|
135 |
* |
|
136 |
* @param size |
|
137 |
* The size of the locked region; must be non-negative, and the sum |
|
138 |
* <tt>position</tt> + <tt>size</tt> must be non-negative |
|
139 |
* |
|
140 |
* @param shared |
|
141 |
* <tt>true</tt> if this lock is shared, |
|
142 |
* <tt>false</tt> if it is exclusive |
|
143 |
* |
|
144 |
* @throws IllegalArgumentException |
|
145 |
* If the preconditions on the parameters do not hold |
|
146 |
*/ |
|
147 |
protected FileLock(FileChannel channel, |
|
148 |
long position, long size, boolean shared) |
|
149 |
{ |
|
150 |
if (position < 0) |
|
151 |
throw new IllegalArgumentException("Negative position"); |
|
152 |
if (size < 0) |
|
153 |
throw new IllegalArgumentException("Negative size"); |
|
154 |
if (position + size < 0) |
|
155 |
throw new IllegalArgumentException("Negative position + size"); |
|
156 |
this.channel = channel; |
|
157 |
this.position = position; |
|
158 |
this.size = size; |
|
159 |
this.shared = shared; |
|
160 |
} |
|
161 |
||
162 |
/** |
|
3631 | 163 |
* Initializes a new instance of this class. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
164 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
165 |
* @param channel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
166 |
* The channel upon whose file this lock is held |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
167 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
168 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
169 |
* The position within the file at which the locked region starts; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
170 |
* must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
171 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
172 |
* @param size |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
173 |
* The size of the locked region; must be non-negative, and the sum |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
174 |
* <tt>position</tt> + <tt>size</tt> must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
175 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
176 |
* @param shared |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
177 |
* <tt>true</tt> if this lock is shared, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
178 |
* <tt>false</tt> if it is exclusive |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
179 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
180 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
181 |
* If the preconditions on the parameters do not hold |
2 | 182 |
* |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
183 |
* @since 1.7 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
184 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
185 |
protected FileLock(AsynchronousFileChannel channel, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
186 |
long position, long size, boolean shared) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
187 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
188 |
if (position < 0) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
189 |
throw new IllegalArgumentException("Negative position"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
190 |
if (size < 0) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
191 |
throw new IllegalArgumentException("Negative size"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
192 |
if (position + size < 0) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
193 |
throw new IllegalArgumentException("Negative position + size"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
194 |
this.channel = channel; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
195 |
this.position = position; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
196 |
this.size = size; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
197 |
this.shared = shared; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
198 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
199 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
200 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
201 |
* Returns the file channel upon whose file this lock was acquired. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
202 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
203 |
* <p> This method has been superseded by the {@link #acquiredBy acquiredBy} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
204 |
* method. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
205 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
206 |
* @return The file channel, or {@code null} if the file lock was not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
207 |
* acquired by a file channel. |
2 | 208 |
*/ |
209 |
public final FileChannel channel() { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
210 |
return (channel instanceof FileChannel) ? (FileChannel)channel : null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
211 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
212 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
213 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
214 |
* Returns the channel upon whose file this lock was acquired. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
215 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
216 |
* @return The channel upon whose file this lock was acquired. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
217 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
218 |
* @since 1.7 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
219 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
220 |
public Channel acquiredBy() { |
2 | 221 |
return channel; |
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Returns the position within the file of the first byte of the locked |
|
226 |
* region. |
|
227 |
* |
|
228 |
* <p> A locked region need not be contained within, or even overlap, the |
|
229 |
* actual underlying file, so the value returned by this method may exceed |
|
230 |
* the file's current size. </p> |
|
231 |
* |
|
232 |
* @return The position |
|
233 |
*/ |
|
234 |
public final long position() { |
|
235 |
return position; |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Returns the size of the locked region in bytes. |
|
240 |
* |
|
241 |
* <p> A locked region need not be contained within, or even overlap, the |
|
242 |
* actual underlying file, so the value returned by this method may exceed |
|
243 |
* the file's current size. </p> |
|
244 |
* |
|
245 |
* @return The size of the locked region |
|
246 |
*/ |
|
247 |
public final long size() { |
|
248 |
return size; |
|
249 |
} |
|
250 |
||
251 |
/** |
|
18164 | 252 |
* Tells whether this lock is shared. |
2 | 253 |
* |
254 |
* @return <tt>true</tt> if lock is shared, |
|
255 |
* <tt>false</tt> if it is exclusive |
|
256 |
*/ |
|
257 |
public final boolean isShared() { |
|
258 |
return shared; |
|
259 |
} |
|
260 |
||
261 |
/** |
|
18164 | 262 |
* Tells whether or not this lock overlaps the given lock range. |
2 | 263 |
* |
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18164
diff
changeset
|
264 |
* @param position |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18164
diff
changeset
|
265 |
* The starting position of the lock range |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18164
diff
changeset
|
266 |
* @param size |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18164
diff
changeset
|
267 |
* The size of the lock range |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
18164
diff
changeset
|
268 |
* |
2 | 269 |
* @return <tt>true</tt> if, and only if, this lock and the given lock |
270 |
* range overlap by at least one byte |
|
271 |
*/ |
|
272 |
public final boolean overlaps(long position, long size) { |
|
273 |
if (position + size <= this.position) |
|
274 |
return false; // That is below this |
|
275 |
if (this.position + this.size <= position) |
|
276 |
return false; // This is below that |
|
277 |
return true; |
|
278 |
} |
|
279 |
||
280 |
/** |
|
281 |
* Tells whether or not this lock is valid. |
|
282 |
* |
|
283 |
* <p> A lock object remains valid until it is released or the associated |
|
284 |
* file channel is closed, whichever comes first. </p> |
|
285 |
* |
|
286 |
* @return <tt>true</tt> if, and only if, this lock is valid |
|
287 |
*/ |
|
288 |
public abstract boolean isValid(); |
|
289 |
||
290 |
/** |
|
291 |
* Releases this lock. |
|
292 |
* |
|
293 |
* <p> If this lock object is valid then invoking this method releases the |
|
294 |
* lock and renders the object invalid. If this lock object is invalid |
|
295 |
* then invoking this method has no effect. </p> |
|
296 |
* |
|
297 |
* @throws ClosedChannelException |
|
298 |
* If the channel that was used to acquire this lock |
|
299 |
* is no longer open |
|
300 |
* |
|
301 |
* @throws IOException |
|
302 |
* If an I/O error occurs |
|
303 |
*/ |
|
304 |
public abstract void release() throws IOException; |
|
305 |
||
306 |
/** |
|
5972
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
307 |
* This method invokes the {@link #release} method. It was added |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
308 |
* to the class so that it could be used in conjunction with the |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
309 |
* automatic resource management block construct. |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
310 |
* |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
311 |
* @since 1.7 |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
312 |
*/ |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
313 |
public final void close() throws IOException { |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
314 |
release(); |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
315 |
} |
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
316 |
|
e3f47656e9d9
6911258: Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
darcy
parents:
5506
diff
changeset
|
317 |
/** |
2 | 318 |
* Returns a string describing the range, type, and validity of this lock. |
319 |
* |
|
320 |
* @return A descriptive string |
|
321 |
*/ |
|
322 |
public final String toString() { |
|
323 |
return (this.getClass().getName() |
|
324 |
+ "[" + position |
|
325 |
+ ":" + size |
|
326 |
+ " " + (shared ? "shared" : "exclusive") |
|
327 |
+ " " + (isValid() ? "valid" : "invalid") |
|
328 |
+ "]"); |
|
329 |
} |
|
330 |
||
331 |
} |