本文整理了Java中java.nio.channels.FileLock.channel()
方法的一些代码示例,展示了FileLock.channel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileLock.channel()
方法的具体详情如下:
包路径:java.nio.channels.FileLock
类名称:FileLock
方法名:channel
[英]Returns the lock's FileChannel.
[中]
代码示例来源:origin: apache/flume
/**
* Unlock directory.
*
* @throws IOException
*/
private void unlock(File dir) throws IOException {
FileLock lock = locks.remove(dir.getAbsolutePath());
if (lock == null) {
return;
}
lock.release();
lock.channel().close();
lock = null;
}
代码示例来源:origin: robovm/robovm
/**
* Flushes and closes all opened files.
*/
@Override
public void close() {
// release locks
super.close();
allLocks.remove(fileName);
try {
FileChannel channel = lock.channel();
lock.release();
channel.close();
File file = new File(fileName + LCK_EXT);
file.delete();
} catch (IOException e) {
// ignore
}
}
代码示例来源: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: apache/flume
/**
* Lock storage to provide exclusive access.
* <p>
* <p> Locking is not supported by all file systems.
* E.g., NFS does not consistently support exclusive locks.
* <p>
* <p> If locking is supported we guarantee exclusive access to the
* storage directory. Otherwise, no guarantee is given.
*
* @throws IOException if locking fails
*/
private void lock(File dir) throws IOException {
FileLock lock = tryLock(dir);
if (lock == null) {
String msg = "Cannot lock " + dir
+ ". The directory is already locked. "
+ channelNameDescriptor;
LOGGER.info(msg);
throw new IOException(msg);
}
FileLock secondLock = tryLock(dir);
if (secondLock != null) {
LOGGER.warn("Directory " + dir + " does not support locking");
secondLock.release();
secondLock.channel().close();
}
locks.put(dir.getAbsolutePath(), lock);
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
/**
* Unlock storage.
*
* @throws IOException
*/
public void unlock() throws IOException {
if (this.lock == null)
return;
this.lock.release();
lock.channel().close();
lock = null;
}
代码示例来源: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());
}
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
if(firstLock != null && firstLock != lock) {
firstLock.release();
firstLock.channel().close();
secondLock.channel().close();
代码示例来源:origin: geotools/geotools
try {
lock.release();
lock.channel().close();
new File(directory, LOCK_FILE).delete();
} catch (IOException e) {
代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs
/**
* Unlock storage.
*
* @throws IOException
*/
public void unlock() throws IOException {
if (this.lock == null)
return;
this.lock.release();
lock.channel().close();
lock = null;
}
代码示例来源:origin: ModeShape/modeshape
protected FileChannel lockedFileChannel() {
try {
fileLockLock.lock();
return fileLock != null ? fileLock.channel() : null;
} finally {
fileLockLock.unlock();
}
}
代码示例来源:origin: io.prestosql.hadoop/hadoop-apache
/**
* Unlock storage.
*
* @throws IOException
*/
public void unlock() throws IOException {
if (this.lock == null)
return;
this.lock.release();
lock.channel().close();
lock = null;
}
代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core
/**
* Unlock storage.
*
* @throws IOException
*/
public void unlock() throws IOException {
if (this.lock == null)
return;
this.lock.release();
lock.channel().close();
lock = null;
}
}
代码示例来源:origin: org.fcrepo/modeshape-jcr
protected FileChannel lockedFileChannel() {
try {
fileLockLock.lock();
return fileLock != null ? fileLock.channel() : null;
} finally {
fileLockLock.unlock();
}
}
代码示例来源:origin: org.eclipse.aether/aether-connector-basic
public void close()
{
close( lock.channel() );
lockFile.delete();
}
代码示例来源:origin: apache/karaf
public synchronized void release() throws Exception {
if (lock != null && lock.isValid()) {
LOG.info("Releasing lock " + lockPath.getPath());
lock.release();
lock.channel().close();
}
lock = null;
}
代码示例来源:origin: org.apache.tez/tez-runtime-library
private void releaseLock(FileLock lock) throws IOException {
if (lock != null && lock.isValid()) {
FileChannel lockChannel = lock.channel();
lock.release();
lockChannel.close();
}
}
代码示例来源:origin: NyaaCat/RPGItems-reloaded
private static void unlock(File itemFile, boolean remove) throws IOException {
if (!plugin.cfg.itemFsLock) return;
FileLock fileLock = remove ? itemFileLocks.remove(itemFile.getCanonicalPath()) : itemFileLocks.get(itemFile.getCanonicalPath());
if (fileLock != null) {
if (fileLock.isValid()) {
fileLock.release();
}
fileLock.channel().close();
} else {
plugin.getLogger().warning("Lock for " + itemFile + " does not exist? If you are reloading a item, that's OK.");
}
}
代码示例来源:origin: de.mhus.lib/mhu-lib-core
public static void releaseLock(FileLock lock) {
try {
FileChannel channel = lock.channel();
lock.close();
channel.close();
} catch (IOException e) {
log.d(e);
}
}
代码示例来源:origin: org.apache.geode/gemfire-core
private byte[] getJarContent() throws IOException {
ChannelInputStream channelInputStream = new ChannelInputStream(this.fileLock.channel());
final ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
final byte[] bytes = new byte[4096];
int bytesRead;
while (((bytesRead = channelInputStream.read(bytes)) != -1)) {
byteOutStream.write(bytes, 0, bytesRead);
}
channelInputStream.close();
return byteOutStream.toByteArray();
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!