Class SharedResourceManager
- java.lang.Object
-
- org.apache.bookkeeper.common.util.SharedResourceManager
-
public class SharedResourceManager extends java.lang.Object
A holder for shared resource singletons.Components like clients and servers need certain resources, e.g. a scheduler, to run. If the user has not provided such resources, these components will use a default one, which is shared as a static resource. This class holds these default resources and manages their lifecycles.
A resource is identified by the reference of a
SharedResourceManager.Resource
object, which is typically a singleton, provided to the get() and release() methods. Each resource object (not its class) maps to an object cached in the holder.Resources are ref-counted and shut down after a delay when the refcount reaches zero.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SharedResourceManager.Resource<T>
Defines a resource, and the way to create and destroy instances of it.
-
Field Summary
Fields Modifier and Type Field Description (package private) static long
DESTROY_DELAY_SECONDS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedResourceManager
create()
static SharedResourceManager
create(java.util.function.Supplier<java.util.concurrent.ScheduledExecutorService> destroyerFactory)
<T> T
get(SharedResourceManager.Resource<T> resource)
<T> void
release(SharedResourceManager.Resource<T> resource, T instance)
static SharedResourceManager
shared()
-
-
-
Field Detail
-
DESTROY_DELAY_SECONDS
static final long DESTROY_DELAY_SECONDS
- See Also:
- Constant Field Values
-
-
Method Detail
-
shared
public static SharedResourceManager shared()
-
create
public static SharedResourceManager create()
-
create
public static SharedResourceManager create(java.util.function.Supplier<java.util.concurrent.ScheduledExecutorService> destroyerFactory)
-
get
public <T> T get(SharedResourceManager.Resource<T> resource)
-
release
public <T> void release(SharedResourceManager.Resource<T> resource, T instance)
-
-