public class SharedResourceManager
extends java.lang.Object
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
SharedResourceManager.Resource<T>
Defines a resource, and the way to create and destroy instances of it.
|
| Modifier and Type | Field and Description |
|---|---|
(package private) static long |
DESTROY_DELAY_SECONDS |
| Modifier and Type | Method and 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() |
static final long DESTROY_DELAY_SECONDS
public static SharedResourceManager shared()
public static SharedResourceManager create()
public static SharedResourceManager create(java.util.function.Supplier<java.util.concurrent.ScheduledExecutorService> destroyerFactory)
public <T> T get(SharedResourceManager.Resource<T> resource)
public <T> void release(SharedResourceManager.Resource<T> resource, T instance)
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.