final class CacheEntry
extends java.lang.Object
ConcurrentCache
. When a thread invokes any of the methods in
this class, except lock()
, it must first have called
lock()
to ensure exclusive access to the entry.
When no thread holds the lock on the entry, it must be in one of the following states:
isValid()
returns
false
, whereas isKept()
returns true
in order to prevent removal of the entry until it has been initialized.
When the entry is in this state, calls to
lockWhenIdentityIsSet()
will block until
settingIdentityComplete()
has been called.Cacheable
and the keep count is zero. isValid()
returns true
and isKept()
returns
false
in this state. getCacheable()
returns a
non-null value.isKept()
returns true
.isValid()
and isKept()
return
false
, and getCacheable()
returns
null
. When an entry has entered the removed state, it cannot be
transitioned back to any of the other states.To prevent deadlocks, each thread should normally lock only one entry at a time. In some cases it is legitimate to hold the lock on two entries, for instance if an entry must be evicted to make room for a new entry. If this is the case, exactly one of the two entries must be in the uninitialized state, and the uninitialized entry must be locked before the lock on the other entry can be requested.
Modifier and Type | Field | Description |
---|---|---|
private Cacheable |
cacheable |
The cached object.
|
private ReplacementPolicy.Callback |
callback |
Callback object used to notify the replacement algorithm about events on
the cached objects (like accesses and requests for removal).
|
private java.util.concurrent.locks.Condition |
forRemove |
Condition variable used to notify a thread that it is allowed to remove
the entry from the cache.
|
private int |
keepCount |
How many threads are currently keeping this entry.
|
private java.util.concurrent.locks.ReentrantLock |
mutex |
Mutex which guards the internal state of the entry.
|
private java.util.concurrent.locks.Condition |
settingIdentity |
Condition variable used to notify a thread that the setting of this
entry's identity is complete.
|
Constructor | Description |
---|---|
CacheEntry() |
Modifier and Type | Method | Description |
---|---|---|
(package private) void |
free() |
Clear this entry and notify the replacement algorithm that the
Cacheable can be reused. |
(package private) Cacheable |
getCacheable() |
Return the cached object held by this entry.
|
(package private) boolean |
isKept() |
Check whether or not this entry is kept.
|
(package private) boolean |
isValid() |
Check whether this entry holds a valid object.
|
(package private) void |
keep(boolean accessed) |
Increase the keep count for this entry.
|
(package private) void |
lock() |
Block until the current thread is granted exclusive access to the entry.
|
(package private) void |
setCacheable(Cacheable c) |
Set the cached object held by this entry.
|
(package private) void |
setCallback(ReplacementPolicy.Callback cb) |
Set the callback object used to notify the replacement algorithm about
actions performed on the cached object.
|
(package private) void |
settingIdentityComplete() |
Notify this entry that the initialization of its cacheable has been
completed.
|
(package private) void |
unkeep() |
Decrement the keep count for this entry.
|
(package private) void |
unkeepForRemove() |
Unkeep the entry and wait until no other thread is keeping it.
|
(package private) void |
unlock() |
Give up exclusive access.
|
(package private) void |
waitUntilIdentityIsSet() |
Block until this entry's cacheable has been initialized (that is, until
settingIdentityComplete() has been called on this object). |
private final java.util.concurrent.locks.ReentrantLock mutex
private Cacheable cacheable
private int keepCount
private java.util.concurrent.locks.Condition forRemove
private java.util.concurrent.locks.Condition settingIdentity
settingIdentityComplete()
private ReplacementPolicy.Callback callback
void lock()
void waitUntilIdentityIsSet()
settingIdentityComplete()
has been called on this object). If
the cacheable has been initialized before this method is called, it will
return immediately. The entry must have been locked for exclusive access
before this method is called. If the method needs to wait, it will
release the lock and reobtain it when it wakes up again.void unlock()
void settingIdentityComplete()
Cacheable.setIdentity()
or
Cacheable.createIdentity()
has been called.void keep(boolean accessed)
accessed
- if true
, notify the entry's callback object
that it has been accessed (normally because of calls to create, find or
findCached); otherwise, don't notify the callback objectvoid unkeep()
boolean isKept()
true
if the object is keptvoid unkeepForRemove()
CacheManager.remove()
, it is the
responsibility of the caller to ensure that only a single thread
executes this method on an object.void setCacheable(Cacheable c)
c
- a cacheable, or null
if the entry is about to be
removedCacheable getCacheable()
boolean isValid()
Cacheable
and have completed setting its
identity.true
if the entry holds a valid objectvoid setCallback(ReplacementPolicy.Callback cb)
cb
- the callback objectvoid free()
Cacheable
can be reused.Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.