Package java.nio.channels

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


        // 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


        // 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

                FileChannel channel = raf.getChannel();
                // Create a exclusive (non-shared) lock that does not allow other readers ...
                if (block) {
                    fileLock = channel.lock(0, Long.MAX_VALUE, false);
                } else {
                    fileLock = channel.tryLock(0, Long.MAX_VALUE, false);
                    if (fileLock == null) {
                        // Couldn't immediately get our write-lock, so unlock the read lock and return ...
                        this.lock.writeLock().unlock();
                        return null;
                    }
View Full Code Here

                    FileChannel channel = raf.getChannel();
                    // Create a shared lock that allows other readers ...
                    if (block) {
                        fileLock = channel.lock(0, Long.MAX_VALUE, true);
                    } else {
                        fileLock = channel.tryLock(0, Long.MAX_VALUE, true);
                        if (fileLock == null) {
                            // Couldn't immediately get our read-lock, so unlock the read lock and return ...
                            this.lock.readLock().unlock();
                            return null;
                        }
View Full Code Here

      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
      channel.tryLock();
      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
View Full Code Here

      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
      channel.tryLock(0, 10, true);
      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
View Full Code Here

      fail();
    } catch (IllegalArgumentException expected) {
    }

    try {
      channel.tryLock(-1, 10, true);
      fail();
    } catch (IllegalArgumentException expected) {
    }

    try {
View Full Code Here

      fail();
    } catch (IllegalArgumentException expected) {
    }

    try {
      channel.tryLock(0, -1, true);
      fail();
    } catch (IllegalArgumentException expected) {
    }
  }
View Full Code Here

    assertNotNull(channel.lock());
    assertNotNull(channel.lock(0, 10, false));
    assertNotNull(channel.lock(0, 10, true));

    assertNotNull(channel.tryLock());
    assertNotNull(channel.tryLock(0, 10, false));
    assertNotNull(channel.tryLock(0, 10, true));

    FileLock lock = channel.lock();
    assertTrue(lock.isValid());
View Full Code Here

    assertNotNull(channel.lock());
    assertNotNull(channel.lock(0, 10, false));
    assertNotNull(channel.lock(0, 10, true));

    assertNotNull(channel.tryLock());
    assertNotNull(channel.tryLock(0, 10, false));
    assertNotNull(channel.tryLock(0, 10, true));

    FileLock lock = channel.lock();
    assertTrue(lock.isValid());
    lock.release();
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.