本文整理了Java中java.nio.channels.FileLock.isValid()
方法的一些代码示例,展示了FileLock.isValid()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileLock.isValid()
方法的具体详情如下:
包路径:java.nio.channels.FileLock
类名称:FileLock
方法名:isValid
[英]Indicates whether this lock is a valid file lock. The lock is valid unless the underlying channel has been closed or it has been explicitly released.
[中]指示此锁是否为有效的文件锁。除非基础通道已关闭或已显式释放,否则锁是有效的。
代码示例来源:origin: stanfordnlp/CoreNLP
public synchronized boolean isActive() {
if (licenses == 0) { assert lock == null || !lock.isValid(); }
if (licenses != 0 && lock != null) { assert lock.isValid(); }
return licenses != 0;
}
代码示例来源:origin: com.h2database/h2
@Override
public boolean isValid() {
return base.isValid();
}
代码示例来源:origin: apache/ignite
/** Locked or not. */
public boolean isLocked() {
return lock != null && lock.isValid();
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Determine if the lock is currently held.
*
* @return true if the lock is currently held
*/
public boolean isLocked() {
return lock != null && lock.isValid();
}
代码示例来源:origin: javamelody/javamelody
void release() throws IOException {
try {
if (fileLock != null && fileLock.isValid()) {
fileLock.release();
}
} finally {
try {
if (fileChannel != null) {
fileChannel.close();
}
} finally {
if (input != null) {
input.close();
}
}
}
}
代码示例来源:origin: apache/activemq
public boolean keepAlive() {
locked = locked && lock != null && lock.isValid() && !hasBeenModified();
return locked;
}
代码示例来源:origin: spotify/helios
public void release() {
if (!lock.isValid()) {
log.debug("lock already released: {}", path);
return;
}
try {
lock.release();
} catch (Exception e) {
log.warn("caught exception releasing port lock: {}", path, e);
}
try {
file.close();
} catch (Exception e) {
log.warn("caught exception closing port lock file: {}", path, e);
}
try {
Files.deleteIfExists(path);
} catch (Exception e) {
log.warn("caught exception deleting port lock file: {}", path, e);
}
}
}
代码示例来源:origin: android-hacker/VirtualXposed
public boolean LockExclusive(File targetFile) {
if (targetFile == null) {
return false;
}
try {
File lockFile = new File(targetFile.getParentFile().getAbsolutePath().concat("/lock"));
if (!lockFile.exists()) {
lockFile.createNewFile();
}
RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile.getAbsolutePath(), "rw");
FileChannel channel = randomAccessFile.getChannel();
java.nio.channels.FileLock lock = channel.lock();
if (!lock.isValid()) {
return false;
}
RefCntInc(lockFile.getAbsolutePath(), lock, randomAccessFile, channel);
return true;
} catch (Exception e) {
return false;
}
}
代码示例来源:origin: android-hacker/VirtualXposed
try {
if (RefCntDec(lockFile.getAbsolutePath()) <= 0) {
if (fileLock != null && fileLock.isValid()) {
fileLock.release();
代码示例来源:origin: apache/geode
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.isDebugEnabled()) {
logger.debug("Deleted lock file {}", f);
}
} else if (f.exists()) {
if (logger.isDebugEnabled()) {
logger.debug("Could not delete lock file {}", f);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Unlocked disk store {}", name);
}
}
代码示例来源:origin: javamelody/javamelody
boolean isAcquired() {
return getFileLock() != null && getFileLock().isValid();
}
}
代码示例来源:origin: geoserver/geoserver
if (!lock.isValid()) {
代码示例来源:origin: jeremylong/DependencyCheck
if (lock == null || !lock.isValid()) {
try {
final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
} while (++ctr < MAX_SLEEP_COUNT && (lock == null || !lock.isValid()));
if (lock == null || !lock.isValid()) {
throw new H2DBLockException("Unable to obtain the update lock, skipping the database update. Skippinig the database update.");
代码示例来源:origin: stanfordnlp/CoreNLP
if (lockOrNull == null || !lockOrNull.isValid()) {
try { Thread.sleep(1000); } catch (InterruptedException e) {
log(e);
代码示例来源:origin: Netflix/Priam
if (lock.isValid()) {
logger.info("Lock on RestoreHookFile acquired");
int countOfProcessStarts = 0;
代码示例来源:origin: apache/rocketmq
/**
* @throws Exception
*/
public void start() throws Exception {
lock = lockFile.getChannel().tryLock(0, 1, false);
if (lock == null || lock.isShared() || !lock.isValid()) {
throw new RuntimeException("Lock failed,MQ already started");
}
lockFile.getChannel().write(ByteBuffer.wrap("lock".getBytes()));
lockFile.getChannel().force(true);
this.flushConsumeQueueService.start();
this.commitLog.start();
this.storeStatsService.start();
if (this.scheduleMessageService != null && SLAVE != messageStoreConfig.getBrokerRole()) {
this.scheduleMessageService.start();
}
if (this.getMessageStoreConfig().isDuplicationEnable()) {
this.reputMessageService.setReputFromOffset(this.commitLog.getConfirmOffset());
} else {
this.reputMessageService.setReputFromOffset(this.commitLog.getMaxOffset());
}
this.reputMessageService.start();
this.haService.start();
this.createTempFile();
this.addScheduleTask();
this.shutdown = false;
}
代码示例来源:origin: org.apache.lucene/lucene-core
@Override
public void ensureValid() throws IOException {
if (closed) {
throw new AlreadyClosedException("Lock instance already released: " + this);
}
// check we are still in the locks map (some debugger or something crazy didn't remove us)
if (!LOCK_HELD.contains(path.toString())) {
throw new AlreadyClosedException("Lock path unexpectedly cleared from map: " + this);
}
// check our lock wasn't invalidated.
if (!lock.isValid()) {
throw new AlreadyClosedException("FileLock invalidated by an external force: " + this);
}
// try to validate the underlying file descriptor.
// this will throw IOException if something is wrong.
long size = channel.size();
if (size != 0) {
throw new AlreadyClosedException("Unexpected lock file size: " + size + ", (lock=" + this + ")");
}
// try to validate the backing file name, that it still exists,
// and has the same creation time as when we obtained the lock.
// if it differs, someone deleted our lock file (and we are ineffective)
FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime();
if (!creationTime.equals(ctime)) {
throw new AlreadyClosedException("Underlying file changed by an external force at " + ctime + ", (lock=" + this + ")");
}
}
代码示例来源:origin: oblac/jodd
@Test
@EnabledOnOs({OS.WINDOWS}) // on windows host, test is successful. on linux host no io-exception is thrown
void testDeleteFileTree_not_successful() throws Exception {
assumeTrue(baseDir_Not_Successful.exists());
assumeTrue(locked_file.exists());
// When you use FileLock, it is purely advisory—acquiring a lock on a file may not stop you from doing anything:
// reading, writing, and deleting a file may all be possible even when another process has acquired a lock.
// Sometimes, a lock might do more than this on a particular platform, but this behavior is unspecified,
// and relying on more than is guaranteed in the class documentation is a recipe for failure.
try (RandomAccessFile randomAccessFile = new RandomAccessFile(locked_file, "rw");
FileLock lock = randomAccessFile.getChannel().lock())
{
assumeTrue(lock.isValid(), locked_file.getAbsolutePath() + " is NOT locked...");
// asserts
IOException expectedException = assertThrows(
IOException.class, () -> PathUtil.deleteFileTree(baseDir_Not_Successful.toPath()));
assertTrue(expectedException instanceof FileSystemException);
assertEquals(locked_file.getAbsolutePath(), ((FileSystemException)expectedException).getFile());
}
}
}
代码示例来源:origin: apache/ignite
lock = ch.tryLock(0, 1, false);
if (lock != null && lock.isValid()) {
writeContent(sb.toString());
代码示例来源:origin: net.sf.ehcache/ehcache
void unlock() {
if (directoryLock != null && directoryLock.isValid()) {
try {
directoryLock.release();
directoryLock.channel().close();
deleteFile(lockFile);
} catch (IOException e) {
throw new CacheException("Failed to release disk store path's lock file:" + lockFile, e);
}
}
if (autoCreated) {
if (diskStorePath.delete()) {
LOG.debug("Deleted directory " + diskStorePath.getName());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!