Source:
public <R> R access(Function<VersionLockedObject<T>, Boolean> directAccessCheckFunction, Consumer<VersionLockedObject<T>> updateFunction, Function<T, R> accessFunction) { long ts = lock.tryOptimisticRead(); if (ts != 0) { Timer optimisticReadTimer = VloMetricsParams .metrics.timer(VloMetricsParams.VLO_OPTIMISTIC_READ); try (Timer.Context optimistReadDuration = MetricsUtils.getConditionalContext(optimisticReadTimer)) { if (directAccessCheckFunction.apply(this)) { log.trace("Access Direct (optimistic-read) access at {}", this, getVersionUnsafe()); R ret = accessFunction.apply(object); long versionForCorrectness = getVersionUnsafe(); if (lock.validate(ts)) { correctnessLogger.trace("Version, {}", versionForCorrectness); return ret; } } } catch (Exception e) { if (lock.validate(ts)) { throw e; } log.warn("Access Direct (optimistic-read) exception, upgrading lock", this); } } Timer updatedObjectReadTimer = VloMetricsParams .metrics.timer(VloMetricsParams.VLO_UPDATED_OBJECT_READ); try (Timer.Context updateObjectReadDuration = MetricsUtils.getConditionalContext(updatedObjectReadTimer)) { ts = lock.tryConvertToWriteLock(ts); if (ts == 0) { ts = lock.writeLock(); } if (directAccessCheckFunction.apply(this)) { log.trace("Access Direct (writelock) access at {}", this, getVersionUnsafe()); R ret = accessFunction.apply(object); long versionForCorrectness = getVersionUnsafe(); if (lock.validate(ts)) { correctnessLogger.trace("Version, {}", versionForCorrectness); return ret; } } updateFunction.accept(this); correctnessLogger.trace("Version, {}", getVersionUnsafe()); log.trace("Access Updated (writelock) access at {}", this, getVersionUnsafe()); return accessFunction.apply(object); } finally { lock.unlock(ts); } }

Target:
public <R> R access(Function<VersionLockedObject<T>, Boolean> directAccessCheckFunction, Consumer<VersionLockedObject<T>> updateFunction, Function<T, R> accessFunction) { long ts = lock.tryOptimisticRead(); if (ts != 0) { try (Timer.Context optimistReadDuration = VloMetricsHelper.getOptimisticReadContext()) { if (directAccessCheckFunction.apply(this)) { log.trace("Access Direct (optimistic-read) access at {}", this, getVersionUnsafe()); R ret = accessFunction.apply(object); long versionForCorrectness = getVersionUnsafe(); if (lock.validate(ts)) { correctnessLogger.trace("Version, {}", versionForCorrectness); return ret; } } } catch (Exception e) { if (lock.validate(ts)) { throw e; } log.warn("Access Direct (optimistic-read) exception, upgrading lock", this); } } try (Timer.Context updateObjectReadDuration = VloMetricsHelper.getUpdatedObjectReadContext()) { ts = lock.tryConvertToWriteLock(ts); if (ts == 0) { ts = lock.writeLock(); } if (directAccessCheckFunction.apply(this)) { log.trace("Access Direct (writelock) access at {}", this, getVersionUnsafe()); R ret = accessFunction.apply(object); long versionForCorrectness = getVersionUnsafe(); if (lock.validate(ts)) { correctnessLogger.trace("Version, {}", versionForCorrectness); return ret; } } updateFunction.accept(this); correctnessLogger.trace("Version, {}", getVersionUnsafe()); log.trace("Access Updated (writelock) access at {}", this, getVersionUnsafe()); return accessFunction.apply(object); } finally { lock.unlock(ts); } }