Example #1
0
 private void releaseOwnership() {
   lock.lock();
   try {
     operations.popCacheAction();
     if (!operations.isInCacheAction()) {
       owner = null;
       condition.signalAll();
     }
   } finally {
     lock.unlock();
   }
 }
Example #2
0
 private void finishLongRunningOperation(boolean wasEnded) {
   lock.lock();
   try {
     operations.popLongRunningOperation();
     if (operations.isInCacheAction()) {
       restoreOwner();
       if (wasEnded) {
         onStartWork();
       }
     }
   } finally {
     lock.unlock();
   }
 }
Example #3
0
  public <K, V> MultiProcessSafePersistentIndexedCache<K, V> newCache(
      final PersistentIndexedCacheParameters<K, V> parameters) {
    Factory<BTreePersistentIndexedCache<K, V>> indexedCacheFactory =
        new Factory<BTreePersistentIndexedCache<K, V>>() {
          public BTreePersistentIndexedCache<K, V> create() {
            return doCreateCache(
                parameters.getCacheFile(),
                parameters.getKeySerializer(),
                parameters.getValueSerializer());
          }
        };
    MultiProcessSafePersistentIndexedCache<K, V> indexedCache =
        parameters.decorate(
            new DefaultMultiProcessSafePersistentIndexedCache<K, V>(
                indexedCacheFactory, fileAccess));

    lock.lock();
    try {
      caches.add(indexedCache);
      if (fileLock != null) {
        indexedCache.onStartWork(operations.getDescription(), stateAtOpen);
      }
    } finally {
      lock.unlock();
    }
    return indexedCache;
  }
Example #4
0
 private boolean startLongRunningOperation(String operationDisplayName) {
   boolean wasEnded;
   lock.lock();
   try {
     if (operations.isInCacheAction()) {
       checkThreadIsOwner();
       wasEnded = onEndWork();
       owner = null;
       condition.signalAll();
     } else {
       wasEnded = false;
     }
     operations.pushLongRunningOperation(operationDisplayName);
   } finally {
     lock.unlock();
   }
   return wasEnded;
 }
Example #5
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 #6
0
 private void takeOwnership(String operationDisplayName) {
   lock.lock();
   try {
     while (owner != null && owner != Thread.currentThread()) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.throwAsUncheckedException(e);
       }
     }
     owner = Thread.currentThread();
     operations.pushCacheAction(operationDisplayName);
   } finally {
     lock.unlock();
   }
 }