Пример #1
0
 protected short create(long key) {
   long start = System.nanoTime();
   short t = calculatable.calculate(owner, key);
   long end = System.nanoTime();
   miss(end - start);
   save(key, t);
   return t;
 }
Пример #2
0
  @Override
  public short getOrCreate(long o) {
    if (DependencyTracker.isBypassCaches()) {
      return calculatable.calculate(owner, o);
    } else {
      lock(o);
      try {
        if (isCalculated(o)) {
          DependencyTracker.mark(getDependencyNode());
          hit();
          return load(o);
        }

        DependencyNode callerNode = DependencyTracker.track(getDependencyNode());
        try {
          while (true) {
            try {
              return create(o);
            } catch (ResourceOccupied e) {
              if (callerNode != null) {
                throw e;
              } else {
                unlock(o);
                try {
                  e.getResource().waitForEndOfModification();
                } finally {
                  lock(o);
                }
                if (isCalculated(o)) {
                  hit();
                  return load(o);
                }
              }
            }
          }
        } finally {
          DependencyTracker.exit(callerNode);
        }
      } finally {
        unlock(o);
      }
    }
  }
Пример #3
0
 @Override
 public CacheDescriptor getDescriptor() {
   CacheId id = CalculatableHelper.getId(calculatable.getClass());
   return CacheFactory.getProvider().getDescriptor(id);
 }