Package java.nio.channels

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


                            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


      // Tries to open the lock file in write mode.
      LOCK_FILES_DIR.mkdirs();
      try {
        RandomAccessFile raf = new RandomAccessFile(lockFile, "rw");
        fileChannel = raf.getChannel();
        fileLock = fileChannel.tryLock();
        if (fileLock == null) {
          // The file is already locked.
          throw new AlreadyLockedException(id);
        }
      } catch (Throwable t) {
View Full Code Here

         */
        try {
            final File lockFile = new File(Global.LOCK_FILE);
            LogController.setUpClientLogging(Global.LOG_DIR);
            final FileChannel lockChannel = new RandomAccessFile(lockFile, "rw").getChannel();
            final FileLock lock = lockChannel.tryLock();
            if (lock == null) {
                lockChannel.close();
                final String message = "Another client is running on your computer.\n" +
                        "You have to quit the other client.\n" +
                        "This client will quit itself now.";
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

                    }
                }

                // 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) {
                    if (LOG.isTraceEnabled()) {
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

 
  public static boolean singletonApp(String namefile) throws IOException{
    final File f = new File(namefile);
    if (f.exists()) f.delete();
    final FileChannel channel = new RandomAccessFile(f, "rw").getChannel();
    final FileLock lock = channel.tryLock();
    if(lock == null){
      JOptionPane.showMessageDialog(null, "���������� ��� ��������");
      channel.close();
      return false;
    }
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

                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                FileLock lock = null;
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    if (LOG.isTraceEnabled()) {
View Full Code Here

                    // Try the next file.
                    continue;
                }
                boolean available;
                try {
                    available = fc.tryLock() != null;
                    // We got the lock OK.
                } catch (IOException ix) {
                    // We got an IOException while trying to get the lock.
                    // This normally indicates that locking is not supported
                    // on the target directory.  We have to proceed without
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.