Class SharedResourceHolder
java.lang.Object
io.grpc.internal.SharedResourceHolder
A holder for shared resource singletons.
Components like client channels and servers need certain resources, e.g. a thread pool, 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 life-cycles.
A resource is identified by the reference of a SharedResourceHolder.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 ref-count reaches zero.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classstatic interfaceDefines a resource, and the way to create and destroy instances of it.(package private) static interface -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final longprivate ScheduledExecutorServiceprivate final SharedResourceHolder.ScheduledExecutorFactoryprivate static final SharedResourceHolderprivate final IdentityHashMap<SharedResourceHolder.Resource<?>, SharedResourceHolder.Instance> -
Constructor Summary
ConstructorsConstructorDescriptionSharedResourceHolder(SharedResourceHolder.ScheduledExecutorFactory destroyerFactory) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tget(SharedResourceHolder.Resource<T> resource) Try to get an existing instance of the given resource.(package private) <T> TgetInternal(SharedResourceHolder.Resource<T> resource) Visible to unit tests.static <T> Trelease(SharedResourceHolder.Resource<T> resource, T instance) Releases an instance of the given resource.(package private) <T> TreleaseInternal(SharedResourceHolder.Resource<T> resource, T instance) Visible to unit tests.
-
Field Details
-
DESTROY_DELAY_SECONDS
static final long DESTROY_DELAY_SECONDS- See Also:
-
holder
-
instances
private final IdentityHashMap<SharedResourceHolder.Resource<?>, SharedResourceHolder.Instance> instances -
destroyerFactory
-
destroyer
-
-
Constructor Details
-
Method Details