|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.singleton.StatelessSingletonRegistry<T>
T
- The super type of all singleton types handled by
this registry. Use Object
if any type
of singleton type can be handled.public class StatelessSingletonRegistry<T>
A stateless singleton registry is a registry with no
internal state that allows any type annotated correctly
with the Singleton
annotation to be fetched, and
possibly created, using the getInstance(Class)
method.
Implementation notes:
This registry do not utilise an internal cache to store the
acquired singletons because that would require synchronisation.
Furthermore, we do not know how the actual singleton classes are
implemented, i.e. static initialisation, lazily initialised, synchronised,
or not synchronised!? Hence, each time the getInstance(Class)
method is invoked the call is forwarded to the actual singleton
method identified by the Singleton
annotation used to
annotate the type supplied as the Class
argument. This means
that all singleton initialisation and creation is handled by the
individual singleton types!
Constructor Summary | |
---|---|
StatelessSingletonRegistry()
Constructor. |
Method Summary | ||
---|---|---|
|
getInstance(Class<S> type)
Returns the singleton instance of the type supplied as type . |
|
boolean |
isSingleton(Class<?> type)
Returns true of the type supplied as type is a singleton
type handled by this registry, false if not. |
|
String |
toString()
Returns the string representation of this registry. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public StatelessSingletonRegistry()
Method Detail |
---|
public <S extends T> S getInstance(Class<S> type)
SingletonRegistry
type
.
Whether or not type
is a singleton type handled
by this registry can be determined by the SingletonRegistry.isSingleton(Class)
method.
getInstance
in interface SingletonRegistry<T>
S
- The actual singleton type.type
- The class token identifying the singleton type; cannot be null.
type
;
never null.
NullPointerException
- If type
is null.
SingletonException
- If type
is not a singleton type
handled by this registry, or if the type cannot be created when
first requested.public boolean isSingleton(Class<?> type)
SingletonRegistry
type
is a singleton
type handled by this registry, false if not.
Even if this method returns true, the actual singleton instance
may not be created before it is requested
.
The creation of the singleton instance can therefore still
fail!
isSingleton
in interface SingletonRegistry<T>
type
- The class token identifying the type; cannot be null.
type
represents a singleton type handled by
this registry.
NullPointerException
- If type
is null.public String toString()
toString
in class Object
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |