コード例 #1
0
 protected char create(boolean key) {
   long start = System.nanoTime();
   char t = calculatable.calculate(owner, key);
   long end = System.nanoTime();
   miss(end - start);
   save(key, t);
   return t;
 }
コード例 #2
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;
 }
コード例 #3
0
 protected float create(double key) {
   long start = System.nanoTime();
   float t = calculatable.calculate(owner, key);
   long end = System.nanoTime();
   miss(end - start);
   save(key, t);
   return t;
 }
コード例 #4
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;
 }
コード例 #5
0
 @SuppressWarnings({"unchecked"})
 protected long create(float o) {
   long start = System.nanoTime();
   try {
     int retry = 0;
     // retry on exception loop
     while (true) {
       try {
         long t = calculatable.calculate(owner, o);
         // successful invocation => just store the value and return
         save(o, t);
         return t;
       } catch (Exception e) {
         // We catch Exception here, but not Error and not Throwable.
         // this is because in case of Error we are likely have no chance even to save
         // an ExceptionRecord to a storage, so don't even try to do so.
         // For example in case of OOM (out of memory) it may be impossible to create
         // even a single new object.
         CacheExceptionHandler exceptionHandler = getDescriptor().getExceptionHandler();
         switch (exceptionHandler.getAction(retry, e)) {
           case RETRY:
             retry++;
             continue;
           case REMEMBER_AND_RETHROW:
             save(
                 o,
                 new ExceptionRecord(
                     e, exceptionHandler.getRememberExceptionExpirationTimestamp(e)));
             // fall through
           case RETHROW:
           default:
             // this method always throws an exception
             ExceptionHelper.throwCheckedExceptionHack(e);
             break;
         }
       }
     }
   } finally {
     // record calculation time even if calculation fails
     long end = System.nanoTime();
     miss(end - start);
   }
 }