public class SynchronizedBuildCache<T extends DBObject>
A thread-safe cache of DBObjects. If trying to add a DBObject to the
cache when it already is there, the add operation blocks until the object
is removed (unless the object is being added by the same thread, in which
case the add operation returns false). This is used by builder classes to
ensure that they do not build the same object at the same time.
Strict equality (i.e. "==") is used for determining whether the objects
are the same.
This is intended to be used as a static cache as different threads are
likely to use different builder instances. Recommended usage is to define a
static SynchronizedBuildCache in the builder class. Just before building
an object, it should be added to this cache. After building, the object
should be removed via a try-finally mechanism.
Removes a listener for this build cache. Does nothing if the listener
is null or has not been previously added.
true if listener was removed
public boolean add(T object)
Add the object to the cache. If the object is already in the cache, this
blocks until the object is removed.
If the same thread calls this method twice on the same object without
calling remove first, then this method returns false and does not
update the cache.
object - the DBObject instance to add to the cache. If null, this
method returns immediately.
true, if added. This method returns false only if a null
parameter was passed in or the same thread attempts to add the same object
to the cache.