コード例 #1
0
  /** Merge the transactional caches into the shared cache */
  public void beforeCommit(boolean readOnly) {
    if (isDebugEnabled) {
      logger.debug("Processing before-commit");
    }

    TransactionData txnData = getTransactionData();
    try {
      if (txnData.isClearOn) {
        // clear shared cache
        final long startNanos = cacheStatsEnabled ? System.nanoTime() : 0;
        sharedCache.clear();
        final long endNanos = cacheStatsEnabled ? System.nanoTime() : 0;
        if (cacheStatsEnabled) {
          TransactionStats stats = txnData.stats;
          stats.record(startNanos, endNanos, OpType.CLEAR);
        }
        if (isDebugEnabled) {
          logger.debug("Clear notification recieved in commit - clearing shared cache");
        }
      } else {
        // transfer any removed items
        for (Serializable key : txnData.removedItemsCache) {
          final long startNanos = System.nanoTime();
          sharedCache.remove(key);
          final long endNanos = System.nanoTime();
          TransactionStats stats = txnData.stats;
          stats.record(startNanos, endNanos, OpType.REMOVE);
        }
        if (isDebugEnabled) {
          logger.debug(
              "Removed "
                  + txnData.removedItemsCache.size()
                  + " values from shared cache in commit");
        }
      }

      // transfer updates
      Set<Serializable> keys = (Set<Serializable>) txnData.updatedItemsCache.keySet();
      for (Map.Entry<Serializable, CacheBucket<V>> entry :
          (Set<Map.Entry<Serializable, CacheBucket<V>>>) txnData.updatedItemsCache.entrySet()) {
        Serializable key = entry.getKey();
        CacheBucket<V> bucket = entry.getValue();
        bucket.doPreCommit(
            sharedCache, key, this.isMutable, this.allowEqualsChecks, txnData.isReadOnly);
      }
      if (isDebugEnabled) {
        logger.debug("Pre-commit called for " + keys.size() + " values.");
      }
    } catch (Throwable e) {
      throw new AlfrescoRuntimeException("Failed to transfer updates to shared cache", e);
    } finally {
      // Block any further updates
      txnData.isClosed = true;
    }
  }
コード例 #2
0
 /**
  * Ensures that the transactional caches are removed from the common cache manager.
  *
  * @param txnData the data with references to the the transactional caches
  */
 private void removeCaches(TransactionData txnData) {
   txnData.isClosed = true;
 }