Package ca.uhn.fhir.jpa.cache
Class ResourceChangeListenerRegistryImpl
java.lang.Object
ca.uhn.fhir.jpa.cache.ResourceChangeListenerRegistryImpl
- All Implemented Interfaces:
IResourceChangeListenerRegistry
@Component
public class ResourceChangeListenerRegistryImpl
extends Object
implements IResourceChangeListenerRegistry
This component holds an in-memory list of all registered
IResourceChangeListener
instances along
with their caches and other details needed to maintain those caches. Register an IResourceChangeListener
instance
with this service to be notified when resources you care about are changed. This service quickly notifies listeners
of changes that happened on the local process and also eventually notifies listeners of changes that were made by
remote processes.-
Constructor Summary
ConstructorDescriptionResourceChangeListenerRegistryImpl
(ca.uhn.fhir.context.FhirContext theFhirContext, ResourceChangeListenerCacheFactory theResourceChangeListenerCacheFactory, InMemoryResourceMatcher theInMemoryResourceMatcher) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
boolean
contains
(IResourceChangeListenerCache theCache) int
iterator()
registerResourceResourceChangeListener
(String theResourceName, SearchParameterMap theSearchParameterMap, IResourceChangeListener theResourceChangeListener, long theRemoteRefreshIntervalMs) Register a listener in order to be notified whenever a resource matching the provided SearchParameterMap changes in any way.void
requestRefreshIfWatching
(org.hl7.fhir.instance.model.api.IBaseResource theResource) Called by theResourceChangeListenerRegistryInterceptor
when a resource is changed to invalidate matching caches so their listeners are notified the next time the caches are refreshed.int
size()
void
unregisterResourceResourceChangeListener
(IResourceChangeListener theResourceChangeListener) Unregister a listener from this servicevoid
unregisterResourceResourceChangeListener
(IResourceChangeListenerCache theResourceChangeListenerCache) Unregister a listener from this service using its cache handle
-
Constructor Details
-
ResourceChangeListenerRegistryImpl
public ResourceChangeListenerRegistryImpl(ca.uhn.fhir.context.FhirContext theFhirContext, ResourceChangeListenerCacheFactory theResourceChangeListenerCacheFactory, InMemoryResourceMatcher theInMemoryResourceMatcher)
-
-
Method Details
-
registerResourceResourceChangeListener
public IResourceChangeListenerCache registerResourceResourceChangeListener(String theResourceName, SearchParameterMap theSearchParameterMap, IResourceChangeListener theResourceChangeListener, long theRemoteRefreshIntervalMs) Register a listener in order to be notified whenever a resource matching the provided SearchParameterMap changes in any way. If the change happened on the same jvm process where this registry resides, then the listener will be called withinResourceChangeListenerCacheRefresherImpl.LOCAL_REFRESH_INTERVAL_MS
of the change happening. If the change happened on a different jvm process, then the listener will be called within theRemoteRefreshIntervalMs.- Specified by:
registerResourceResourceChangeListener
in interfaceIResourceChangeListenerRegistry
- Parameters:
theResourceName
- the type of the resource the listener should be notified about (e.g. "Subscription" or "SearchParameter")theSearchParameterMap
- the listener will only be notified of changes to resources that match this maptheResourceChangeListener
- the listener that will be called whenever resource changes are detectedtheRemoteRefreshIntervalMs
- the number of milliseconds between checking the database for changed resources that match the search parameter map- Returns:
- RegisteredResourceChangeListener that stores the resource id cache, and the next refresh time
- Throws:
DataFormatException
- if theResourceName is not a valid resource type in our FhirContextIllegalArgumentException
- if theSearchParamMap cannot be evaluated in-memory
-
unregisterResourceResourceChangeListener
public void unregisterResourceResourceChangeListener(IResourceChangeListener theResourceChangeListener) Unregister a listener from this service- Specified by:
unregisterResourceResourceChangeListener
in interfaceIResourceChangeListenerRegistry
- Parameters:
theResourceChangeListener
-
-
unregisterResourceResourceChangeListener
public void unregisterResourceResourceChangeListener(IResourceChangeListenerCache theResourceChangeListenerCache) Description copied from interface:IResourceChangeListenerRegistry
Unregister a listener from this service using its cache handle- Specified by:
unregisterResourceResourceChangeListener
in interfaceIResourceChangeListenerRegistry
- Parameters:
theResourceChangeListenerCache
-
-
iterator
-
size
-
clearCachesForUnitTest
-
contains
- Specified by:
contains
in interfaceIResourceChangeListenerRegistry
- Parameters:
theCache
-- Returns:
- true if theCache is registered
-
getResourceVersionCacheSizeForUnitTest
-
requestRefreshIfWatching
Description copied from interface:IResourceChangeListenerRegistry
Called by theResourceChangeListenerRegistryInterceptor
when a resource is changed to invalidate matching caches so their listeners are notified the next time the caches are refreshed.- Specified by:
requestRefreshIfWatching
in interfaceIResourceChangeListenerRegistry
- Parameters:
theResource
- the resource that changed that might trigger a refresh
-
getWatchedResourceNames
- Specified by:
getWatchedResourceNames
in interfaceIResourceChangeListenerRegistry
- Returns:
- a set of resource names watched by the registered listeners
-
clearListenersForUnitTest
- Specified by:
clearListenersForUnitTest
in interfaceIResourceChangeListenerRegistry
-