本文整理了Java中java.nio.channels.FileLock.isShared()
方法的一些代码示例,展示了FileLock.isShared()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileLock.isShared()
方法的具体详情如下:
包路径:java.nio.channels.FileLock
类名称:FileLock
方法名:isShared
[英]Indicates if the file lock is shared with other processes or if it is exclusive.
[中]指示文件锁是与其他进程共享还是独占。
代码示例来源:origin: com.h2database/h2
protected FileLockRetry(FileLock base, FileChannel channel) {
super(channel, base.position(), base.size(), base.isShared());
this.base = base;
}
代码示例来源: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: didi/DDMQ
/**
* @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 && BrokerRole.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();
if (BrokerRole.SLAVE != messageStoreConfig.getBrokerRole()) {
this.haService.initInSyncOffset(getMaxPhyOffset());
}
this.shutdown = false;
}
代码示例来源:origin: org.jruby/jruby-complete
private static boolean lockStateChanges(FileLock lock, int lockMode) {
if (lock == null) {
// no lock, only proceed if we are acquiring
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return false;
default:
return true;
}
} else {
// existing lock, only proceed if we are unlocking or changing
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return true;
case LOCK_EX:
case LOCK_EX | LOCK_NB:
return lock.isShared();
case LOCK_SH:
case LOCK_SH | LOCK_NB:
return !lock.isShared();
default:
return false;
}
}
}
代码示例来源:origin: org.jruby/jruby-core
private static boolean lockStateChanges(FileLock lock, int lockMode) {
if (lock == null) {
// no lock, only proceed if we are acquiring
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return false;
default:
return true;
}
} else {
// existing lock, only proceed if we are unlocking or changing
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return true;
case LOCK_EX:
case LOCK_EX | LOCK_NB:
return lock.isShared();
case LOCK_SH:
case LOCK_SH | LOCK_NB:
return !lock.isShared();
default:
return false;
}
}
}
代码示例来源:origin: OpenMods/OpenModsLib
private ExclusiveLock(File file, FileChannel fc, FileLock lock) {
super(file, fc, lock);
if (lock.isShared()) throw new AssertionError("Invalid lock: " + lock);
}
代码示例来源:origin: OpenMods/OpenModsLib
private SharedLock(File file, FileChannel fc, FileLock lock) {
super(file, fc, lock);
if (!lock.isShared()) throw new AssertionError("Invalid lock: " + lock);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
private static boolean lockStateChanges(FileLock lock, int lockMode) {
if (lock == null) {
// no lock, only proceed if we are acquiring
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return false;
default:
return true;
}
} else {
// existing lock, only proceed if we are unlocking or changing
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return true;
case LOCK_EX:
case LOCK_EX | LOCK_NB:
return lock.isShared();
case LOCK_SH:
case LOCK_SH | LOCK_NB:
return !lock.isShared();
default:
return false;
}
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
private static boolean lockStateChanges(FileLock lock, int lockMode) {
if (lock == null) {
// no lock, only proceed if we are acquiring
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return false;
default:
return true;
}
} else {
// existing lock, only proceed if we are unlocking or changing
switch (lockMode & 0xF) {
case LOCK_UN:
case LOCK_UN | LOCK_NB:
return true;
case LOCK_EX:
case LOCK_EX | LOCK_NB:
return lock.isShared();
case LOCK_SH:
case LOCK_SH | LOCK_NB:
return !lock.isShared();
default:
return false;
}
}
}
代码示例来源:origin: bluestreak01/questdb
@Override
public String toString() {
return "Lock{" +
"lockName=" + lockName +
", isShared=" + (lock == null ? "NULL" : lock.isShared()) +
", isValid=" + (lock == null ? "NULL" : lock.isValid()) +
", refCount=" + refCount.get() +
'}';
}
代码示例来源:origin: BaseXdb/basex
@Override
public boolean lock(final boolean write) {
try {
if(fl != null) {
if(write != fl.isShared()) return true;
fl.release();
}
fl = file.getChannel().tryLock(0, Long.MAX_VALUE, !write);
return fl != null;
} catch(final IOException ex) {
throw Util.notExpected(ex);
}
}
代码示例来源:origin: apache/archiva
public boolean isShared()
{
return this.fileLock.isValid() && this.fileLock.isShared();
}
代码示例来源:origin: org.basex/basex
@Override
public boolean lock(final boolean write) {
try {
if(fl != null) {
if(write != fl.isShared()) return true;
fl.release();
}
fl = file.getChannel().tryLock(0, Long.MAX_VALUE, !write);
return fl != null;
} catch(final IOException ex) {
throw Util.notExpected(ex);
}
}
代码示例来源:origin: org.apache.archiva/archiva-filelock
public boolean isShared()
{
return this.fileLock.isValid() && this.fileLock.isShared();
}
代码示例来源:origin: com.eventsourcing/h2
protected FileLockRetry(FileLock base, FileChannel channel) {
super(channel, base.position(), base.size(), base.isShared());
this.base = base;
}
代码示例来源:origin: org.wowtools/h2
protected FileLockRetry(FileLock base, FileChannel channel) {
super(channel, base.position(), base.size(), base.isShared());
this.base = base;
}
代码示例来源:origin: eu.fbk.utils/utils-core
@Override
public synchronized void release() throws IOException {
// Abort if already released
if (!this.valid) {
return;
}
try {
// Decrement the ref count. If zero, release the lock, remove the entry in
// the global map, close the lock file and delete it if the lock was
// exclusive (in that case we are sure the lock was not open in other
// applications)
synchronized (LOCK_DATA) {
if (refCount.decrementAndGet() == 0) {
try {
lock.release();
} finally {
LOCK_DATA.remove(path);
IO.closeQuietly(lock.channel());
if (!lock.isShared()) {
Files.deleteIfExists(path);
}
}
}
}
} finally {
this.valid = false;
}
}
代码示例来源:origin: apache/felix
if (lock.isShared()) {
代码示例来源:origin: org.tmatesoft.sqljet/sqljet
/**
* @param channel
* @param position
* @param size
* @param shared
*/
public SqlJetFileLock(SqlJetFileLockManager manager, FileLock fileLock) {
super(fileLock.channel(), fileLock.position(), fileLock.size(), fileLock.isShared());
this.manager = manager;
this.fileLock = fileLock;
this.locksCount = 1;
}
代码示例来源:origin: org.apache.rocketmq/rocketmq-store
/**
* @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;
}
内容来源于网络,如有侵权,请联系作者删除!