T
- the type of objects stored in this resource poolpublic abstract class BaseResourcePool<T> extends java.lang.Object implements ResourcePool<T>
ResourcePool
interface, providing
bookkeeping for the managed()
method and support for sharing
resources amongst multiple pools.Modifier and Type | Class and Description |
---|---|
(package private) static interface |
BaseResourcePool.Predicate |
(package private) static class |
BaseResourcePool.WeakLinkedList<T> |
Modifier and Type | Field and Description |
---|---|
(package private) long |
curTarget |
private static int |
FOREVER |
(package private) long |
managedSize |
private java.lang.Thread |
managerThread |
(package private) long |
maxSize |
(package private) long |
origTarget |
private static int |
RECENT |
private static int |
RECENTLY_USEFUL |
private BaseResourcePool.WeakLinkedList<T> |
resourceHead |
(package private) ResourcePool<T> |
sharedParent |
private static java.lang.String[] |
stageReasons |
private static BaseResourcePool.Predicate[] |
stageTesters |
Modifier | Constructor and Description |
---|---|
protected |
BaseResourcePool(long target,
long max) |
protected |
BaseResourcePool(ResourcePool<T> parent) |
protected |
BaseResourcePool(ResourcePool<T> parent,
long target,
long max) |
Modifier and Type | Method and Description |
---|---|
private void |
cleanup(BaseResourcePool.Predicate predicate) |
boolean |
cleanup(long needed)
Clean up the resources in the indicated pool using a standard
algorithm until at least the specified amount of resource units
have been reclaimed.
|
(package private) static java.lang.String |
commas(long v) |
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.
|
private static void |
printpoolpercent(int stat,
int total,
java.lang.String desc) |
void |
printSummary(boolean printlocksources) |
private void |
pruneLastChance(boolean desperate) |
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> freed)
Record the
ManagedResource object as no longer being managed
by this pool. |
void |
resourceManaged(ManagedResource<T> mr)
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.
|
(package private) static void |
showLink(java.lang.String label,
BaseResourcePool.WeakLinkedList<?> cur,
boolean showAge) |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
size
private static final int FOREVER
private static final int RECENTLY_USEFUL
private static final int RECENT
private static final BaseResourcePool.Predicate[] stageTesters
private static final java.lang.String[] stageReasons
long managedSize
final long origTarget
long curTarget
final long maxSize
final ResourcePool<T> sharedParent
private final java.lang.Thread managerThread
private BaseResourcePool.WeakLinkedList<T> resourceHead
protected BaseResourcePool(long target, long max)
protected BaseResourcePool(ResourcePool<T> parent)
protected BaseResourcePool(ResourcePool<T> parent, long target, long max)
public boolean cleanup(long needed)
needed
- private void pruneLastChance(boolean desperate)
private void cleanup(BaseResourcePool.Predicate predicate)
static void showLink(java.lang.String label, BaseResourcePool.WeakLinkedList<?> cur, boolean showAge)
public 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
.freeDisposalRequestedAndCheckResources
in interface ResourcePool<T>
forgiveStaleLocks
- true
if the caller wishes to forgive
and unlock all outstanding locks on non-permanent resourcesstatic java.lang.String commas(long v)
public void printSummary(boolean printlocksources)
private static void printpoolpercent(int stat, int total, java.lang.String desc)
public boolean isManagerThread()
ResourcePool
isManagerThread
in interface ResourcePool<T>
public final long managed()
ResourcePool
ResourcePool.used()
method if the pool is shared amongst other resources.managed
in interface ResourcePool<T>
public long used()
ResourcePool
used
in interface ResourcePool<T>
public final long max()
ResourcePool
max
in interface ResourcePool<T>
public final long origTarget()
ResourcePool
ResourcePool.max()
method.origTarget
in interface ResourcePool<T>
public final long target()
ResourcePool
ResourcePool.max()
method, larger than the amount returned by the
ResourcePool.origTarget()
method, and may change over time.target
in interface ResourcePool<T>
ResourcePool.setTarget(long)
public final void setTarget(long newTarget)
ResourcePool
newTarget
number must be less than or equal to
the amount returned by the ResourcePool.max()
method, larger than the amount
returned by the ResourcePool.origTarget()
method.setTarget
in interface ResourcePool<T>
newTarget
- the new current target to be setpublic boolean prepareForAllocation(long size)
ResourcePool
prepareForAllocation
in interface ResourcePool<T>
size
- the size of the resource that is about to be allocatedpublic final void recordAllocated(long size)
ResourcePool
ManagedResource
.recordAllocated
in interface ResourcePool<T>
size
- the amount of the resource to be indicated as managed.public final void resourceManaged(ManagedResource<T> mr)
ResourcePool
ManagedResource
object as being currently managed
by this pool.resourceManaged
in interface ResourcePool<T>
mr
- the resource that is now being managedpublic final void resourceFreed(ManagedResource<T> freed)
ResourcePool
ManagedResource
object as no longer being managed
by this pool.resourceFreed
in interface ResourcePool<T>
freed
- the resource that is freed, no longer being managedpublic final void recordFree(long size)
ResourcePool
ManagedResource
.recordFree
in interface ResourcePool<T>
size
- the amount of the resource to remove from the managed amount.