public class SimpleResourceRegistry extends Object implements ResourceRegistry
SimpleResourceRegistry is a basic implementation of a ResourceRegistry.| Modifier and Type | Class and Description |
|---|---|
protected class |
SimpleResourceRegistry.RegistryKey
Key class for a registered resource.
|
protected class |
SimpleResourceRegistry.RegistryValue
A holder for resource objects and their (optional) respective
ResourceLifecycleObservers. |
ResourceRegistry.ResourceLifecycleObserver<R>DEFAULT_NAME| Constructor and Description |
|---|
SimpleResourceRegistry()
Construct a
SimpleResourceRegistry. |
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Invoked when all resources owned by the implementer can safely be released.
|
<R> R |
getResource(Class<R> clzResource)
Attempts to retrieve the resource that was registered with the specified class.
|
<R> R |
getResource(Class<R> clzResource, String sResourceName)
Attempts to retrieve the resource that was registered with the specified class and name.
|
boolean |
isEmpty()
Determine if the
ResourceRegistry is empty (contains no resource registrations). |
<R> String |
registerResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
Registers a resource according to the specified
RegistrationBehavior. |
<R> String |
registerResource(Class<R> clzResource, R resource)
Registers the resource for later retrieval with
ResourceResolver.getResource(Class). |
<R> String |
registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
Registers a resource according to the specified
RegistrationBehavior. |
<R> String |
registerResource(Class<R> clzResource, String sResourceName, R resource)
Registers the resource with the specified name for later retrieval with
ResourceResolver.getResource(Class, String). |
<R> void |
unregisterResource(Class<R> clzResource, String sResourceName)
Unregisters the resource that was previously registered of the specified class and name.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclosepublic SimpleResourceRegistry()
SimpleResourceRegistry.public boolean isEmpty()
ResourceRegistry is empty (contains no resource registrations).public void dispose()
Once disposed of the object should no longer be considered to be usable.
Note the Disposable interface is compatible with try-with-resources which will automatically invoke this method.
dispose in interface Disposablepublic <R> R getResource(Class<R> clzResource)
getResource in interface ResourceResolverR - the type of the resourceclzResource - the class of the resourcenull if the resource is unknown to the ResourceRegistrypublic <R> R getResource(Class<R> clzResource, String sResourceName)
getResource in interface ResourceResolverR - the type of the resourceclzResource - the class of the resourcesResourceName - the name of the resourcenull if the resource is unknown to the ResourceRegistrypublic <R> String registerResource(Class<R> clzResource, R resource)
ResourceResolver.getResource(Class).
Notes:
ResourceRegistry.registerResource(Class, String, Object)Disposable will be disposed when the ResourceRegistry is disposed.registerResource in interface ResourceRegistryclzResource - the class of the resourceresource - the resourcepublic <R> String registerResource(Class<R> clzResource, String sResourceName, R resource)
ResourceResolver.getResource(Class, String).
Notes:
Disposable will be disposed when the ResourceRegistry is disposed.registerResource in interface ResourceRegistryclzResource - the class of the resourcesResourceName - the proposed name of the resourceresource - the resourcepublic <R> String registerResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
RegistrationBehavior. If successful the registered resource may later be retrieved using method ResourceResolver.getResource(Class).
Notes:
ResourceRegistry.registerResource(Class, String, Builder, RegistrationBehavior, ResourceLifecycleObserver)Disposable will be disposed when the ResourceRegistry is disposed.registerResource in interface ResourceRegistryR - the type of the resourceclzResource - the class of the resourcebldrResource - the Builder to realize the resource to register (if required the specified behavior requires a resource)behavior - the RegistrationBehavior to useobserver - an optional ResourceRegistry.ResourceLifecycleObserver that will be called when the resource is being released from the ResourceRegistry (may be null)public <R> String registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
RegistrationBehavior. If successful the registered resource may later be retrieved using method ResourceResolver.getResource(Class, String).
Notes:
Disposable will be disposed when the ResourceRegistry is disposed.registerResource in interface ResourceRegistryR - the type of the resourceclzResource - the class of the resourcesResourceName - the proposed name of the resourcebldrResource - the Builder to realize the resource to register (if required the specified behavior requires a resource)behavior - the RegistrationBehavior to useobserver - an optional ResourceRegistry.ResourceLifecycleObserver that will be called when the resource is being released from the ResourceRegistry (may be null)public <R> void unregisterResource(Class<R> clzResource, String sResourceName)
Note: Unregistering a resource does not cause it to be disposed, but it does call ResourceRegistry.ResourceLifecycleObserver.onRelease(Object) if an observer was provided at the time of registration.
unregisterResource in interface ResourceRegistryR - the type of the resourceclzResource - the class of the resourcesResourceName - the name of the resource