java.nio.channels.FileLock#isValid()源码实例Demo

下面列出了java.nio.channels.FileLock#isValid() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ACDD   文件: OpenAtlasFileLock.java
/**
 * lock odex
 *
 * @param bundleDexFile optimize dex file
 **/
public boolean LockExclusive(File bundleDexFile) {

    if (bundleDexFile == null) {
        return false;
    }
    try {
        File lockFile = new File(bundleDexFile.getParentFile().getAbsolutePath().concat("/lock"));
        if (!lockFile.exists()) {
            lockFile.createNewFile();
        }
        RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile.getAbsolutePath(), "rw");
        FileChannel channel = randomAccessFile.getChannel();
        FileLock lock = channel.lock();
        if (!lock.isValid()) {
            return false;
        }
        RefCntInc(lockFile.getAbsolutePath(), lock, randomAccessFile, channel);
        return true;
    } catch (Exception e) {
        log.error(processName + " FileLock " + bundleDexFile.getParentFile().getAbsolutePath().concat("/lock") + " Lock FAIL! " + e.getMessage());
        return false;
    }
}
 
源代码2 项目: AtlasForAndroid   文件: AtlasFileLock.java
public boolean LockExclusive(File file) {
    if (file == null) {
        return false;
    }
    try {
        FileChannel channel = new RandomAccessFile(file.getAbsolutePath(), "rw").getChannel();
        if (channel == null) {
            return false;
        }
        Log.i(TAG, processName + " attempting to FileLock " + file);
        FileLock lock = channel.lock();
        if (!lock.isValid()) {
            return false;
        }
        RefCntInc(file.getAbsolutePath(), lock);
        Log.i(TAG, processName + " FileLock " + file + " Suc! ");
        return true;
    } catch (Exception e) {
        Log.e(TAG, processName + " FileLock " + file + " FAIL! " + e.getMessage());
        return false;
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码4 项目: TencentKona-8   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码5 项目: jdk8u60   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码6 项目: openjdk-jdk8u   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码7 项目: openjdk-jdk8u-backup   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码8 项目: Bytecoder   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    if (!fd.valid())
        return; // nothing to do

    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else if (closer != null) {
        // Perform the cleaning action so it is not redone when
        // this channel becomes phantom reachable.
        try {
            closer.clean();
        } catch (UncheckedIOException uioe) {
            throw uioe.getCause();
        }
    } else {
        fdAccess.close(fd);
    }

}
 
源代码9 项目: openjdk-jdk9   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    if (!fd.valid())
        return; // nothing to do

    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码10 项目: jdk8u-jdk   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码11 项目: hottub   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码12 项目: gemfirexd-oss   文件: DiskStoreImpl.java
void closeLockFile() {
  FileLock myfl = this.fl;
  if (myfl != null) {
    try {
      FileChannel fc = myfl.channel();
      if (myfl.isValid()) {
        myfl.release();
      }
      fc.close();
    } catch (IOException ignore) {
    }
    this.fl = null;
  }
  File f = this.lockFile;
  if (f != null) {
    if (f.delete()) {
      if (logger.fineEnabled()) {
        logger.fine("Deleted lock file " + f);
      }
    } else if (f.exists()) {
      if (logger.fineEnabled()) {
        logger.fine("Could not delete lock file " + f);
      }
    }
  }
  logger.info(LocalizedStrings.DEBUG, "Unlocked disk store " + name); // added
                                                                      // to
                                                                      // help
                                                                      // debug
                                                                      // 41734
}
 
源代码13 项目: jdk8u_jdk   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码14 项目: ACDD   文件: OpenAtlasFileLock.java
/**
 * unlock odex file
 **/
public void unLock(File bundleDexFile) {

    File lockFile = new File(bundleDexFile.getParentFile().getAbsolutePath().concat("/lock"));
    if (!lockFile.exists()) {
        return;
    }
    if (lockFile == null || this.mRefCountMap.containsKey(lockFile.getAbsolutePath())) {
        FileLockCount fileLockCount = this.mRefCountMap.get(lockFile.getAbsolutePath());
        if (fileLockCount != null) {
            FileLock fileLock = fileLockCount.mFileLock;
            RandomAccessFile randomAccessFile = fileLockCount.fOs;
            FileChannel fileChannel = fileLockCount.fChannel;
            try {
                if (RefCntDec(lockFile.getAbsolutePath()) <= 0) {
                    if (fileLock != null && fileLock.isValid()) {
                        fileLock.release();
                    }
                    if (randomAccessFile != null) {
                        randomAccessFile.close();
                    }
                    if (fileChannel != null) {
                        fileChannel.close();
                    }
                }
            } catch (IOException e) {
                log.error(processName + " FileLock " + bundleDexFile.getParentFile().getAbsolutePath().concat("/lock") + " unlock FAIL! " + e.getMessage());
            }
        }
    }
}
 
源代码15 项目: gemfirexd-oss   文件: DiskStoreImpl.java
void closeLockFile() {
  FileLock myfl = this.fl;
  if (myfl != null) {
    try {
      FileChannel fc = myfl.channel();
      if (myfl.isValid()) {
        myfl.release();
      }
      fc.close();
    } catch (IOException ignore) {
    }
    this.fl = null;
  }
  File f = this.lockFile;
  if (f != null) {
    if (f.delete()) {
      if (logger.fineEnabled()) {
        logger.fine("Deleted lock file " + f);
      }
    } else if (f.exists()) {
      if (logger.fineEnabled()) {
        logger.fine("Could not delete lock file " + f);
      }
    }
  }
  logger.info(LocalizedStrings.DEBUG, "Unlocked disk store " + name); // added
                                                                      // to
                                                                      // help
                                                                      // debug
                                                                      // 41734
}
 
源代码16 项目: jdk8u-jdk   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码17 项目: jdk8u-dev-jdk   文件: FileChannelImpl.java
protected void implCloseChannel() throws IOException {
    // Release and invalidate any locks that we still hold
    if (fileLockTable != null) {
        for (FileLock fl: fileLockTable.removeAll()) {
            synchronized (fl) {
                if (fl.isValid()) {
                    nd.release(fd, fl.position(), fl.size());
                    ((FileLockImpl)fl).invalidate();
                }
            }
        }
    }

    // signal any threads blocked on this channel
    threads.signalAndWait();

    if (parent != null) {

        // Close the fd via the parent stream's close method.  The parent
        // will reinvoke our close method, which is defined in the
        // superclass AbstractInterruptibleChannel, but the isOpen logic in
        // that method will prevent this method from being reinvoked.
        //
        ((java.io.Closeable)parent).close();
    } else {
        nd.close(fd);
    }

}
 
源代码18 项目: AtlasForAndroid   文件: AtlasFileLock.java
public void unLock(File file) {
    if (file == null || this.mRefCountMap.containsKey(file.getAbsolutePath())) {
        FileLock fileLock = ((FileLockCount) this.mRefCountMap.get(file.getAbsolutePath())).mFileLock;
        if (fileLock != null && fileLock.isValid()) {
            try {
                if (RefCntDec(file.getAbsolutePath()) <= 0) {
                    fileLock.release();
                    Log.i(TAG, processName + " FileLock " + file.getAbsolutePath() + " SUC! ");
                }
            } catch (IOException e) {
            }
        }
    }
}
 
源代码19 项目: tez   文件: Fetcher.java
private void releaseLock(FileLock lock) throws IOException {
  if (lock != null && lock.isValid()) {
    FileChannel lockChannel = lock.channel();
    lock.release();
    lockChannel.close();
  }
}
 
 方法所在类