Package java.nio.channels

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


      try {
        /*
         * lock file
         */
        FileChannel channel = output.getChannel();
        FileLock lock = channel.tryLock();
        if (lock == null)
          throw new ServiceInterruption("Could not lock file: '"+file+"'",null,1000L,-1L,10,false);

        try {

View Full Code Here


      try {
        /*
         * lock file
         */
        FileChannel channel = output.getChannel();
        FileLock lock = channel.tryLock();
        if (lock == null)
          throw new ServiceInterruption("Could not lock file: '"+outputPath+"'",null,1000L,-1L,10,false);

        try {

View Full Code Here

            {
                _storeRAF = new RandomAccessFile(_storeFile, "rw");
                FileChannel fileChannel = _storeRAF.getChannel();
                try
                {
                    _storeLock = fileChannel.tryLock();
                }
                catch (OverlappingFileLockException e)
                {
                    _storeLock = null;
                }
View Full Code Here

        FileOutputStream out = new FileOutputStream(lockFile);
        FileChannel channel = out.getChannel();
        try
        {
            _fileLock = channel.tryLock();
        }
        catch(OverlappingFileLockException e)
        {
            _fileLock = null;
        }
View Full Code Here

        FileChannel ch = lockOut_.getChannel();
        assert lock_ == null;

        if (timeoutSec == 0) {
            lock_ = ch.tryLock(); /* no wait */

        } else if (timeoutSec < 0) {
            lock_ = ch.lock(); /* wait */
           
        } else {
View Full Code Here

           
        } else {
            final int sleepMs = 100;
            int elapsedMs = 0;
            while (elapsedMs < timeoutSec * 1000) {
                if ((lock_ = ch.tryLock()) != null) { break; }
                Thread.sleep(sleepMs);
                elapsedMs += sleepMs;
            }
        }

View Full Code Here

  }

  private void lockFile(final long lockWaitTime, final long lockRetryPeriod) throws IOException {
      final long entryTime = System.currentTimeMillis();
      final FileChannel channel = file.getChannel();
    m_lock = channel.tryLock(0, Long.MAX_VALUE, false);
    if (m_lock != null) {
      counters.registerQuickLock();
      return;
    }
    do {
View Full Code Here

        Thread.sleep(lockRetryPeriod);
      }
      catch (final InterruptedException e) {
          Thread.currentThread().interrupt();
      }
      m_lock = channel.tryLock(0, Long.MAX_VALUE, false);
      if (m_lock != null) {
        counters.registerDelayedLock();
        return;
      }
    } while (System.currentTimeMillis() - entryTime <= lockWaitTime);
View Full Code Here

            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

    @Override
    public boolean writeExifGpsInfo(File jpeg, Wpt wpt, boolean overwrite){
        boolean result = false;
        try{
            FileChannel input = (new RandomAccessFile(jpeg, "rw")).getChannel();
            FileLock lock = input.tryLock();
            if(lock == null){
                throw new IOException("Cannot lock input file.");
            }
            File tmpFile = null;
            try{
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.