org.jasig.portlet.calendar.spring
Class DoubleCheckedCreator<T>

java.lang.Object
  extended by org.jasig.portlet.calendar.spring.DoubleCheckedCreator<T>
Direct Known Subclasses:
SingletonDoubleCheckedCreator

public abstract class DoubleCheckedCreator<T>
extends Object

Implementation of double-checked locking for object creation using a ReadWriteLock

Version:
$Revision: 22522 $
Author:
Eric Dalquist

Field Summary
protected  org.apache.commons.logging.Log logger
           
protected  Lock readLock
           
protected  Lock writeLock
           
 
Constructor Summary
DoubleCheckedCreator()
           
DoubleCheckedCreator(ReadWriteLock readWriteLock)
           
 
Method Summary
protected abstract  T create(Object... args)
           
 T get(Object... args)
          Double checking retrieval/creation of an object
protected  boolean invalid(T value, Object... args)
          The default impl returns true if value is null.
protected abstract  T retrieve(Object... args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger

readLock

protected final Lock readLock

writeLock

protected final Lock writeLock
Constructor Detail

DoubleCheckedCreator

public DoubleCheckedCreator()

DoubleCheckedCreator

public DoubleCheckedCreator(ReadWriteLock readWriteLock)
Method Detail

create

protected abstract T create(Object... args)
Parameters:
args - Arguments to use when creating the object
Returns:
A newly created object

retrieve

protected abstract T retrieve(Object... args)
Parameters:
args - Arguments to use when retrieving the object
Returns:
An existing object if available

invalid

protected boolean invalid(T value,
                          Object... args)
The default impl returns true if value is null.

Parameters:
value - The object to validate
args - Arguments to use when validating the object
Returns:
true if the object is invalid and should be created, false if not.

get

public final T get(Object... args)
Double checking retrieval/creation of an object

Parameters:
args - Optional arguments to pass to retrieve(Object...), create(Object...), and invalid(Object, Object...).
Returns:
A retrieved or created object.


Copyright © 2012 Jasig. All Rights Reserved.