- Type Parameters:
T- The concrete poolable type.
- Direct Known Subclasses:
BSlotPadded
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBSlot(BlockingQueue<BSlot<T>> live, AtomicLong poisonedSlots) Create a new BSlot instance, which will return to the given live queue when released from a claim, and update the given counter when poisoned. -
Method Summary
Modifier and TypeMethodDescriptionvoidTransition this slot from claimed to dead.voidTransition this slot from thread-locally claimed, to live.voidTransition this slot from dead to live.voidMark the object represented by this slot as expired.longGet the approximate number of milliseconds that have transpired since the object was allocated.longGet the approximateSystem.nanoTime()timestamp for when the object was allocated.Get the Poolable object represented by this SlotInfo instance.longgetStamp()Get the stamp value that has been set on this SlotInfo, or 0 if none has been set since the Poolable was allocated.booleanAttempt to transition this slot from live to claimed.booleanAttempt to transition this slot from live to thread-locally claimed.voidSignal to the pool that the currently claimed object in this slot has been released.voidsetStamp(long stamp) Set the stamp value on this SlotInfo.toString()
-
Field Details
-
obj
The object being pooled. -
poison
Any exception encountered when trying to allocate an object for this slot. -
leakCheck
A reference to the allocated object, used by thePreciseLeakDetector.
-
-
Constructor Details
-
BSlot
Create a new BSlot instance, which will return to the given live queue when released from a claim, and update the given counter when poisoned.- Parameters:
live- The queue of live slots.poisonedSlots- The counter of poisoned slots.
-
-
Method Details
-
expire
Description copied from interface:SlotMark the object represented by this slot as expired. Expired objects cannot be claimed again, and will be deallocated by the pool at the earliest convenience. Objects are normally expired automatically using theExpirationpolicy that the pool has been configured with. If an object through its use is found to be unusable, then it can be explicitly expired using this method. Objects can only be explicitly expired while they are claimed, and such expired objects will not be deallocated until they are released back to the pool.It is a user error to expire objects that are not currently claimed. It is likewise a user error to expire a Slot while inside the Allocators
allocatemethod.The expiration only takes effect after the object has been released, so calling this method from within the Expirations
hasExpiredmethod will not prevent the object from being claimed, but will prevent it from being claimed again after it's been released back to the pool. An Expiration policy that expires all objects with this method, is effectively allowing objects to only be claimed once.Pools are free to throw a PoolException if they detect any wrong uses, but it is not guaranteed and the exact behaviour is not specified. "Unspecified behaviour" means that deadlocks and infinite loops are fair responses as well. Therefore, heed the advice and don't misuse expire!
Pools must, however, guarantee that an object is never
deallocatedmore than once. This guarantee must hold even if expire is misused. -
release
Description copied from interface:SlotSignal to the pool that the currently claimed object in this slot has been released.It is a user error to release a slot that is not currently claimed. It is likewise a user error to release a Slot while inside the Allocators
allocatemethod, or the ExpirationshasExpiredmethod.On the other hand, it is not an error to release a Poolable from a thread other than the one that claimed it.
Pools are free to throw a PoolException if they detect any of these wrong uses, but it is not guaranteed and the exact behaviour is not specified. "Unspecified behaviour" means that deadlocks and infinite loops are fair responses as well. Therefore, heed the advice and don't misuse release!
Pools must, however, guarantee that an object is never
deallocatedmore than once. This guarantee must hold even if release is misused. -
claimTlr2live
public void claimTlr2live()Transition this slot from thread-locally claimed, to live. -
dead2live
public void dead2live()Transition this slot from dead to live. -
claim2dead
public void claim2dead()Transition this slot from claimed to dead. -
live2claim
public boolean live2claim()Attempt to transition this slot from live to claimed.- Returns:
trueif the state transition succeeds, otherwisefalse.
-
live2claimTlr
public boolean live2claimTlr()Attempt to transition this slot from live to thread-locally claimed.- Returns:
trueif the state transition succeeds, otherwisefalse.
-
getAgeMillis
public long getAgeMillis()Description copied from interface:SlotInfoGet the approximate number of milliseconds that have transpired since the object was allocated.- Specified by:
getAgeMillisin interfaceSlotInfo<T extends Poolable>- Returns:
- The age of the object in milliseconds.
-
getCreatedNanoTime
public long getCreatedNanoTime()Description copied from interface:SlotInfoGet the approximateSystem.nanoTime()timestamp for when the object was allocated.- Specified by:
getCreatedNanoTimein interfaceSlotInfo<T extends Poolable>- Returns:
- The object allocation
System.nanoTime()timestamp.
-
getPoolable
Description copied from interface:SlotInfoGet the Poolable object represented by this SlotInfo instance.WARNING: Do not
release()Poolables from within anExpiration— doing so is a user error, and the behaviour of the pool in such a situation is unspecified and implementation specific. This means that deadlocks and infinite loops are possible outcomes as well.WARNING: Also note that accessing the Poolable through this method, from your
Expirationimplementation, is a potentially concurrent access. This means that you need to take thread-safety issues into consideration - especially if you intend on manipulating the Poolable. In particular, you might be racing with other threads that are checking if this Poolable is expired or not, and they might even have claimed the Poolable and put it to use, by the time it is returned from this method.- Specified by:
getPoolablein interfaceSlotInfo<T extends Poolable>- Returns:
- The Poolable being examined for validity. Never
null.
-
getStamp
public long getStamp()Description copied from interface:SlotInfoGet the stamp value that has been set on this SlotInfo, or 0 if none has been set since the Poolable was allocated.Apart from the zero-value, the actual meaning of this value is completely up to the
Expirationthat sets it. -
setStamp
public void setStamp(long stamp) Description copied from interface:SlotInfoSet the stamp value on this SlotInfo.This method is only thread-safe to call from within the scope of the
Expiration.hasExpired(SlotInfo)method.The stamp value is 0 by default, if it has not been set after the Poolable has been allocated. Its meaning is otherwise up to the particular Expiration that might use it.
-
toString
-