当前位置: 首页>>代码示例>>Java>>正文


Java FileLock.release方法代码示例

本文整理汇总了Java中java.nio.channels.FileLock.release方法的典型用法代码示例。如果您正苦于以下问题:Java FileLock.release方法的具体用法?Java FileLock.release怎么用?Java FileLock.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.FileLock的用法示例。


在下文中一共展示了FileLock.release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: release

import java.nio.channels.FileLock; //导入方法依赖的package包/类
private static void release(String lockName, FileLock fileLock, File file, Closeable stream) {
    synchronized (LOCK_MAP) {
        if (fileLock != null) {
            try {
                LOCK_MAP.remove(lockName, fileLock.hashCode());
                ConcurrentHashMap<Integer, ProcessLock> locks = LOCK_MAP.get(lockName);
                if (locks == null || locks.isEmpty()) {
                    IOUtil.deleteFileOrDir(file);
                }

                if (fileLock.channel().isOpen()) {
                    fileLock.release();
                }
            } catch (Throwable ex) {
                LogUtil.e(ex.getMessage(), ex);
            } finally {
                IOUtil.closeQuietly(fileLock.channel());
            }
        }

        IOUtil.closeQuietly(stream);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ProcessLock.java

示例2: incrementNextTaskId

import java.nio.channels.FileLock; //导入方法依赖的package包/类
public synchronized int incrementNextTaskId() {
	int toRet = -1;
	try {
		FileLock l = channel.lock();
		buffer.position(0);
		int current = buffer.getInt();
		buffer.position(0);
		current++;
		toRet = current;
		buffer.putInt(current);
		l.release();
	} catch (IOException e) {
		System.err.println("SharedSystemData, IOException : " + e.getMessage());
		e.printStackTrace();
	}
	
	return toRet;
}
 
开发者ID:bizzard4,项目名称:MpiTaskFramework,代码行数:19,代码来源:SharedSystemData.java

示例3: zipFile

import java.nio.channels.FileLock; //导入方法依赖的package包/类
/**
 * Compactar uma arquivo.
 * @param inputFile informar o arquivo a ser compactado.
 * @param zipFilePath informar o nome e caminho zip.
 * @param iZipFile se necessário, informar uma {@link IZipFile}.
 * @throws IOException
 */
public static void zipFile(File inputFile, String zipFilePath, IZipFile iZipFile) throws IOException {
    FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath);
    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
    ZipEntry zipEntry = new ZipEntry(inputFile.getName());
    zipOutputStream.putNextEntry(zipEntry);
    FileInputStream fileInputStream = new FileInputStream(inputFile);
    FileChannel fileChannel = fileInputStream.getChannel();
    FileLock fileLock = fileChannel.tryLock(0L, Long.MAX_VALUE, /*shared*/true);
    long sizeToZip = fileInputStream.available();
    long sizeCompacted = 0;
    try {
        byte[] buf = new byte[1024];
        int bytesRead;
        while ((bytesRead = fileInputStream.read(buf)) > 0) {
            sizeCompacted += bytesRead;
            zipOutputStream.write(buf, 0, bytesRead);
            if (iZipFile != null) iZipFile.progress(sizeToZip, sizeCompacted);
        }
    } finally {
        fileLock.release();
        zipOutputStream.closeEntry();
        zipOutputStream.close();
        fileOutputStream.close();
    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:33,代码来源:OhaHelper.java

示例4: testOperationActions

import java.nio.channels.FileLock; //导入方法依赖的package包/类
public void testOperationActions() throws Exception { // #72397
    final NbModuleProject project = generateStandaloneModule("module");
    cgpi.setProject(project);
    DialogDisplayerImpl dd = (DialogDisplayerImpl) Lookup.getDefault().lookup(DialogDisplayer.class);
    FileObject lock = FileUtil.createData(project.getProjectDirectory(), "build/testuserdir/lock");
    RandomAccessFile raf = new RandomAccessFile(FileUtil.toFile(lock), "rw");
    FileLock lck = raf.getChannel().lock();
    EventQueue.invokeAndWait(new Runnable() {
        @Override public void run() {
            ((ContextAwareAction) CommonProjectActions.deleteProjectAction()).createContextAwareInstance(Lookups.singleton(project)).actionPerformed(null);
        }
    });
    assertNotNull("warning message emitted", dd.getLastNotifyDescriptor());
    assertEquals("warning message emitted", dd.getLastNotifyDescriptor().getMessage(),
            Bundle.ERR_ModuleIsBeingRun());
    dd.reset();
    lck.release();
    raf.close();
    lock.delete();
    EventQueue.invokeAndWait(new Runnable() {
        @Override public void run() {
            CommonProjectActions.deleteProjectAction().actionPerformed(null);
        }
    });
    assertNull("no warning message", dd.getLastNotifyDescriptor());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ModuleOperationsTest.java

示例5: unlockFile

import java.nio.channels.FileLock; //导入方法依赖的package包/类
/**
 * Unlock file already locked with {@link #lockFile(String) lockFile()} method
 *
 * @param fileName file name
 */
@Override
public void unlockFile(
                        String fileName ) {

    synchronized (lockedFiles) {

        FileLock fileLock = lockedFiles.get(fileName);
        if (fileLock != null) {
            try {
                fileLock.release();
            } catch (Exception e) {
                throw new FileSystemOperationException("Could not unlock file '" + fileName + "'", e);
            } finally {
                IoUtils.closeStream(fileLock.channel());
                lockedFiles.remove(fileName);
            }
        } else {
            log.warn("File '" + fileName + "' is not locked, so we will not try to unlock it");
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:27,代码来源:LocalFileSystemOperations.java

示例6: unzipFile

import java.nio.channels.FileLock; //导入方法依赖的package包/类
private File unzipFile(File cachedFile) throws IOException {
  String filename = cachedFile.getName();
  File destDir = new File(cachedFile.getParentFile(), filename + "_unzip");
  if (!destDir.exists()) {
    File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock");
    FileOutputStream out = new FileOutputStream(lockFile);
    try {
      FileLock lock = out.getChannel().lock();
      try {
        // Recheck in case of concurrent processes
        if (!destDir.exists()) {
          Path tempDir = fileCache.createTempDir();
          ZipUtils.unzip(cachedFile, tempDir.toFile(), newLibFilter());
          FileUtils.moveDirectory(tempDir.toFile(), destDir);
        }
      } finally {
        lock.release();
      }
    } finally {
      out.close();
      FileUtils.deleteQuietly(lockFile);
    }
  }
  return destDir;
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:26,代码来源:DefaultPluginJarExploder.java

示例7: releaseLock

import java.nio.channels.FileLock; //导入方法依赖的package包/类
void releaseLock(final FileLock fileLock, final File lockFile) throws IOException {
  if (lockFile == null) {
    return;
  }

  try {
    if (fileLock != null) {
      fileLock.release();
      fileLock.channel().close();
    }
  } finally {
    if (!lockFile.delete()) {
      lockFile.deleteOnExit();
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:JarDeployerDUnitTest.java

示例8: isLockSupported

import java.nio.channels.FileLock; //导入方法依赖的package包/类
/**
 * Check whether underlying file system supports file locking.
 * 
 * @return <code>true</code> if exclusive locks are supported or
 *         <code>false</code> otherwise.
 * @throws IOException
 * @see StorageDirectory#lock()
 */
public boolean isLockSupported() throws IOException {
  FileLock firstLock = null;
  FileLock secondLock = null;
  try {
    firstLock = lock;
    if(firstLock == null) {
      firstLock = tryLock();
      if(firstLock == null)
        return true;
    }
    secondLock = tryLock();
    if(secondLock == null)
      return true;
  } finally {
    if(firstLock != null && firstLock != lock) {
      firstLock.release();
      firstLock.channel().close();
    }
    if(secondLock != null) {
      secondLock.release();
      secondLock.channel().close();
    }
  }
  return false;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:Storage.java

示例9: setNextTaskId

import java.nio.channels.FileLock; //导入方法依赖的package包/类
/**
 * Acquire file lock and set next task id.
 */
public synchronized void setNextTaskId(int pNextTaskId) {
	try {
		FileLock l = channel.lock();
		buffer.position(0);
		buffer.putInt(pNextTaskId);
		l.release();
	} catch (IOException e) {
		System.err.println("SharedSystemData, IOException : " + e.getMessage());
		e.printStackTrace();
	}
}
 
开发者ID:bizzard4,项目名称:MpiTaskFramework,代码行数:15,代码来源:SharedSystemData.java

示例10: getNextTaskId

import java.nio.channels.FileLock; //导入方法依赖的package包/类
/**
 * Acquire file lock and get next task id.
 * @return
 */
public synchronized int getNextTaskId() {
	int toRet = -1;
	try {
		FileLock l = channel.lock();
		buffer.position(0);
		toRet = buffer.getInt();
		l.release();
	} catch (IOException e) {
		System.err.println("SharedSystemData, IOException : " + e.getMessage());
		e.printStackTrace();
	}
	
	return toRet;
}
 
开发者ID:bizzard4,项目名称:MpiTaskFramework,代码行数:19,代码来源:SharedSystemData.java

示例11: setShutdownSignal

import java.nio.channels.FileLock; //导入方法依赖的package包/类
public synchronized void setShutdownSignal(boolean pShutdownSignal) {
	try {
		FileLock l = channel.lock();
		buffer.position(Integer.BYTES);
		buffer.putInt(pShutdownSignal ? 1 : 0);
		l.release();
	} catch (IOException e) {
		System.err.println("SharedSystemData, IOException : " + e.getMessage());
		e.printStackTrace();
	}
}
 
开发者ID:bizzard4,项目名称:MpiTaskFramework,代码行数:12,代码来源:SharedSystemData.java

示例12: getShutdownSignal

import java.nio.channels.FileLock; //导入方法依赖的package包/类
public boolean getShutdownSignal() {
	boolean toRet = false;
	try {
		FileLock l = channel.lock(Integer.BYTES, Integer.BYTES, false);
		buffer.position(Integer.BYTES);
		toRet = buffer.getInt() == 1 ? true : false;
		l.release();
	} catch (IOException e) {
		System.err.println("SharedSystemData, IOException : " + e.getMessage());
		e.printStackTrace();
	}
	
	return toRet;
}
 
开发者ID:bizzard4,项目名称:MpiTaskFramework,代码行数:15,代码来源:SharedSystemData.java

示例13: testCannotLock

import java.nio.channels.FileLock; //导入方法依赖的package包/类
public void testCannotLock() throws Exception {
    FileOutputStream os = new FileOutputStream(file);
    FileLock lock = os.getChannel().lock();
    try {
        assertTrue("Is locked", condition.eval());
    } finally {
        lock.release();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:IsLockedTest.java

示例14: main

import java.nio.channels.FileLock; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception{
    FileOutputStream fos=new FileOutputStream("");
    FileLock fl=fos.getChannel().tryLock();
    if(fl!=null){
        System.out.println("Locked File");
        TimeUnit.MILLISECONDS.sleep(100);
        fl.release();
        System.out.println("Released Lock");
    }
    fos.close();
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:12,代码来源:FileLocking.java

示例15: unlock

import java.nio.channels.FileLock; //导入方法依赖的package包/类
/**
 * Unlock the state directory for the given {@link TaskId}
 * @param taskId
 * @throws IOException
 */
void unlock(final TaskId taskId) throws IOException {
    final FileLock lock = locks.remove(taskId);
    if (lock != null) {
        lock.release();

        log.debug("{} Released state dir lock for task {}", logPrefix, taskId);

        final FileChannel fileChannel = channels.remove(taskId);
        if (fileChannel != null) {
            fileChannel.close();
        }
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:StateDirectory.java


注:本文中的java.nio.channels.FileLock.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。