com.wideplay.warp.persist.internal
Class LazyReference<T>

java.lang.Object
  extended by com.wideplay.warp.persist.internal.LazyReference<T>

@ThreadSafe
public class LazyReference<T>
extends Object

Utility to lazily load an object reference. It uses Double-Checked Locking under the covers and thus can safely be accessed from multiple threads concurrently.


Method Summary
 T get()
          Get the existing T instance, or lazily initialize T using instanceProvider.
static
<T> LazyReference<T>
of(com.google.inject.Provider<T> instanceProvider)
          Create a lazy reference with a provider of the eventual instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public T get()
Get the existing T instance, or lazily initialize T using instanceProvider.

Returns:
the T instance unique to this LazyReference

of

public static <T> LazyReference<T> of(com.google.inject.Provider<T> instanceProvider)
Create a lazy reference with a provider of the eventual instance.

Parameters:
instanceProvider - a Provider that gives out the eventual instance, usually an expensive operation
Returns:
an uninitialized reference to T