com.taco.util
Class CachedDelayedResult

java.lang.Object
  extended by com.taco.util.CachedDelayedResult
All Implemented Interfaces:
IDelayedResult, java.io.Serializable
Direct Known Subclasses:
CompositeConverter.DelayedConvertedResult

public abstract class CachedDelayedResult
extends java.lang.Object
implements IDelayedResult, java.io.Serializable

An implementation of IDelayedResult which caches the computed result.

See Also:
Serialized Form

Field Summary
protected  java.lang.Object _cachedResult
          The lazily computed and cached result.
protected  java.lang.Throwable _lastException
          The exception thrown when _computeResult() was run.
 
Constructor Summary
CachedDelayedResult()
           
 
Method Summary
protected abstract  java.lang.Object _computeResult()
          Compute the result.
 java.lang.Object force()
          If the result has been cached, return it.
 boolean hasBeenForced()
          Return true if the result has been computed already.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_cachedResult

protected java.lang.Object _cachedResult
The lazily computed and cached result.


_lastException

protected java.lang.Throwable _lastException
The exception thrown when _computeResult() was run.

Constructor Detail

CachedDelayedResult

public CachedDelayedResult()
Method Detail

force

public final java.lang.Object force()
If the result has been cached, return it. If an exception was thrown when _computeResult() was called last time, throw a RuntimeException whose cause is that exception. Otherwise, call _computeResult() and save it in the cache. This method is synchronized so it is thread-safe.

Specified by:
force in interface IDelayedResult

hasBeenForced

public final boolean hasBeenForced()
Return true if the result has been computed already.


_computeResult

protected abstract java.lang.Object _computeResult()
Compute the result. If an exception occurs, catch it and save it in _lastException.