Package java.nio.channels

Examples of java.nio.channels.FileChannel.tryLock()


            boolean writable;

            try {
                fos = new FileOutputStream(file, true);
                FileChannel channel = fos.getChannel();
                lock = channel.tryLock();
            } catch (IOException e) {
                log.warn("Error while attempting to lock the file: " + file.getName(), e);
                writable = false;
            } finally {
                if (lock != null) {
View Full Code Here


      // Try acquiring the lock without blocking. This method returns
      // null or throws an exception if the file is already locked.
      FileLock lock;
      try {
        lock = channel.tryLock();
      } catch (OverlappingFileLockException e) {
        // File is already locked in this thread or virtual machine
        return; // give up
      }
      if (lock == null) return;
View Full Code Here

        // We got an IOException while trying to open the file.
        // Try the next file.
        continue;
    }
    try {
        FileLock fl = fc.tryLock();
        if (fl == null) {
            // We failed to get the lock.  Try next file.
      continue;
        }
        // We got the lock OK.
View Full Code Here

    // randomFile = new RandomAccessFile(this.strFileName, pstrAccessMode);
    randomFile = new RandomAccessFile(this, pstrAccessMode);
    FileChannel channel = randomFile.getChannel();
    FileLock fleLock = null;
    try {
      fleLock = channel.tryLock();
    }
    catch (OverlappingFileLockException e) {
      flgFileIsLocked = true;
    }
    catch (Exception e) {
View Full Code Here

      FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel();
      // Try acquiring the lock without blocking. This method returns
      // null or throws an exception if the file is already locked.
      try
      {
        lock = channel.tryLock();
      }
      catch (OverlappingFileLockException e)
      {
        // File is already locked in this thread or virtual machine
        return;
View Full Code Here

                case LOCK_EX | LOCK_NB:
                    if (currentLock != null) {
                        currentLock.release();
                        currentLock = null;
                    }
                    currentLock = fileChannel.tryLock();
                    if (currentLock != null) {
                        return RubyFixnum.zero(context.getRuntime());
                    }

                    break;
View Full Code Here

                    if (currentLock != null) {
                        currentLock.release();
                        currentLock = null;
                    }

                    currentLock = fileChannel.tryLock(0L, Long.MAX_VALUE, true);
                    if (currentLock != null) {
                        return RubyFixnum.zero(context.getRuntime());
                    }

                    break;
View Full Code Here

        FileLock lock = null;
        ByteBuffer bb = null;
        try {
            channel = fos.getChannel();
            if (channel != null) {
                lock = channel.tryLock();
            }
            bb = getTempByteBuffer();
        } catch (Throwable t) {
        }
        if (lock == null || bb == null || !bb.hasArray()) {
View Full Code Here

                }
                throw new Exception("Unable to create bundle cache lock file: " + ex);
            }
            try
            {
                m_lock = fc.tryLock();
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to lock bundle cache: " + ex);
            }
View Full Code Here

                    }
                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    LOG.trace("Acquired exclusive read lock: {} to file: {}", lock, target);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.