< prev index next >

src/java.base/share/classes/sun/nio/ch/FileLockImpl.java

Print this page

        

@@ -29,29 +29,35 @@
 import java.nio.channels.*;
 
 public class FileLockImpl
     extends FileLock
 {
-    private volatile boolean invalid;
+    private final FileLockState state;
 
     FileLockImpl(FileChannel channel, long position, long size, boolean shared)
     {
         super(channel, position, size, shared);
+        state = new FileLockState(position, size);
     }
 
     FileLockImpl(AsynchronousFileChannel channel, long position, long size, boolean shared)
     {
         super(channel, position, size, shared);
+        state = new FileLockState(position, size);
+    }
+
+    FileLockState getState() {
+        return state;
     }
 
     public boolean isValid() {
-        return !invalid;
+        return state.isValid();
     }
 
     void invalidate() {
         assert Thread.holdsLock(this);
-        invalid = true;
+        state.invalidate();
     }
 
     public synchronized void release() throws IOException {
         Channel ch = acquiredBy();
         if (!ch.isOpen())

@@ -60,9 +66,9 @@
             if (ch instanceof FileChannelImpl)
                 ((FileChannelImpl)ch).release(this);
             else if (ch instanceof AsynchronousFileChannelImpl)
                 ((AsynchronousFileChannelImpl)ch).release(this);
             else throw new AssertionError();
-            invalidate();
+            state.invalidate();
         }
     }
 }
< prev index next >