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 ListenerObjects more quickly. It keeps a local Map where requests are
mapped to Collections of ListenerObjects. This class extends from DefaultListenerObjectRetriever and adds caching to the retrieval methods, except
DefaultListenerObjectRetriever.getListenerObjects(), because that one simply returns all ListenerObjects.
This class implements the ListenerObjectCreationObserver in order to clear the cache if any new ListenerObjects are created by any of the ListenerObjectCreators
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
Nested ClassesModifier and TypeClassDescriptionprotected static classThis class represents the request made to thisCachedListenerObjectRetriever. -
Field Summary
FieldsFields inherited from class org.rribbit.retrieval.DefaultListenerObjectRetriever
listenerObjectCreators -
Constructor Summary
ConstructorsConstructorDescriptionWhenever you use this constructor, be sure to set theListenerObjectCreatorwith the setter provided by this class.CachedListenerObjectRetriever(ListenerObjectCreator... listenerObjectCreators) This constructor is recommended, since it forces you to specify theListenerObjectCreator. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListenerObjectCreator(ListenerObjectCreator listenerObjectCreator) Adds aListenerObjectCreatorto thisDefaultListenerObjectRetriever.protected voidChecks whether the hint is null, in order to be able to fullfill theListenerObjectRetrievercontract.protected voidcheckReturnType(Class<?> returnType) Checks whether the returntype is null, in order to be able to fullfill theListenerObjectRetrievercontract.protected voidgetListenerObjects(Class<?> returnType) Returns aCollectionofListenerObjects that satisfy the following requirements.getListenerObjects(Class<?> returnType, String hint) Returns aCollectionofListenerObjects that satisfy the following requirements.getListenerObjects(String hint) Returns aCollectionofListenerObjects that satisfy the following requirements.protected voidinit()Initializes the cache of thisCachedListenerObjectRetriever.voidonClassAdded(Class<?> addedClass) Clears the cache.voidsetListenerObjectCreator(ListenerObjectCreator listenerObjectCreator) Removes allListenerObjectCreators from thisDefaultListenerObjectRetrieverand adds only the given one.Methods inherited from class org.rribbit.retrieval.DefaultListenerObjectRetriever
getListenerObjectCreators, getListenerObjects, getListenerObjectsFromAllCreators, matchesHint, matchesReturnType
-
Field Details
-
cache
The cache ofCollections ofListenerObjects.
-
-
Constructor Details
-
CachedListenerObjectRetriever
public CachedListenerObjectRetriever()Whenever you use this constructor, be sure to set theListenerObjectCreatorwith the setter provided by this class. If you don't, runtimeNullPointerExceptions will occur. -
CachedListenerObjectRetriever
This constructor is recommended, since it forces you to specify theListenerObjectCreator. Passing a null value for this will result in runtimeNullPointerExceptions.- Parameters:
listenerObjectCreators-
-
-
Method Details
-
init
protected void init()Initializes the cache of thisCachedListenerObjectRetriever. -
onClassAdded
Clears the cache.- Specified by:
onClassAddedin interfaceListenerObjectCreationObserver- Parameters:
addedClass-
-
getListenerObjects
Description copied from interface:ListenerObjectRetrieverReturns aCollectionofListenerObjects that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject
- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Overrides:
getListenerObjectsin classDefaultListenerObjectRetriever- Parameters:
returnType- the return type that has to be assignable from the returntype of eachListenerObject- Returns:
- a
CollectionofListenerObjects that satisfy the above requirements, or an emptyCollectionif there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetrieverReturns aCollectionofListenerObjects that satisfy the following requirements.- The hints of the
ListenerObjectmust contain the 'hint' parameter
- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Overrides:
getListenerObjectsin classDefaultListenerObjectRetriever- Parameters:
hint- the hint that has to be contained by the hints of eachListenerObject- Returns:
- a
CollectionofListenerObjects that satisfy the above requirements, or an emptyCollectionif there were no matches. This method never returns null.
- The hints of the
-
getListenerObjects
Description copied from interface:ListenerObjectRetrieverReturns aCollectionofListenerObjects that satisfy the following requirements.- The parameter 'returnType' is assignable from the returntype of the
ListenerObject - The hints of the
ListenerObjectmust contain the 'hint' parameter
- Specified by:
getListenerObjectsin interfaceListenerObjectRetriever- Overrides:
getListenerObjectsin classDefaultListenerObjectRetriever- Parameters:
returnType- the return type that has to be assignable from the returntype of eachListenerObjecthint- the hint that has to be contained by the hints of eachListenerObject- Returns:
- a
CollectionofListenerObjects that satisfy the above requirements, or an emptyCollectionif there were no matches. This method never returns null.
- The parameter 'returnType' is assignable from the returntype of the
-
addListenerObjectCreator
Description copied from class:DefaultListenerObjectRetrieverAdds aListenerObjectCreatorto thisDefaultListenerObjectRetriever.- Overrides:
addListenerObjectCreatorin classDefaultListenerObjectRetriever- Parameters:
listenerObjectCreator- TheListenerObjectCreatorthat needs to be added to thisDefaultListenerObjectRetriever
-
setListenerObjectCreator
Description copied from class:DefaultListenerObjectRetrieverRemoves allListenerObjectCreators from thisDefaultListenerObjectRetrieverand adds only the given one. After invoking this method, only the givenListenerObjectCreatorwill be used by thisDefaultListenerObjectRetriever.- Overrides:
setListenerObjectCreatorin classDefaultListenerObjectRetriever- Parameters:
listenerObjectCreator- TheListenerObjectCreatorthat must be the soleListenerObjectCreatorused by thisDefaultListenerObjectRetriever
-
checkHint
Checks whether the hint is null, in order to be able to fullfill theListenerObjectRetrievercontract.- Parameters:
hint-
-
checkReturnType
Checks whether the returntype is null, in order to be able to fullfill theListenerObjectRetrievercontract.- Parameters:
returnType-
-
clearCache
protected void clearCache()
-