Top Description Fields Constructors Methods
org.apache.commons.pool2.impl

public Class DefaultPooledObject<T>

extends Object
implements PooledObject<T>
Class Inheritance
All Implemented Interfaces
org.apache.commons.pool2.PooledObject, java.lang.Comparable
Known Direct Subclasses
org.apache.commons.pool2.impl.PooledSoftReference
Type Parameters
<T>
the type of object in the pool
Imports
java.io.PrintWriter, java.time.Clock, .Duration, .Instant, java.util.Deque, org.apache.commons.pool2.PooledObject, .PooledObjectState, .TrackedUse

This wrapper is used to track the additional information, such as state, for the pooled objects.

This class is intended to be thread-safe.

Since
2.0

Field Summary

Modifier and TypeField and Description
private volatile CallStack
private volatile long
private final Instant
private volatile Instant
private volatile Instant
private volatile Instant
private volatile boolean
private final T
private PooledObjectState
private final Clock
private volatile CallStack

Constructor Summary

AccessConstructor and Description
public
DefaultPooledObject(final T
The object to wrap
object
)

Creates a new instance that wraps the provided object so that the pool can track the state of the pooled object.

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean

Returns:

true if the original state was IDLE
allocate
()

Implements org.apache.commons.pool2.PooledObject.allocate.

Allocates the object.
public int
compareTo(final PooledObject<T>
the object to be compared.
other
)

Implements org.apache.commons.pool2.PooledObject.compareTo.

Orders instances based on idle time - i.e. the length of time since the instance was returned to the pool.
public synchronized boolean

Returns:

true if the state was ALLOCATED or RETURNING.
deallocate
()

Implements org.apache.commons.pool2.PooledObject.deallocate.

Deallocates the object and sets it IDLE if it is currently ALLOCATED or RETURNING.
public synchronized boolean
endEvictionTest(final Deque<PooledObject<T>>
The queue of idle objects to which the object should be returned.
idleQueue
)

Implements org.apache.commons.pool2.PooledObject.endEvictionTest.

Notifies the object that the eviction test has ended.
public long
getActiveTimeMillis()

Implements org.apache.commons.pool2.PooledObject.getActiveTimeMillis.

Gets the amount of time in milliseconds this object last spent in the active state (it may still be active in which case subsequent calls will return an increased value).
public long

Returns:

The number of times this object has been borrowed.
getBorrowedCount
()

Overrides default org.apache.commons.pool2.PooledObject.getBorrowedCount.

Gets the number of times this object has been borrowed.
public Instant
getCreateInstant()

Overrides default org.apache.commons.pool2.PooledObject.getCreateInstant.

Gets the time (using the same basis as Instant#now()) that this object was created.
public long
getCreateTime()

Implements org.apache.commons.pool2.PooledObject.getCreateTime.

Gets the time (using the same basis as java.time.Clock#instant()) that this object was created.
public Duration
getIdleDuration()

Overrides default org.apache.commons.pool2.PooledObject.getIdleDuration.

Gets the amount of time that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).
public Duration
getIdleTime()

Overrides default org.apache.commons.pool2.PooledObject.getIdleTime.

Gets the amount of time that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).
public long
getIdleTimeMillis()

Implements org.apache.commons.pool2.PooledObject.getIdleTimeMillis.

Gets the amount of time in milliseconds that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).
public Instant
getLastBorrowInstant()

Overrides default org.apache.commons.pool2.PooledObject.getLastBorrowInstant.

Gets the time the wrapped object was last borrowed.
public long
getLastBorrowTime()

Implements org.apache.commons.pool2.PooledObject.getLastBorrowTime.

Gets the time the wrapped object was last borrowed.
public Instant
getLastReturnInstant()

Overrides default org.apache.commons.pool2.PooledObject.getLastReturnInstant.

Gets the time the wrapped object was last borrowed.
public long
getLastReturnTime()

Implements org.apache.commons.pool2.PooledObject.getLastReturnTime.

Gets the time the wrapped object was last returned.
public Instant

Returns:

the last Instant this object was used.
getLastUsedInstant
()

Overrides default org.apache.commons.pool2.PooledObject.getLastUsedInstant.

Gets an estimate of the last time this object was used.
public long

Returns:

the last time this object was used
getLastUsedTime
()

Implements org.apache.commons.pool2.PooledObject.getLastUsedTime.

Gets an estimate of the last time this object was used.
public T
getObject()

Implements org.apache.commons.pool2.PooledObject.getObject.

Gets the underlying object that is wrapped by this instance of PooledObject.
public synchronized PooledObjectState

Returns:

state
getState
()

Implements org.apache.commons.pool2.PooledObject.getState.

Gets the state of this object.
public synchronized void
public synchronized void
public synchronized void
private Instant

Returns:

the current instant of the clock.
now
()

Gets the current instant of the clock.

public void
printStackTrace(final PrintWriter
The destination for the debug output.
writer
)

Implements org.apache.commons.pool2.PooledObject.printStackTrace.

Prints the stack trace of the code that borrowed this pooled object and the stack trace of the last code to use this object (if available) to the supplied writer.
public void
setLogAbandoned(final boolean
The new configuration setting for abandoned object tracking.
logAbandoned
)

Implements org.apache.commons.pool2.PooledObject.setLogAbandoned.

Sets whether to use abandoned object tracking.
public void
setRequireFullStackTrace(final boolean
the new configuration setting for abandoned object logging
requireFullStackTrace
)

Overrides default org.apache.commons.pool2.PooledObject.setRequireFullStackTrace.

Configures the stack trace generation strategy based on whether or not fully detailed stack traces are required.
public synchronized boolean
startEvictionTest()

Implements org.apache.commons.pool2.PooledObject.startEvictionTest.

Attempts to place the pooled object in the PooledObjectState#EVICTION state.
public String
toString()

Overrides java.lang.Object.toString.

Implements org.apache.commons.pool2.PooledObject.toString.

Gets a String form of the wrapper for debug purposes.
public void
use()

Implements org.apache.commons.pool2.PooledObject.use.

Records the current stack trace as the last time the object was used.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

borrowedByback to summary
private volatile CallStack borrowedBy
borrowedCountback to summary
private volatile long borrowedCount
createInstantback to summary
private final Instant createInstant
lastBorrowInstantback to summary
private volatile Instant lastBorrowInstant
lastReturnInstantback to summary
private volatile Instant lastReturnInstant
lastUseInstantback to summary
private volatile Instant lastUseInstant
logAbandonedback to summary
private volatile boolean logAbandoned
objectback to summary
private final T object
stateback to summary
private PooledObjectState state
systemClockback to summary
private final Clock systemClock
usedByback to summary
private volatile CallStack usedBy

Constructor Detail

DefaultPooledObjectback to summary
public DefaultPooledObject(final T object)

Creates a new instance that wraps the provided object so that the pool can track the state of the pooled object.

Parameters
object:T

The object to wrap

Method Detail

allocateback to summary
public synchronized boolean allocate()

Implements org.apache.commons.pool2.PooledObject.allocate.

Allocates the object.

Returns:boolean

true if the original state was IDLE

Annotations
@Override
compareToback to summary
public int compareTo(final PooledObject<T> other)

Implements org.apache.commons.pool2.PooledObject.compareTo.

Doc from org.apache.commons.pool2.PooledObject.compareTo.

Orders instances based on idle time - i.e. the length of time since the instance was returned to the pool. Used by the GKOP idle object evictor.

Note

This class has a natural ordering that is inconsistent with equals if distinct objects have the same identity hash code.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:PooledObject<T>

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
deallocateback to summary
public synchronized boolean deallocate()

Implements org.apache.commons.pool2.PooledObject.deallocate.

Deallocates the object and sets it IDLE if it is currently ALLOCATED or RETURNING.

Returns:boolean

true if the state was ALLOCATED or RETURNING.

Annotations
@Override
endEvictionTestback to summary
public synchronized boolean endEvictionTest(final Deque<PooledObject<T>> idleQueue)

Implements org.apache.commons.pool2.PooledObject.endEvictionTest.

Doc from org.apache.commons.pool2.PooledObject.endEvictionTest.

Notifies the object that the eviction test has ended.

Parameters
idleQueue:Deque<PooledObject<T>>

The queue of idle objects to which the object should be returned.

Returns:boolean

Currently not used.

Annotations
@Override
getActiveTimeMillisback to summary
public long getActiveTimeMillis()

Implements org.apache.commons.pool2.PooledObject.getActiveTimeMillis.

Doc from org.apache.commons.pool2.PooledObject.getActiveTimeMillis.

Gets the amount of time in milliseconds this object last spent in the active state (it may still be active in which case subsequent calls will return an increased value).

Returns:long

The time in milliseconds last spent in the active state.

Annotations
@Override
getBorrowedCountback to summary
public long getBorrowedCount()

Overrides default org.apache.commons.pool2.PooledObject.getBorrowedCount.

Gets the number of times this object has been borrowed.

Returns:long

The number of times this object has been borrowed.

Annotations
@Override
Since
2.1
getCreateInstantback to summary
public Instant getCreateInstant()

Overrides default org.apache.commons.pool2.PooledObject.getCreateInstant.

Doc from org.apache.commons.pool2.PooledObject.getCreateInstant.

Gets the time (using the same basis as Instant#now()) that this object was created.

Returns:Instant

The creation time for the wrapped object.

Annotations
@Override
getCreateTimeback to summary
public long getCreateTime()

Implements org.apache.commons.pool2.PooledObject.getCreateTime.

Doc from org.apache.commons.pool2.PooledObject.getCreateTime.

Gets the time (using the same basis as java.time.Clock#instant()) that this object was created.

Returns:long

The creation time for the wrapped object.

Annotations
@Override
getIdleDurationback to summary
public Duration getIdleDuration()

Overrides default org.apache.commons.pool2.PooledObject.getIdleDuration.

Doc from org.apache.commons.pool2.PooledObject.getIdleDuration.

Gets the amount of time that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).

Returns:Duration

The amount of time in last spent in the idle state.

Annotations
@Override
getIdleTimeback to summary
public Duration getIdleTime()

Overrides default org.apache.commons.pool2.PooledObject.getIdleTime.

Doc from org.apache.commons.pool2.PooledObject.getIdleTime.

Gets the amount of time that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).

Returns:Duration

The amount of time in last spent in the idle state.

Annotations
@Override
getIdleTimeMillisback to summary
public long getIdleTimeMillis()

Implements org.apache.commons.pool2.PooledObject.getIdleTimeMillis.

Doc from org.apache.commons.pool2.PooledObject.getIdleTimeMillis.

Gets the amount of time in milliseconds that this object last spend in the idle state (it may still be idle in which case subsequent calls will return an increased value).

Returns:long

The time in milliseconds last spent in the idle state.

Annotations
@Override
getLastBorrowInstantback to summary
public Instant getLastBorrowInstant()

Overrides default org.apache.commons.pool2.PooledObject.getLastBorrowInstant.

Doc from org.apache.commons.pool2.PooledObject.getLastBorrowInstant.

Gets the time the wrapped object was last borrowed.

Returns:Instant

The time the object was last borrowed.

Annotations
@Override
getLastBorrowTimeback to summary
public long getLastBorrowTime()

Implements org.apache.commons.pool2.PooledObject.getLastBorrowTime.

Doc from org.apache.commons.pool2.PooledObject.getLastBorrowTime.

Gets the time the wrapped object was last borrowed.

Returns:long

The time the object was last borrowed.

Annotations
@Override
getLastReturnInstantback to summary
public Instant getLastReturnInstant()

Overrides default org.apache.commons.pool2.PooledObject.getLastReturnInstant.

Doc from org.apache.commons.pool2.PooledObject.getLastReturnInstant.

Gets the time the wrapped object was last borrowed.

Returns:Instant

The time the object was last borrowed.

Annotations
@Override
getLastReturnTimeback to summary
public long getLastReturnTime()

Implements org.apache.commons.pool2.PooledObject.getLastReturnTime.

Doc from org.apache.commons.pool2.PooledObject.getLastReturnTime.

Gets the time the wrapped object was last returned.

Returns:long

The time the object was last returned.

Annotations
@Override
getLastUsedInstantback to summary
public Instant getLastUsedInstant()

Overrides default org.apache.commons.pool2.PooledObject.getLastUsedInstant.

Gets an estimate of the last time this object was used. If the class of the pooled object implements TrackedUse, what is returned is the maximum of TrackedUse#getLastUsedInstant() and getLastBorrowTime(); otherwise this method gives the same value as getLastBorrowTime().

Returns:Instant

the last Instant this object was used.

Annotations
@Override
getLastUsedTimeback to summary
public long getLastUsedTime()

Implements org.apache.commons.pool2.PooledObject.getLastUsedTime.

Gets an estimate of the last time this object was used. If the class of the pooled object implements TrackedUse, what is returned is the maximum of TrackedUse#getLastUsedInstant() and getLastBorrowTime(); otherwise this method gives the same value as getLastBorrowTime().

Returns:long

the last time this object was used

Annotations
@Override
getObjectback to summary
public T getObject()

Implements org.apache.commons.pool2.PooledObject.getObject.

Doc from org.apache.commons.pool2.PooledObject.getObject.

Gets the underlying object that is wrapped by this instance of PooledObject.

Returns:T

The wrapped object.

Annotations
@Override
getStateback to summary
public synchronized PooledObjectState getState()

Implements org.apache.commons.pool2.PooledObject.getState.

Gets the state of this object.

Returns:PooledObjectState

state

Annotations
@Override
invalidateback to summary
public synchronized void invalidate()

Implements org.apache.commons.pool2.PooledObject.invalidate.

Sets the state to INVALID.

Annotations
@Override
markAbandonedback to summary
public synchronized void markAbandoned()

Implements org.apache.commons.pool2.PooledObject.markAbandoned.

Marks the pooled object as ABANDONED.

Annotations
@Override
markReturningback to summary
public synchronized void markReturning()

Implements org.apache.commons.pool2.PooledObject.markReturning.

Marks the pooled object as RETURNING.

Annotations
@Override
nowback to summary
private Instant now()

Gets the current instant of the clock.

Returns:Instant

the current instant of the clock.

printStackTraceback to summary
public void printStackTrace(final PrintWriter writer)

Implements org.apache.commons.pool2.PooledObject.printStackTrace.

Doc from org.apache.commons.pool2.PooledObject.printStackTrace.

Prints the stack trace of the code that borrowed this pooled object and the stack trace of the last code to use this object (if available) to the supplied writer.

Parameters
writer:PrintWriter

The destination for the debug output.

Annotations
@Override
setLogAbandonedback to summary
public void setLogAbandoned(final boolean logAbandoned)

Implements org.apache.commons.pool2.PooledObject.setLogAbandoned.

Doc from org.apache.commons.pool2.PooledObject.setLogAbandoned.

Sets whether to use abandoned object tracking. If this is true the implementation will need to record the stack trace of the last caller to borrow this object.

Parameters
logAbandoned:boolean

The new configuration setting for abandoned object tracking.

Annotations
@Override
setRequireFullStackTraceback to summary
public void setRequireFullStackTrace(final boolean requireFullStackTrace)

Overrides default org.apache.commons.pool2.PooledObject.setRequireFullStackTrace.

Configures the stack trace generation strategy based on whether or not fully detailed stack traces are required. When set to false, abandoned logs may only include caller class information rather than method names, line numbers, and other normal metadata available in a full stack trace.

Parameters
requireFullStackTrace:boolean

the new configuration setting for abandoned object logging

Annotations
@Override
Since
2.5
startEvictionTestback to summary
public synchronized boolean startEvictionTest()

Implements org.apache.commons.pool2.PooledObject.startEvictionTest.

Doc from org.apache.commons.pool2.PooledObject.startEvictionTest.

Attempts to place the pooled object in the PooledObjectState#EVICTION state.

Returns:boolean

true if the object was placed in the PooledObjectState#EVICTION state otherwise false.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements org.apache.commons.pool2.PooledObject.toString.

Doc from org.apache.commons.pool2.PooledObject.toString.

Gets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
useback to summary
public void use()

Implements org.apache.commons.pool2.PooledObject.use.

Doc from org.apache.commons.pool2.PooledObject.use.

Records the current stack trace as the last time the object was used.

Annotations
@Override