< prev index next >

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

Print this page

        

@@ -30,61 +30,18 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.lang.ref.*;
 import java.io.FileDescriptor;
 import java.io.IOException;
 
-abstract class FileLockTable {
-    protected FileLockTable() {
-    }
-
-    /**
-     * Creates and returns a file lock table for a channel that is connected to
-     * the a system-wide map of all file locks for the Java virtual machine.
-     */
-    public static FileLockTable newSharedFileLockTable(Channel channel,
-                                                       FileDescriptor fd)
-        throws IOException
-    {
-        return new SharedFileLockTable(channel, fd);
-    }
-
-    /**
-     * Adds a file lock to the table.
-     *
-     * @throws OverlappingFileLockException if the file lock overlaps
-     *         with an existing file lock in the table
-     */
-    public abstract void add(FileLock fl) throws OverlappingFileLockException;
-
-    /**
-     * Remove an existing file lock from the table.
-     */
-    public abstract void remove(FileLock fl);
-
-    /**
-     * Removes all file locks from the table.
-     *
-     * @return  The list of file locks removed
-     */
-    public abstract List<FileLock> removeAll();
-
-    /**
-     * Replaces an existing file lock in the table.
-     */
-    public abstract void replace(FileLock fl1, FileLock fl2);
-}
-
-
 /**
  * A file lock table that is over a system-wide map of all file locks.
  */
-class SharedFileLockTable extends FileLockTable {
-
+class FileLockTable {
     /**
      * A weak reference to a FileLock.
      * <p>
-     * SharedFileLockTable uses a list of file lock references to avoid keeping the
+     * FileLockTable uses a list of file lock references to avoid keeping the
      * FileLock (and FileChannel) alive.
      */
     private static class FileLockReference extends WeakReference<FileLock> {
         private FileKey fileKey;
 

@@ -116,17 +73,27 @@
     private final FileKey fileKey;
 
     // Locks obtained for this channel
     private final Set<FileLock> locks;
 
-    SharedFileLockTable(Channel channel, FileDescriptor fd) throws IOException {
+    /**
+     * Creates and returns a file lock table for a channel that is connected to
+     * the a system-wide map of all file locks for the Java virtual machine.
+     */
+    public static FileLockTable newFileLockTable(Channel channel,
+                                                 FileDescriptor fd)
+        throws IOException
+    {
+        return new FileLockTable(channel, fd);
+    }
+
+    FileLockTable(Channel channel, FileDescriptor fd) throws IOException {
         this.channel = channel;
         this.fileKey = FileKey.create(fd);
         this.locks = ConcurrentHashMap.newKeySet();
     }
 
-    @Override
     public void add(FileLock fl) throws OverlappingFileLockException {
         List<FileLockReference> list = lockMap.get(fileKey);
 
         for (;;) {
 

@@ -174,11 +141,10 @@
         if (list.isEmpty()) {
             lockMap.remove(fk);
         }
     }
 
-    @Override
     public void remove(FileLock fl) {
         assert fl != null;
 
         // the lock must exist so the list of locks must be present
         List<FileLockReference> list = lockMap.get(fileKey);

@@ -199,11 +165,10 @@
                 index++;
             }
         }
     }
 
-    @Override
     public List<FileLock> removeAll() {
         List<FileLock> result = new ArrayList<FileLock>();
         List<FileLockReference> list = lockMap.get(fileKey);
         if (list != null) {
             synchronized (list) {

@@ -231,11 +196,10 @@
             }
         }
         return result;
     }
 
-    @Override
     public void replace(FileLock fromLock, FileLock toLock) {
         // the lock must exist so there must be a list
         List<FileLockReference> list = lockMap.get(fileKey);
         assert list != null;
 
< prev index next >