Ejemplo n.º 1
0
 @Override
 @SuppressWarnings({"unchecked"})
 public long getOrCreate(float o) {
   if (DependencyTracker.isBypassCaches()) {
     return calculatable.calculate(owner, o);
   } else {
     preCheckDirty();
     lock(o);
     try {
       Object v = load(o);
       ExceptionHelper.throwIfExceptionRecordNotExpired(v);
       if (v != UNDEFINED) {
         DependencyTracker.mark(getDependencyNode());
         hit();
         return (Long) 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);
               ExceptionHelper.throwIfExceptionRecordNotExpired(v);
               if (v != UNDEFINED) {
                 hit();
                 return (Long) v;
               }
             }
           }
         }
       } finally {
         DependencyTracker.exit(callerNode);
       }
     } finally {
       unlock(o);
       postCheckDirty();
     }
   }
 }
Ejemplo 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);
     }
   }
 }
  @Override
  public char getOrCreate(boolean 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);
      }
    }
  }