Package org.rribbit.retrieval
Class CachedListenerObjectRetriever
java.lang.Object
org.rribbit.retrieval.DefaultListenerObjectRetriever
org.rribbit.retrieval.CachedListenerObjectRetriever
- All Implemented Interfaces:
ListenerObjectCreationObserver
,ListenerObjectRetriever
public class CachedListenerObjectRetriever
extends DefaultListenerObjectRetriever
implements ListenerObjectCreationObserver
This
ListenerObjectRetriever
implements caching to be able to retrieve ListenerObject
s more quickly. It keeps a local Map
where requests are
mapped to Collection
s of ListenerObject
s. This class extends from DefaultListenerObjectRetriever
and adds caching to the retrieval methods, except
DefaultListenerObjectRetriever.getListenerObjects()
, because that one simply returns all ListenerObject
s.
This class implements the ListenerObjectCreationObserver
in order to clear the cache if any new ListenerObject
s are created by any of the ListenerObjectCreator
s
that are associated with this CachedListenerObjectRetriever
. Also, if you add a ListenerObjectCreator
to this CachedListenerObjectRetriever
, the cache will
be cleared as well.- Author:
- G.J. Schouten
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
This class represents the request made to thisCachedListenerObjectRetriever
. -
Field Summary
Fields inherited from class org.rribbit.retrieval.DefaultListenerObjectRetriever
listenerObjectCreators
-
Constructor Summary
ConstructorDescriptionWhenever you use this constructor, be sure to set theListenerObjectCreator
with the setter provided by this class.CachedListenerObjectRetriever
(ListenerObjectCreator... listenerObjectCreators) This constructor is recommended, since it forces you to specify theListenerObjectCreator
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListenerObjectCreator
(ListenerObjectCreator listenerObjectCreator) Adds aListenerObjectCreator
to thisDefaultListenerObjectRetriever
.protected void
Checks whether the hint is null, in order to be able to fullfill theListenerObjectRetriever
contract.protected void
checkReturnType
(Class<?> returnType) Checks whether the returntype is null, in order to be able to fullfill theListenerObjectRetriever
contract.protected void
getListenerObjects
(Class<?> returnType) Returns aCollection
ofListenerObject
s that satisfy the following requirements.getListenerObjects
(Class<?> returnType, String hint) Returns aCollection
ofListenerObject
s that satisfy the following requirements.getListenerObjects
(String hint) Returns aCollection
ofListenerObject
s that satisfy the following requirements.protected void
init()
Initializes the cache of thisCachedListenerObjectRetriever
.void
onClassAdded
(Class<?> addedClass) Clears the cache.void
setListenerObjectCreator
(ListenerObjectCreator listenerObjectCreator) Removes allListenerObjectCreator
s from thisDefaultListenerObjectRetriever
and adds only the given one.Methods inherited from class org.rribbit.retrieval.DefaultListenerObjectRetriever
getListenerObjectCreators, getListenerObjects, getListenerObjectsFromAllCreators, matchesHint, matchesReturnType
-
Field Details
-
cache
The cache ofCollection
s ofListenerObject
s.
-
-
Constructor Details
-
CachedListenerObjectRetriever
public CachedListenerObjectRetriever()Whenever you use this constructor, be sure to set theListenerObjectCreator
with the setter provided by this class. If you don't, runtimeNullPointerException
s will occur. -
CachedListenerObjectRetriever
This constructor is recommended, since it forces you to specify theListenerObjectCreator
. Passing a null value for this will result in runtimeNullPointerException
s.- Parameters:
listenerObjectCreators
-
-
-
Method Details
-
init
protected void init()Initializes the cache of thisCachedListenerObjectRetriever
. -
onClassAdded
Clears the cache.- Specified by:
onClassAdded
in interfaceListenerObjectCreationObserver
- Parameters:
addedClass
-
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
Returns aCollection
ofListenerObject
s that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Overrides:
getListenerObjects
in classDefaultListenerObjectRetriever
- Parameters:
returnType
- the return type that has to be assignable from the returntype of eachListenerObject
- Returns:
- a
Collection
ofListenerObject
s that satisfy the above requirements, or an emptyCollection
if there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
Returns aCollection
ofListenerObject
s that satisfy the following requirements.- The hints of the
ListenerObject
must contain the 'hint' parameter
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Overrides:
getListenerObjects
in classDefaultListenerObjectRetriever
- Parameters:
hint
- the hint that has to be contained by the hints of eachListenerObject
- Returns:
- a
Collection
ofListenerObject
s that satisfy the above requirements, or an emptyCollection
if there were no matches. This method never returns null.
- The hints of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetriever
Returns aCollection
ofListenerObject
s that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject
- The hints of the
ListenerObject
must contain the 'hint' parameter
- Specified by:
getListenerObjects
in interfaceListenerObjectRetriever
- Overrides:
getListenerObjects
in classDefaultListenerObjectRetriever
- Parameters:
returnType
- the return type that has to be assignable from the returntype of eachListenerObject
hint
- the hint that has to be contained by the hints of eachListenerObject
- Returns:
- a
Collection
ofListenerObject
s that satisfy the above requirements, or an emptyCollection
if there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
addListenerObjectCreator
Description copied from class:DefaultListenerObjectRetriever
Adds aListenerObjectCreator
to thisDefaultListenerObjectRetriever
.- Overrides:
addListenerObjectCreator
in classDefaultListenerObjectRetriever
- Parameters:
listenerObjectCreator
- TheListenerObjectCreator
that needs to be added to thisDefaultListenerObjectRetriever
-
setListenerObjectCreator
Description copied from class:DefaultListenerObjectRetriever
Removes allListenerObjectCreator
s from thisDefaultListenerObjectRetriever
and adds only the given one. After invoking this method, only the givenListenerObjectCreator
will be used by thisDefaultListenerObjectRetriever
.- Overrides:
setListenerObjectCreator
in classDefaultListenerObjectRetriever
- Parameters:
listenerObjectCreator
- TheListenerObjectCreator
that must be the soleListenerObjectCreator
used by thisDefaultListenerObjectRetriever
-
checkHint
Checks whether the hint is null, in order to be able to fullfill theListenerObjectRetriever
contract.- Parameters:
hint
-
-
checkReturnType
Checks whether the returntype is null, in order to be able to fullfill theListenerObjectRetriever
contract.- Parameters:
returnType
-
-
clearCache
protected void clearCache()
-