Java 8 FileLock - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 FileLock class.

This code example shows how to use the following methods: channel, isValid, release
        } 
        return lock != null;
    } 
 
    public void release() throws Exception {
        if (lock != null && lock.isValid()) {
            LOG.info("Releasing lock " + lockPath.getPath());
            lock.release();
            lock.channel().close();
        } 
        lock = null;
    } 
  
    public boolean isAlive() throws Exception {
        return lock != null && lock.isValid() && lockPath.exists();
    } 
 
    private static File getKarafLock(File lock,Properties props) {
        File rc = null;
 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: channel, isShared, position, size
     * @param position 
     * @param size 
     * @param shared 
     */ 
    public SqlJetFileLock(SqlJetFileLockManager manager, FileLock fileLock) {
        super(fileLock.channel(), fileLock.position(), fileLock.size(), fileLock.isShared());
        this.manager = manager;
        this.fileLock = fileLock;
        this.locksCount = 1;
    } 
 
    /* 
     * (non-Javadoc) 
     *  
     * @see java.nio.channels.FileLock#isValid() 
     */ 
    @Override 
    public boolean isValid() { 
        return fileLock.isValid();
    } 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: release
    } 
 
    public void release() 
    { 
        try { 
            lock.release();
        } 
        catch (IOException e) {
            Throwables.propagate(e);
        } 
        finally { 
            Closeables.closeQuietly(channel);
        } 
    } 
 
    @Override 
    public String toString()
    { 
        StringBuilder sb = new StringBuilder();
        sb.append("DbLock");
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: release
String msg = "hello from" + instanceName + " " + i + LINE_SEPARATOR;
      fos.write(msg.getBytes());
    } finally { 
      if (fileLock != null) {
        fileLock.release();
      } 
    } 
  } 
 
  static void printDotAndSleep(int i) throws InterruptedException {
    if (i % DOT_FREQ == 0) {
      System.out.print(".");
      Thread.sleep(delay);
    } 
    if (i % DOT_WITH_NEW_LINE_FREQ == 0) System.out.println("");
  } 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: channel, release
 
        // must call super 
        super.releaseExclusiveReadLock(operations, file, exchange);
 
        if (lock != null) {
            Channel channel = lock.channel();
            try { 
                lock.release();
            } finally { 
                // must close channel first 
                IOHelper.close(channel, "while releasing exclusive read lock for file: " + lockFileName, LOG);
            } 
        } 
    } 
 
    private boolean sleep() { 
        LOG.trace("Exclusive read lock not granted. Sleeping for {} millis.", checkInterval);
        try { 
            Thread.sleep(checkInterval);
            return false; 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: isValid, release
            // Expected 
        } 
 
        // Adjacent locks are legal 
        FileLock adjacentLock = readOnlyChannel.tryLock(1, 3, true);
        assertTrue(adjacentLock.isValid());
        adjacentLock.release();
 
        // Release longer lived lock 
        lock.release();
    } 
} 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: release
    { 
        if ( lock != null )
        { 
            try 
            { 
                lock.release();
            } 
            catch ( IOException e )
            { 
                logger.warn( "Error releasing lock for resolution tracking file " + file, e );
            } 
        } 
    } 
 
    private void close( Closeable closeable, File file )
    { 
        if ( closeable != null )
        { 
            try 
            { 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: release
 
    public void unlock(File fileToUnlock) {
        FileLock fileLock = lockCache.get(fileToUnlock);
        try { 
            if (fileLock != null) {
                fileLock.release();
            } 
            FileChannelCache.closeChannelFor(fileToUnlock);
        } catch (IOException e) {
            throw new MessagingException("Failed to unlock file: " 
                    + fileToUnlock, e);
        } 
	} 
} 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: release
      // Mainly to catch FileLockInterruptionExceptions (see LOGBACK-875) 
      resilientFOS.postIOFailure(e);
    } 
    finally { 
      if (fileLock != null) {
        fileLock.release();
      } 
 
      // Re-interrupt if we started in an interrupted state (see LOGBACK-875) 
      if (interrupted) {
        Thread.currentThread().interrupt();
      } 
    } 
  } 
 
  @Override 
  protected void writeOut(E event) throws IOException {
    if (prudent) {
      safeWrite(event);
    } else { 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: isShared, release
        { 
            if (raf != null)
                close(raf);
            return false; 
        } 
        else if (lock.isShared())
        { 
            release(); 
            return false; 
        } 
        else 
            return true; 
    } 
 
    /** 
     * Return true if the write lock is currently acquired exclusively. 
     */ 
    public synchronized boolean isLocked() 
    { 
        return (lock != null && !lock.isShared());

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 FileLock Questions & Answers:

See Code Examples for Java 8 FileLock Methods: