ro.isdc.wro.util
Class DestroyableLazyInitializer<T>

java.lang.Object
  extended by ro.isdc.wro.util.DestroyableLazyInitializer<T>

public abstract class DestroyableLazyInitializer<T>
extends Object

A clone of LazyInitializer, which doesn't throw any checked exception when get method is invoked. Also, it allows to destroy the created object.

Since:
1.4.2
Author:
Alex Objelean

Constructor Summary
DestroyableLazyInitializer()
           
 
Method Summary
 void destroy()
          Destroy the initialized object.
 T get()
          Returns the object wrapped by this instance.
protected abstract  T initialize()
          Creates and initializes the object managed by this LazyInitializer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DestroyableLazyInitializer

public DestroyableLazyInitializer()
Method Detail

get

public T get()
Returns the object wrapped by this instance. On first access the object is created. After that it is cached and can be accessed pretty fast.

Returns:
the object initialized by this LazyInitializer the object

destroy

public final void destroy()
Destroy the initialized object. This will trigger the re-initialization when get() method is invoked.


initialize

protected abstract T initialize()
Creates and initializes the object managed by this LazyInitializer. This method is called by get() when the object is accessed for the first time. An implementation can focus on the creation of the object. No synchronization is needed, as this is already handled by get().

Returns:
the managed data object


Copyright © 2008-2011. All Rights Reserved.