public interface ResourceRegistry extends ResourceResolver, com.oracle.coherence.common.base.Disposable
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.
Modifier and Type | Interface and Description |
---|---|
static interface |
ResourceRegistry.ResourceLifecycleObserver<R>
The
ResourceRegistry.ResourceLifecycleObserver interface defines lifecycle handlers
for resources registered with a ResourceRegistry . |
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_NAME
The name to use for the registration of a singleton and thus default resource.
|
Modifier and Type | Method and Description |
---|---|
<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.
|
getResource, getResource
static final String DEFAULT_NAME
<R> String registerResource(Class<R> clzResource, R resource) throws IllegalArgumentException
ResourceResolver.getResource(Class)
.
Notes:
registerResource(Class, String, Object)
Disposable
will be disposed when the
ResourceRegistry
is disposed.
clzResource
- the class of the resourceresource
- the resourceIllegalArgumentException
- if a resource of the same specified type
is already registered<R> String registerResource(Class<R> clzResource, String sResourceName, R resource) throws IllegalArgumentException
ResourceResolver.getResource(Class, String)
.
Notes:
Disposable
will be disposed when the
ResourceRegistry
is disposed.
clzResource
- the class of the resourceresource
- the resourcesResourceName
- the proposed name of the resourceIllegalArgumentException
- if a resource of the same specified type
and name is already registered<R> String registerResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer) throws IllegalArgumentException
RegistrationBehavior
.
If successful the registered resource may later be retrieved using method
ResourceResolver.getResource(Class)
.
Notes:
registerResource(Class, String, Builder, RegistrationBehavior, ResourceLifecycleObserver)
Disposable
will be disposed when the
ResourceRegistry
is disposed.
R
- 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)IllegalArgumentException
- if a resource with the specified class
is already registered with
the ResourceRegistry
and
the behavior was RegistrationBehavior.FAIL
<R> String registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer) throws IllegalArgumentException
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.
R
- 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)IllegalArgumentException
- if a resource with the specified class
is already registered with
the ResourceRegistry
and
the behavior was RegistrationBehavior.FAIL
<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.
R
- the type of the resourceclzResource
- the class of the resourcesResourceName
- the name of the resource