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


Java OverlappingFileLockException类代码示例

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


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

示例1: lock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
public void lock(Object key) throws IOException {
    if (key == null) {
        throw new NullPointerException("key should not be null");
    }
    int hashCode = key.hashCode();
    FileLock fileLock;
    for (;;) {
        try {
            fileLock = fileChannel.lock(hashCode, 1, false);
            break;
        } catch (OverlappingFileLockException e) {
            Thread.yield();
        } catch (Throwable cause) {
            throw new RuntimeException("lock file fail", cause);
        }
    }
    FileLock old = fileLockThreadLocal.get();
    if (old != null) {
        old.release();
    }
    fileLockThreadLocal.set(fileLock);
}
 
开发者ID:neozhangning,项目名称:FasterDB,代码行数:23,代码来源:KeyLocker.java

示例2: lock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
private static boolean lock(File directory)
{
  String name = "node.lock";
  File lockfile = new File(directory, name);
  lockfile.deleteOnExit();
  try
  {
    FileChannel fc = (FileChannel) Channels.newChannel(new FileOutputStream(lockfile));
    lock = fc.tryLock();
    if (lock != null)
    {
      return true;
    }
  }
  catch (IOException x)
  {
    System.err.println(x.toString());
  }
  catch (OverlappingFileLockException e)
  {
    System.err.println(e.toString());
  }
  return false;
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:25,代码来源:WorkPathHelper.java

示例3: lock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
private void lock() throws IOException, BlockStoreException {
    if (!semaphores.tryAcquire()) {
        throw new BlockStoreException("File in use");
    }
    try {
        lock = file.getChannel().tryLock();
    } catch (OverlappingFileLockException e) {
        semaphores.release();
        lock = null;
    }
    if (lock == null) {
        try {
            this.file.close();
        } finally {
            this.file = null;
        }
        throw new BlockStoreException("Could not lock file");
    }
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:20,代码来源:DiskBlockStore.java

示例4: obtain

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
/**
 * Locks the file, with a timeout (non-blocking).
 * @param timeout_ms timeout duration in milliseconds.
 * @throws IOException I/O exception occured.
 * @throws InterruptedException current thread interrupted.
 * @throws TimeoutException failed to obtain lock.
 */
public void obtain(long timeout_ms)
      throws IOException, InterruptedException, TimeoutException
{
   Long quit_time = System.currentTimeMillis() + timeout_ms;
   if (fileLock != null && fileLock.isValid())
   {
      // lock has already been obtained.
      return;
   }
   do
   {
      try
      {
         fileLock = fileToLock.tryLock();
         return;
      }
      catch (OverlappingFileLockException e)
      {
         Thread.sleep(1000);
      }
   } while (System.currentTimeMillis() < quit_time);
   throw new TimeoutException();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:31,代码来源:AsyncFileLock.java

示例5: tryLock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
/**
 * Attempts to acquire an exclusive lock on the directory.
 *
 * @return A lock object representing the newly-acquired lock or
 * <code>null</code> if directory is already locked.
 * @throws IOException if locking fails.
 */
@SuppressWarnings("resource")
private FileLock tryLock(File dir) throws IOException {
  File lockF = new File(dir, FILE_LOCK);
  lockF.deleteOnExit();
  RandomAccessFile file = new RandomAccessFile(lockF, "rws");
  FileLock res = null;
  try {
    res = file.getChannel().tryLock();
  } catch (OverlappingFileLockException oe) {
    file.close();
    return null;
  } catch (IOException e) {
    LOGGER.error("Cannot create lock on " + lockF, e);
    file.close();
    throw e;
  }
  return res;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:26,代码来源:Log.java

示例6: shouldLockTaskStateDirectory

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
@Test
public void shouldLockTaskStateDirectory() throws Exception {
    final TaskId taskId = new TaskId(0, 0);
    final File taskDirectory = directory.directoryForTask(taskId);

    directory.lock(taskId, 0);

    try (
        final FileChannel channel = FileChannel.open(
            new File(taskDirectory, StateDirectory.LOCK_FILE_NAME).toPath(),
            StandardOpenOption.CREATE, StandardOpenOption.WRITE)
    ) {
        channel.tryLock();
        fail("shouldn't be able to lock already locked directory");
    } catch (final OverlappingFileLockException e) {
        // pass
    } finally {
        directory.unlock(taskId);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:StateDirectoryTest.java

示例7: isPreUpgradableLayout

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
@Override
public boolean isPreUpgradableLayout(StorageDirectory sd) throws IOException {
  File oldF = new File(sd.getRoot(), "storage");
  if (!oldF.exists()) {
    return false;
  }
  // check the layout version inside the storage file
  // Lock and Read old storage file
  try (RandomAccessFile oldFile = new RandomAccessFile(oldF, "rws");
    FileLock oldLock = oldFile.getChannel().tryLock()) {
    if (null == oldLock) {
      LOG.error("Unable to acquire file lock on path " + oldF.toString());
      throw new OverlappingFileLockException();
    }
    oldFile.seek(0);
    int oldVersion = oldFile.readInt();
    if (oldVersion < LAST_PRE_UPGRADE_LAYOUT_VERSION) {
      return false;
    }
  }
  return true;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:23,代码来源:DataStorage.java

示例8: lock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
private void lock() throws IOException, BlockStoreException {
    if (!semaphores.tryAcquire(fileName)) {
        throw new BlockStoreException("File in use");
    }
    try {
        lock = channel.tryLock();
    } catch (OverlappingFileLockException e) {
        semaphores.release(fileName);
        lock = null;
    }
    if (lock == null) {
        try {
            this.file.close();
        } finally {
            this.file = null;
        }
        throw new BlockStoreException("Could not lock file");
    }
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:20,代码来源:BoundedOverheadBlockStore.java

示例9: lock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
private void lock() throws IOException, BlockStoreException {
    if (!semaphores.tryAcquire(fileName)) {
        throw new BlockStoreException("File in use");
    }
    try {
        lock = file.getChannel().tryLock();
    } catch (OverlappingFileLockException e) {
        semaphores.release(fileName);
        lock = null;
    }
    if (lock == null) {
        try {
            this.file.close();
        } finally {
            this.file = null;
        }
        throw new BlockStoreException("Could not lock file");
    }
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:20,代码来源:DiskBlockStore.java

示例10: test_repate_restart

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
@Test(expected = OverlappingFileLockException.class)
public void test_repate_restart() throws Exception {
    long totalMsgs = 100;
    QUEUE_TOTAL = 1;
    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8);
    messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 4);
    messageStoreConfig.setMaxHashSlotNum(100);
    messageStoreConfig.setMaxIndexNum(100 * 10);
    MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig());

    boolean load = master.load();
    assertTrue(load);

    try {
        master.start();
        master.start();
    } finally {
        master.shutdown();
        master.destroy();
    }
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:25,代码来源:DefaultMessageStoreTest.java

示例11: tryLock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
/**
 * Attempts to acquire an exclusive lock on the storage.
 * 
 * @return A lock object representing the newly-acquired lock or
 * <code>null</code> if storage is already locked.
 * @throws IOException if locking fails.
 */
FileLock tryLock() throws IOException {
  File lockF = new File(root, STORAGE_FILE_LOCK);
  lockF.deleteOnExit();
  RandomAccessFile file = new RandomAccessFile(lockF, "rws");
  FileLock res = null;
  try {
    res = file.getChannel().tryLock();
  } catch(OverlappingFileLockException oe) {
    file.close();
    return null;
  } catch(IOException e) {
    LOG.error("Cannot create lock on " + lockF, e);
    file.close();
    throw e;
  }
  return res;
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:25,代码来源:Storage.java

示例12: lockCLI

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
void lockCLI(File lockPlace) throws Exception {
   if (lockPlace != null) {
      lockPlace.mkdirs();
      if (serverLockFile == null) {
         File fileLock = new File(lockPlace, "cli.lock");
         serverLockFile = new RandomAccessFile(fileLock, "rw");
      }
      try {
         FileLock lock = serverLockFile.getChannel().tryLock();
         if (lock == null) {
            throw new CLIException("Error: There is another process using the server at " + lockPlace + ". Cannot start the process!");
         }
         serverLockLock = lock;
      } catch (OverlappingFileLockException e) {
         throw new CLIException("Error: There is another process using the server at " + lockPlace + ". Cannot start the process!");
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:19,代码来源:LockAbstract.java

示例13: tryLock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
public FileLock tryLock(Channel channel, long start, long size, boolean shared) throws IOException{
    
    if(!channel.isOpen()) {
        throw new ClosedChannelException();
    }
    
    Iterator<EphemeralFsFileLock> iter = locks.iterator();
    while(iter.hasNext()) {
        EphemeralFsFileLock oldLock = iter.next();
        if(!oldLock.isValid()) {
            iter.remove();
        }
        else if(oldLock.overlaps(start, size)) {
            throw new OverlappingFileLockException();
        }
    }
    EphemeralFsFileLock newLock = 
            channel instanceof FileChannel ? 
            new EphemeralFsFileLock((FileChannel) channel, start, size, shared) :
            new EphemeralFsFileLock((AsynchronousFileChannel) channel, start, size, shared);
   locks.add(newLock);
   return newLock;

}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:25,代码来源:FileContents.java

示例14: testLockShared

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
@Test
public void testLockShared() throws Exception {
    Path file = root.resolve("locked");
    Files.createFile(file);
    
    FileChannel channel = (FileChannel) 
            Files.newByteChannel(file, StandardOpenOption.WRITE, StandardOpenOption.READ);
    try
    {
        FileLock lock = channel.tryLock(0, 5, true);
        assertNotNull(lock);
        assertTrue(lock.isShared());
        assertTrue(lock.isValid());
        
        try
        {
            lock = channel.tryLock(0, 5, true);
            fail();
        } catch(OverlappingFileLockException e) {
            //pass
        }
        
    } finally {
        channel.close();
    }
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:27,代码来源:FileLockTest.java

示例15: addLock

import java.nio.channels.OverlappingFileLockException; //导入依赖的package包/类
synchronized void addLock(FileLock lock)
        throws OverlappingFileLockException {
    long lockEnd = lock.position() + lock.size();
    for (Iterator<FileLock> keyItr = locks.iterator(); keyItr.hasNext();) {
        FileLock existingLock = keyItr.next();
        if (existingLock.position() > lockEnd) {
            // This, and all remaining locks, start beyond our end (so
            // cannot overlap).
            break;
        }
        if (existingLock.overlaps(lock.position(), lock.size())) {
            throw new OverlappingFileLockException();
        }
    }
    locks.add(lock);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:LockManager.java


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