當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。