Exemplo n.º 1
0
 @SuppressWarnings({"unchecked"})
 protected F create(E key) {
   long start = System.nanoTime();
   F t = calculatable.calculate(owner, key);
   long end = System.nanoTime();
   miss(end - start);
   save(key, t);
   return t;
 }
Exemplo n.º 2
0
 @Override
 @SuppressWarnings({"unchecked"})
 public F getOrCreate(E o) {
   if (DependencyTracker.isBypassCaches()) {
     return calculatable.calculate(owner, o);
   } else {
     lock(o);
     try {
       Object v = load(o);
       if (v != UNDEFINED) {
         DependencyTracker.mark(getDependencyNode());
         hit();
         return (F) v;
       }
       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);
               }
               v = load(o);
               if (v != UNDEFINED) {
                 hit();
                 return (F) v;
               }
             }
           }
         }
       } finally {
         DependencyTracker.exit(callerNode);
       }
     } finally {
       unlock(o);
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public CacheDescriptor getDescriptor() {
   CacheId id = CalculatableHelper.getId(calculatable.getClass());
   return CacheFactory.getProvider().getDescriptor(id);
 }