Package com.tangosol.util
Interface ResourceRegistry
- All Superinterfaces:
AutoCloseable,Disposable,ResourceResolver
- All Known Implementing Classes:
NullImplementation.NullResourceRegistry,SimpleResourceRegistry,SimpleResourceResolver
A
ResourceRegistry is a registry and owner of strongly typed and
explicitly named resources.
When a resource is registered with a ResourceRegistry, the
ResourceRegistry assumes ownership of the said resource, up until
at which point the ResourceRegistry is disposed.
Important: Although a ResourceRegistry manages
resources in a thread-safe manner, it is possible for a thread calling
ResourceResolver.getResource(Class, String) to receive a null return
value while another thread is registering a resource.
- Since:
- Coherence 12.1.2
- Author:
- bo 2011.06.05
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceTheResourceRegistry.ResourceLifecycleObserverinterface defines lifecycle handlers for resources registered with aResourceRegistry. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name to use for the registration of a singleton and thus default resource. -
Method Summary
Modifier and TypeMethodDescription<R> StringregisterResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer) Registers a resource according to the specifiedRegistrationBehavior.<R> StringregisterResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer) Registers a resource according to the specifiedRegistrationBehavior.<R> StringregisterResource(Class<R> clzResource, String sResourceName, R resource) Registers the resource with the specified name for later retrieval withResourceResolver.getResource(Class, String).<R> StringregisterResource(Class<R> clzResource, R resource) Registers the resource for later retrieval withResourceResolver.getResource(Class).<R> voidunregisterResource(Class<R> clzResource, String sResourceName) Unregisters the resource that was previously registered of the specified class and name.Methods inherited from interface com.oracle.coherence.common.base.Disposable
close, disposeMethods inherited from interface com.tangosol.util.ResourceResolver
getResource, getResource
-
Field Details
-
DEFAULT_NAME
The name to use for the registration of a singleton and thus default resource.- See Also:
-
-
Method Details
-
registerResource
Registers the resource for later retrieval withResourceResolver.getResource(Class).Notes:
- Multiple resources for the same class can be registered if each
resource is registered with a unique name via
registerResource(Class, String, Object) - Registration of resources will occur in a thread-safe manner.
- Resources that are
Disposablewill be disposed when theResourceRegistryis disposed.
- Parameters:
clzResource- the class of the resourceresource- the resource- Returns:
- the actual name used to register the resource
- Throws:
IllegalArgumentException- if a resource of the same specified type is already registered
- Multiple resources for the same class can be registered if each
resource is registered with a unique name via
-
registerResource
<R> String registerResource(Class<R> clzResource, String sResourceName, R resource) throws IllegalArgumentException Registers the resource with the specified name for later retrieval withResourceResolver.getResource(Class, String).Notes:
- Registration of resources will occur in a thread-safe manner.
- Resources that are
Disposablewill be disposed when theResourceRegistryis disposed.
- Parameters:
clzResource- the class of the resourcesResourceName- the proposed name of the resourceresource- the resource- Returns:
- the actual name used to register the resource
- Throws:
IllegalArgumentException- if a resource of the same specified type and name is already registered
-
registerResource
<R> String registerResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer) throws IllegalArgumentException Registers a resource according to the specifiedRegistrationBehavior. If successful the registered resource may later be retrieved using methodResourceResolver.getResource(Class).Notes:
- Multiple resources for the same class can be registered if each
resource is registered with a unique name via
registerResource(Class, String, Builder, RegistrationBehavior, ResourceLifecycleObserver) - Registration of resources will occur in a thread-safe manner.
- Resources that are
Disposablewill be disposed when theResourceRegistryis disposed.
- Type Parameters:
R- the type of the resource- Parameters:
clzResource- the class of the resourcebldrResource- theBuilderto realize the resource to register (if required the specified behavior requires a resource)behavior- theRegistrationBehaviorto useobserver- an optionalResourceRegistry.ResourceLifecycleObserverthat will be called when the resource is being released from theResourceRegistry(may be null)- Returns:
- the actual name used to register the resource
- Throws:
IllegalArgumentException- if a resource with the specified class is already registered with theResourceRegistryand the behavior wasRegistrationBehavior.FAIL
- Multiple resources for the same class can be registered if each
resource is registered with a unique name via
-
registerResource
<R> String registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer) throws IllegalArgumentException Registers a resource according to the specifiedRegistrationBehavior. If successful the registered resource may later be retrieved using methodResourceResolver.getResource(Class, String).Notes:
- Registration of resources will occur in a thread-safe manner.
- Resources that are
Disposablewill be disposed when theResourceRegistryis disposed.
- Type Parameters:
R- the type of the resource- Parameters:
clzResource- the class of the resourcesResourceName- the proposed name of the resourcebldrResource- theBuilderto realize the resource to register (if required the specified behavior requires a resource)behavior- theRegistrationBehaviorto useobserver- an optionalResourceRegistry.ResourceLifecycleObserverthat will be called when the resource is being released from theResourceRegistry(may be null)- Returns:
- the actual name used to register the resource
- Throws:
IllegalArgumentException- if a resource with the specified class is already registered with theResourceRegistryand the behavior wasRegistrationBehavior.FAIL
-
unregisterResource
Unregisters the resource that was previously registered of the specified class and name.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.- Type Parameters:
R- the type of the resource- Parameters:
clzResource- the class of the resourcesResourceName- the name of the resource
-