Package com.tangosol.util
Class SimpleResourceRegistry
- java.lang.Object
-
- com.tangosol.util.SimpleResourceRegistry
-
- All Implemented Interfaces:
Disposable
,ResourceRegistry
,ResourceResolver
,AutoCloseable
- Direct Known Subclasses:
SimpleResourceResolver
public class SimpleResourceRegistry extends Object implements ResourceRegistry
ASimpleResourceRegistry
is a basic implementation of aResourceRegistry
.- Since:
- Coherence 12.1.2
- Author:
- bo 2011.06.22, pp 2012.02.29
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
SimpleResourceRegistry.RegistryKey
Key class for a registered resource.protected class
SimpleResourceRegistry.RegistryValue
A holder for resource objects and their (optional) respectiveResourceLifecycleObservers
.-
Nested classes/interfaces inherited from interface com.tangosol.util.ResourceRegistry
ResourceRegistry.ResourceLifecycleObserver<R>
-
-
Field Summary
-
Fields inherited from interface com.tangosol.util.ResourceRegistry
DEFAULT_NAME
-
-
Constructor Summary
Constructors Constructor Description SimpleResourceRegistry()
Construct aSimpleResourceRegistry
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theResourceRegistry
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 specifiedRegistrationBehavior
.<R> String
registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
Registers a resource according to the specifiedRegistrationBehavior
.<R> String
registerResource(Class<R> clzResource, String sResourceName, R resource)
Registers the resource with the specified name for later retrieval withResourceResolver.getResource(Class, String)
.<R> String
registerResource(Class<R> clzResource, R resource)
Registers the resource for later retrieval withResourceResolver.getResource(Class)
.void
registerResources(ResourceRegistry registry)
Register all the resources contained in this registry with the target registry.void
registerResources(ResourceRegistry registry, RegistrationBehavior behavior)
Register all the resources contained in this registry with the target registry.<R> void
unregisterResource(Class<R> clzResource, String sResourceName)
Unregisters the resource that was previously registered of the specified class and name.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.oracle.coherence.common.base.Disposable
close
-
-
-
-
Constructor Detail
-
SimpleResourceRegistry
public SimpleResourceRegistry()
Construct aSimpleResourceRegistry
.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Determine if theResourceRegistry
is empty (contains no resource registrations).- Returns:
- true if the registry contains no resource registrations
-
registerResources
public void registerResources(ResourceRegistry registry)
Register all the resources contained in this registry with the target registry.- Parameters:
registry
- the targetResourceRegistry
to register resources with
-
registerResources
public void registerResources(ResourceRegistry registry, RegistrationBehavior behavior)
Register all the resources contained in this registry with the target registry.- Parameters:
registry
- the targetResourceRegistry
to register resources withbehavior
- theRegistrationBehavior
to use
-
dispose
public void dispose()
Invoked when all resources owned by the implementer can safely be released.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.
- Specified by:
dispose
in interfaceDisposable
-
getResource
public <R> R getResource(Class<R> clzResource)
Attempts to retrieve the resource that was registered with the specified class.- Specified by:
getResource
in interfaceResourceResolver
- Type Parameters:
R
- the type of the resource- Parameters:
clzResource
- the class of the resource- Returns:
- the registered resource or
null
if the resource is unknown to theResourceRegistry
-
getResource
public <R> R getResource(Class<R> clzResource, String sResourceName)
Attempts to retrieve the resource that was registered with the specified class and name.- Specified by:
getResource
in interfaceResourceResolver
- Type Parameters:
R
- the type of the resource- Parameters:
clzResource
- the class of the resourcesResourceName
- the name of the resource- Returns:
- the registered resource or
null
if the resource is unknown to theResourceRegistry
-
registerResource
public <R> String registerResource(Class<R> clzResource, R resource)
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
ResourceRegistry.registerResource(Class, String, Object)
- Registration of resources will occur in a thread-safe manner.
- Resources that are
Disposable
will be disposed when theResourceRegistry
is disposed.
- Specified by:
registerResource
in interfaceResourceRegistry
- Parameters:
clzResource
- the class of the resourceresource
- the resource- Returns:
- the actual name used to register the resource
- Multiple resources for the same class can be registered if each
resource is registered with a unique name via
-
registerResource
public <R> String registerResource(Class<R> clzResource, String sResourceName, R resource)
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
Disposable
will be disposed when theResourceRegistry
is disposed.
- Specified by:
registerResource
in interfaceResourceRegistry
- Parameters:
clzResource
- the class of the resourcesResourceName
- the proposed name of the resourceresource
- the resource- Returns:
- the actual name used to register the resource
-
registerResource
public <R> String registerResource(Class<R> clzResource, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
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
ResourceRegistry.registerResource(Class, String, Builder, RegistrationBehavior, ResourceLifecycleObserver)
- Registration of resources will occur in a thread-safe manner.
- Resources that are
Disposable
will be disposed when theResourceRegistry
is disposed.
- Specified by:
registerResource
in interfaceResourceRegistry
- Type Parameters:
R
- the type of the resource- Parameters:
clzResource
- the class of the resourcebldrResource
- theBuilder
to realize the resource to register (if required the specified behavior requires a resource)behavior
- theRegistrationBehavior
to useobserver
- an optionalResourceRegistry.ResourceLifecycleObserver
that will be called when the resource is being released from theResourceRegistry
(may be null)- Returns:
- the actual name used to register the resource
- Multiple resources for the same class can be registered if each
resource is registered with a unique name via
-
registerResource
public <R> String registerResource(Class<R> clzResource, String sResourceName, Builder<? extends R> bldrResource, RegistrationBehavior behavior, ResourceRegistry.ResourceLifecycleObserver<R> observer)
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
Disposable
will be disposed when theResourceRegistry
is disposed.
- Specified by:
registerResource
in interfaceResourceRegistry
- Type Parameters:
R
- the type of the resource- Parameters:
clzResource
- the class of the resourcesResourceName
- the proposed name of the resourcebldrResource
- theBuilder
to realize the resource to register (if required the specified behavior requires a resource)behavior
- theRegistrationBehavior
to useobserver
- an optionalResourceRegistry.ResourceLifecycleObserver
that will be called when the resource is being released from theResourceRegistry
(may be null)- Returns:
- the actual name used to register the resource
-
unregisterResource
public <R> void unregisterResource(Class<R> clzResource, String sResourceName)
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.- Specified by:
unregisterResource
in interfaceResourceRegistry
- Type Parameters:
R
- the type of the resource- Parameters:
clzResource
- the class of the resourcesResourceName
- the name of the resource
-
-