Example #1
0
  private boolean onStartWork() {
    if (fileLock != null) {
      return false;
    }
    fileLock =
        lockManager.lock(
            lockFile,
            lockOptions.withMode(Exclusive),
            cacheDisplayName,
            operations.getDescription());
    stateAtOpen = fileLock.getState();
    for (UnitOfWorkParticipant cache : caches) {
      cache.onStartWork(operations.getDescription(), stateAtOpen);
    }

    lockManager.allowContention(fileLock, whenContended());

    return true;
  }
Example #2
0
 /**
  * Opens this cache access with the given lock mode. Calling this with {@link
  * org.gradle.cache.internal.FileLockManager.LockMode#Exclusive} will lock the cache for exclusive
  * access from all other threads (including those in this process and all other processes), until
  * {@link #close()} is called.
  *
  * @param lockOptions
  */
 public void open(LockOptions lockOptions) {
   lock.lock();
   try {
     if (owner != null) {
       throw new IllegalStateException(
           String.format("Cannot open the %s, as it is already in use.", cacheDisplayName));
     }
     this.lockOptions = lockOptions;
     if (lockOptions.getMode() == FileLockManager.LockMode.None) {
       return;
     }
     if (fileLock != null) {
       throw new IllegalStateException("File lock " + lockFile + " is already open.");
     }
     fileLock = lockManager.lock(lockFile, lockOptions, cacheDisplayName);
     stateAtOpen = fileLock.getState();
     takeOwnership(String.format("Access %s", cacheDisplayName));
     lockManager.allowContention(fileLock, whenContended());
   } finally {
     lock.unlock();
   }
 }