T
- the type of resource stored in this poolpublic interface ResourcePool<T>
used()
and max()
methods will return absolute values indicating the amounts used or
available for all resources that come from the shared pool, but the
managed()
method will only indicate the amount of the resource
used for managed resources and the target()
method will return
the amount of the total shared resource that the allocation methods
should attempt to stay under.
long newsize = ...; // size of new resource allocation if (pool.used() + newsize >= pool.target()) { cleanup(pool); // possibly multiple passes of increasing aggressiveness } if (pool.used() + newsize >= pool.max()) { throw OOM(); } allocate(newsize);The amounts and sizes returned from the methods should all be in the same units, usually bytes.
ManagedResource
Modifier and Type | Method and Description |
---|---|
void |
freeDisposalRequestedAndCheckResources(boolean forgiveStaleLocks)
Check that all resources are in the correct state for an idle condition
and free any resources which were disposed from a non-resource thread.
|
boolean |
isManagerThread()
True if Thread.currentThread() is a thread that created this ResourcePool
|
long |
managed()
The amount of this resource currently being used to hold managed
resources.
|
long |
max()
The total space available in this pool for allocating any kind of
resource, even unmanaged resources, and including those resources
already allocated.
|
long |
origTarget()
The initial target of the maximum amount of space in this resource pool
that should be used so as to be friendly to other parts of the system.
|
boolean |
prepareForAllocation(long size)
Prepare for an allocation of a resource from this pool of the
indicated size by freeing up uninteresting resources until the
allocation fits within the target() or max() sizes.
|
void |
recordAllocated(long size)
Record the indicated amount of the resource as being allocated for
a
ManagedResource . |
void |
recordFree(long size)
Record the indicated amount of the resource as no longer being
held in a
ManagedResource . |
void |
resourceFreed(ManagedResource<T> resource)
Record the
ManagedResource object as no longer being managed
by this pool. |
void |
resourceManaged(ManagedResource<T> resource)
Record the
ManagedResource object as being currently managed
by this pool. |
void |
setTarget(long newTarget)
Sets a new current target of the maximum amount of space in this
resource pool that should be used so as to be friendly to other parts
of the system.
|
long |
size(T resource)
The estimated size of the indicated resource.
|
long |
target()
The current target of the maximum amount of space in this resource pool
that should be used so as to be friendly to other parts of the system.
|
long |
used()
The amount of a resource currently being used to hold any kind of
resource, whether managed or not.
|
void freeDisposalRequestedAndCheckResources(boolean forgiveStaleLocks)
forgiveStaleLocks
parameter is used to indicate that
an exceptional condition occurred which caused the caller to abort a
cycle of resource usage, potentially with outstanding resource locks.
This method will unlock all non-permanent resources that have outstanding
locks if forgiveStaleLocks
is true
, or it will print out
a warning and a resource summary if that parameter is false
.forgiveStaleLocks
- true
if the caller wishes to forgive
and unlock all outstanding locks on non-permanent resourcesboolean isManagerThread()
long used()
long managed()
used()
method if the pool is shared amongst other resources.long max()
long target()
max()
method, larger than the amount returned by the
origTarget()
method, and may change over time.setTarget(long)
long origTarget()
max()
method.void setTarget(long newTarget)
newTarget
number must be less than or equal to
the amount returned by the max()
method, larger than the amount
returned by the origTarget()
method.newTarget
- the new current target to be setlong size(T resource)
resource
- the resource to be measuredvoid recordAllocated(long size)
ManagedResource
.size
- the amount of the resource to be indicated as managed.void recordFree(long size)
ManagedResource
.size
- the amount of the resource to remove from the managed amount.void resourceManaged(ManagedResource<T> resource)
ManagedResource
object as being currently managed
by this pool.resource
- the resource that is now being managedvoid resourceFreed(ManagedResource<T> resource)
ManagedResource
object as no longer being managed
by this pool.resource
- the resource that is freed, no longer being managedboolean prepareForAllocation(long size)
size
- the size of the resource that is about to be allocatedCopyright © 2020. All rights reserved.