public class IdentityPool
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private class |
IdentityPool.IdentityContext
Context-local container which manages the keys which were returned by
nextPrimaryKey() for this context and were not committed or rolled back.
|
private class |
IdentityPool.KeyScanner
This helper class implements functionality of Identity pool scanning thread.
|
private static class |
IdentityPool.ScanMethod
Enumeration which defines a set of available methods for retrieval of
available keys.
|
Modifier and Type | Field and Description |
---|---|
private ContextLocal<IdentityPool.IdentityContext> |
context
Context-local container for the keys which were returned by
nextPrimaryKey() for this context and were not committed or rolled back.
|
private Range |
currentlyScannedRange
The range currently being scanned.
|
private Database |
database
Database for which this identity pool has been initialized.
|
private java.util.SortedSet<java.lang.Long> |
handedOutKeys
Keys which were returned by nextPrimaryKey() and were not committed or rolled back.
|
private java.util.SortedSet<Range> |
keysPool
Available keys stored in ranges.
|
private static java.util.logging.Logger |
LOG
Logger
|
private int |
maximumScanInterval
Maximum number of seconds to which scanInterval can grow.
|
private long |
maxKey
Current upper bound of key range for scanning.
|
private java.util.SortedSet<java.lang.Long> |
pendingHandedOutKeys
Keys which were returned by nextPrimaryKey(), were committed or
rolled back but included in the range currently being scanned and
pending for scanning to be completed in order to exclude this set
of keys from newly found keys.
|
private long |
poolSize
Number of available keys (total of keysPool and reclaimedKeysPool).
|
private java.util.SortedSet<java.lang.Long> |
reclaimedKeysPool
Available reclaimed keys which are ≤ maxKey.
|
private int |
scanDelay
Number of seconds between range queries, in case an admin wants to
"spread out" the impact of reclamation scans.
|
private int |
scanInterval
The minimum time in seconds between database scans triggered by
scanThreshold.
|
private IdentityPool.ScanMethod |
scanMethod
Method of available keys searching
|
private int |
scanRange
Number of records to involve in each query.
|
private int |
scanThreshold
The minimum size of available IDs being tracked before a database scan
is triggered to find more IDs.
|
private int |
sessionHoldTime
Maximum time between scans (in seconds) for which we can hold the
session in order to not to obtain a new session each time.
|
private boolean |
stopped
Indicates that the pool is stopped (probably because of an error).
|
private int |
targetSize
The number of IDs we will try to reach in the pool, before we stop scanning.
|
private java.lang.Object |
waitLock
Synchronization object between the scanning thread and identity pool itself.
|
Constructor and Description |
---|
IdentityPool(Database database)
Create the identity pool for the given database.
|
Modifier and Type | Method and Description |
---|---|
private void |
clearKeysInHands(java.util.Collection<java.lang.Long> keys)
Notifies the pool that the following handed out keys were committed or
rolled back and we can remove them from the global handed out set.
|
boolean |
isKeyScanningEnabled()
Indicate whether key scanning is enabled.
|
java.io.Serializable |
nextPrimaryKey()
Return the next primary key from the pool (for the database which is
served by this pool).
|
void |
reclaimKeys(java.io.Serializable[] keys)
Returns the array of keys to the pool (presumably recovered by deletes
and create rollbacks).
|
void |
setScanStartKey(java.io.Serializable key)
Tells identity pool the starting high end of keys to check in its
descending range scans.
|
void |
stop()
Stops the pool, i.e.
|
private static final java.util.logging.Logger LOG
private final java.util.SortedSet<Range> keysPool
private final java.util.SortedSet<java.lang.Long> reclaimedKeysPool
private final java.util.SortedSet<java.lang.Long> handedOutKeys
private final java.util.SortedSet<java.lang.Long> pendingHandedOutKeys
private long poolSize
private int targetSize
private int scanThreshold
private int scanInterval
private int maximumScanInterval
private int scanRange
private int scanDelay
private long maxKey
private final Range currentlyScannedRange
private int sessionHoldTime
private IdentityPool.ScanMethod scanMethod
private final java.lang.Object waitLock
private Database database
private boolean stopped
private final ContextLocal<IdentityPool.IdentityContext> context
public IdentityPool(Database database)
database
- Database for which the identity pool will be created.public java.io.Serializable nextPrimaryKey()
null
if no key is
available.public boolean isKeyScanningEnabled()
true
if scan method is not NONE
, else false
.public void setScanStartKey(java.io.Serializable key)
key
- High end of keys.public void reclaimKeys(java.io.Serializable[] keys)
keys
- The array of keys to be returned to the pool.public void stop()
private void clearKeysInHands(java.util.Collection<java.lang.Long> keys)
keys
- Previously handed out keys which were committed or rolled back.