public class BucketDispatcher extends java.lang.Object implements java.io.Serializable, TemporaryCloseable
createBucket(java.lang.Class<? extends messif.buckets.LocalBucket>, long, long, long, boolean, java.util.Map<java.lang.String, java.lang.Object>)
method - the unique ID is assigned automatically.
To create a bucket, a specific bucket implementation class, capacity settings and additional class-specific parameters are needed.
They are either passed to the createBucket
method, or the dispatcher's default values are used.
Automatic pivot choosers can be created for new buckets - see setAutoPivotChooser(java.lang.Class<? extends messif.pivotselection.AbstractPivotChooser>)
.
To remove a bucket from the dispatcher, use removeBucket(int, boolean)
. Note that
objects remain inside the bucket, just the bucket will be no longer maintained
by this dispatcher.LocalBucket
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
log
Logger for the bucket dispatcher
|
static int |
UNASSIGNED_BUCKET_ID
The ID of buckets that do not belong to a dispatcher
|
Constructor and Description |
---|
BucketDispatcher(int maxBuckets,
long bucketCapacity,
java.lang.Class<? extends LocalBucket> defaultBucketClass)
Creates a new instance of BucketDispatcher only with maximal capacity specification.
|
BucketDispatcher(int maxBuckets,
long bucketCapacity,
long bucketSoftCapacity,
long bucketLowOccupation,
boolean bucketOccupationAsBytes,
java.lang.Class<? extends LocalBucket> defaultBucketClass)
Creates a new instance of BucketDispatcher with full specification of default values.
|
BucketDispatcher(int maxBuckets,
long bucketCapacity,
long bucketSoftCapacity,
long bucketLowOccupation,
boolean bucketOccupationAsBytes,
java.lang.Class<? extends LocalBucket> defaultBucketClass,
java.util.Map<java.lang.String,java.lang.Object> defaultBucketClassParams)
Creates a new instance of BucketDispatcher with full specification of default values.
|
Modifier and Type | Method and Description |
---|---|
LocalBucket |
addBucket(LocalBucket bucket)
Add an existing bucket to this dispatcher.
|
boolean |
closeTemporarilyIfIdle(boolean resetAccessCounter)
Release the resources associated with this instance.
|
protected AbstractPivotChooser |
createAutoPivotChooser(LocalBucket bucket)
Creates a new pivot chooser for the provided bucket.
|
LocalBucket |
createBucket()
Create new local bucket with the default storage class and default storage capacity.
|
LocalBucket |
createBucket(java.lang.Class<? extends LocalBucket> storageClass)
Create new local bucket with specified storage class and default storage capacity.
|
static LocalBucket |
createBucket(java.lang.Class<? extends LocalBucket> storageClass,
long capacity,
long softCapacity,
long lowOccupation,
boolean occupationAsBytes,
java.util.Map<java.lang.String,java.lang.Object> storageClassParams)
Create new local bucket with specified storage class and storage capacity (different from default values).
|
LocalBucket |
createBucket(java.lang.Class<? extends LocalBucket> storageClass,
java.util.Map<java.lang.String,java.lang.Object> storageClassParams)
Create new local bucket with specified storage class and default storage capacity.
|
LocalBucket |
createBucket(java.lang.Class<? extends LocalBucket> storageClass,
java.util.Map<java.lang.String,java.lang.Object> storageClassParams,
long capacity,
long softCapacity,
long lowOccupation)
Create new local bucket with specified storage class and storage capacity (different from default values).
|
LocalBucket |
createBucket(long capacity,
long softCapacity,
long lowOccupation)
Create new local bucket with default storage class and specified storage capacity.
|
void |
destroy()
Destroys all buckets managed by this dispatcher.
|
void |
finalize()
Finalize all buckets managed by this dispatcher.
|
java.util.Set<java.lang.Integer> |
getAllBucketIDs()
Returns the set of bucket IDs maintained by this dispatcher.
|
java.util.Collection<LocalBucket> |
getAllBuckets()
Returns the collection of all buckets maintained by this dispatcher.
|
AbstractPivotChooser |
getAutoPivotChooser(int bucketID)
Returns pivot chooser that was automatically created for a bucket of this dispatcher.
|
java.lang.Class<? extends AbstractPivotChooser> |
getAutoPivotChooserClass()
Returns the class of the pivot chooser that is currently used for buckets in this dispatcher.
|
LocalBucket |
getBucket(int bucketID)
Returns the bucket with the specified ID.
|
long |
getBucketCapacity()
Returns the default hard capactity limit for new buckets.
|
int |
getBucketCount()
Returns the actual number of buckets maintained by this dispatcher.
|
long |
getBucketLowOccupation()
Returns the default hard low-occupation capactity limit for new buckets.
|
boolean |
getBucketOccupationAsBytes()
Returns the default flag whether to compute occupation & capacity in bytes (true)
or number of objects (false) for new buckets.
|
long |
getBucketSoftCapacity()
Returns the default soft capactity limit for new buckets.
|
java.lang.Class<? extends LocalBucket> |
getDefaultBucketClass()
Returns the default class for newly created buckets.
|
java.util.Map<java.lang.String,java.lang.Object> |
getDefaultBucketClassParams()
Returns the default parameters for newly created buckets with default bucket class.
|
int |
getMaxBuckets()
Returns the maximal number of buckets maintained by this dispatcher.
|
int |
getObjectCount()
Returns the sum of object counts stored in all buckets maintained by this dispatcher.
|
long |
getOccupation()
Returns the sum of occupations of all buckets maintained by this dispatcher.
|
int |
getOverloadedBucketCount()
Returns number of buckets that exceed their soft-capacities.
|
LocalBucket |
moveBucket(int bucketID,
BucketDispatcher targetDispatcher)
Move the bucket with the specified ID to another dispatcher.
|
void |
removeBucket(int bucketID)
Delete the bucket with specified ID from this dispatcher.
|
LocalBucket |
removeBucket(int bucketID,
boolean destroyBucket)
Delete the bucket with specified ID from this dispatcher.
|
void |
setAllBucketLowOccupation(long bucketLowOccupation)
Set the low occupation for all buckets registered by this dispatcher.
|
void |
setAllBucketSoftCapacity(long bucketSoftCapacity)
Set the soft capacity for all buckets registered by this dispatcher.
|
void |
setAutoPivotChooser(AbstractPivotChooser autoPivotChooserInstance)
Set the pivot chooser instance that chooses pivots for all the buckets in this dispatcher.
|
void |
setAutoPivotChooser(java.lang.Class<? extends AbstractPivotChooser> autoPivotChooserClass)
Set the class of pivot chooser that will be created whenever a bucket is created by this dispatcher.
|
void |
setBucketCapacity(long bucketCapacity)
Set bucket capacity for all new buckets.
|
void |
setBucketLowOccupation(long bucketLowOccupation)
Set parameter "low occupation" for all new buckets
|
void |
setBucketOccupationAsBytes(boolean bucketOccupationAsBytes)
Set parameter
bucketOccupationAsBytes for all new buckets. |
void |
setBucketSoftCapacity(long bucketSoftCapacity)
Set new soft capacity for all new buckets.
|
void |
setDefaultBucketClass(java.lang.Class<? extends LocalBucket> defaultBucketClass)
Set default class for all new buckets
|
void |
setDefaultBucketClassParams(java.util.Map<java.lang.String,java.lang.Object> defaultBucketClassParams)
New parameters for all new default buckets
|
void |
setTemporaryClosePeriod(long period)
Update the period of the automatic temporary-closeable checking of the buckets.
|
java.lang.String |
toString()
Returns information about storage maintained by this dispatcher.
|
protected static final java.util.logging.Logger log
public static final int UNASSIGNED_BUCKET_ID
public BucketDispatcher(int maxBuckets, long bucketCapacity, long bucketSoftCapacity, long bucketLowOccupation, boolean bucketOccupationAsBytes, java.lang.Class<? extends LocalBucket> defaultBucketClass, java.util.Map<java.lang.String,java.lang.Object> defaultBucketClassParams)
maxBuckets
- the maximal number of buckets maintained by this dispatcherbucketCapacity
- the default bucket hard capacity for newly created bucketsbucketSoftCapacity
- the default bucket soft capacity for newly created bucketsbucketLowOccupation
- the default bucket hard low-occupation for newly created bucketsbucketOccupationAsBytes
- the default flag whether to store occupation & capacity in bytes (true) or number of objects (false) for newly create bucketsdefaultBucketClass
- the default class for newly created bucketsdefaultBucketClassParams
- the default parameters for newly created buckets with default bucket classpublic BucketDispatcher(int maxBuckets, long bucketCapacity, long bucketSoftCapacity, long bucketLowOccupation, boolean bucketOccupationAsBytes, java.lang.Class<? extends LocalBucket> defaultBucketClass)
maxBuckets
- the maximal number of buckets maintained by this dispatcherbucketCapacity
- the default bucket hard capacity for newly created bucketsbucketSoftCapacity
- the default bucket soft capacity for newly created bucketsbucketLowOccupation
- the default bucket hard low-occupation for newly created bucketsbucketOccupationAsBytes
- the default flag whether to store occupation & capacity in bytes (true) or number of objects (false) for newly create bucketsdefaultBucketClass
- the default class for newly created bucketspublic BucketDispatcher(int maxBuckets, long bucketCapacity, java.lang.Class<? extends LocalBucket> defaultBucketClass)
maxBuckets
- the maximal number of buckets maintained by this dispatcherbucketCapacity
- the default bucket hard capacity for newly created bucketsdefaultBucketClass
- the default class for newly created bucketspublic void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- if there was an error during releasing resourcespublic void destroy() throws java.lang.Throwable
java.lang.Throwable
- if there was an error during destroying bucketspublic AbstractPivotChooser getAutoPivotChooser(int bucketID)
bucketID
- the ID of the bucket for which to get the pivot chooserpublic void setAutoPivotChooser(java.lang.Class<? extends AbstractPivotChooser> autoPivotChooserClass) throws java.lang.IllegalArgumentException
autoPivotChooserClass
- the class of the pivot chooser to createjava.lang.IllegalArgumentException
- if the specified class is abstract or does not have a public nullary constructorpublic void setAutoPivotChooser(AbstractPivotChooser autoPivotChooserInstance)
autoPivotChooserInstance
- the pivot chooser instancepublic java.lang.Class<? extends AbstractPivotChooser> getAutoPivotChooserClass()
protected AbstractPivotChooser createAutoPivotChooser(LocalBucket bucket)
getAutoPivotChooser(int)
will
return it for the bucket.bucket
- the bucket for which to create pivot chooserpublic void setBucketCapacity(long bucketCapacity)
bucketCapacity
- new hard capacity.public void setBucketLowOccupation(long bucketLowOccupation)
bucketLowOccupation
- new low occupation.public void setBucketOccupationAsBytes(boolean bucketOccupationAsBytes)
bucketOccupationAsBytes
for all new buckets.bucketOccupationAsBytes
- new value for parameter bucketOccupationAsBytes
.public void setBucketSoftCapacity(long bucketSoftCapacity)
bucketSoftCapacity
- new soft capacity parameterpublic void setDefaultBucketClass(java.lang.Class<? extends LocalBucket> defaultBucketClass)
defaultBucketClass
- new bucket default class.public void setDefaultBucketClassParams(java.util.Map<java.lang.String,java.lang.Object> defaultBucketClassParams)
defaultBucketClassParams
- new parameters for default bucketspublic void setAllBucketSoftCapacity(long bucketSoftCapacity)
bucketSoftCapacity
- new bucket soft capacity for the existing bucketspublic void setAllBucketLowOccupation(long bucketLowOccupation)
bucketLowOccupation
- new low occupation.public int getMaxBuckets()
public long getBucketCapacity()
public long getBucketSoftCapacity()
public long getBucketLowOccupation()
public boolean getBucketOccupationAsBytes()
public java.lang.Class<? extends LocalBucket> getDefaultBucketClass()
public java.util.Map<java.lang.String,java.lang.Object> getDefaultBucketClassParams()
public int getBucketCount()
public int getOverloadedBucketCount()
public long getOccupation()
public int getObjectCount()
public java.util.Set<java.lang.Integer> getAllBucketIDs()
public java.util.Collection<LocalBucket> getAllBuckets()
public LocalBucket getBucket(int bucketID) throws java.util.NoSuchElementException
bucketID
- the ID of the bucket to returnjava.util.NoSuchElementException
- if there is no bucket associated with the specified ID in this dispatcherpublic boolean closeTemporarilyIfIdle(boolean resetAccessCounter) throws java.io.IOException
TemporaryCloseable
closeTemporarilyIfIdle
in interface TemporaryCloseable
resetAccessCounter
- flag whether to reset the access counterjava.io.IOException
- if there was a problem closing the instance resourcespublic void setTemporaryClosePeriod(long period)
period
- the new checking period in milliseconds;
zero value means disable the checkingpublic static LocalBucket createBucket(java.lang.Class<? extends LocalBucket> storageClass, long capacity, long softCapacity, long lowOccupation, boolean occupationAsBytes, java.util.Map<java.lang.String,java.lang.Object> storageClassParams) throws java.lang.IllegalArgumentException
storageClass
- the class that represents the bucket implementation to usecapacity
- the hard capacity of the new bucketsoftCapacity
- the soft capacity of the new bucket (soft <= hard must hold otherwise hard is set to soft)lowOccupation
- the low-occupation limit for the new bucketoccupationAsBytes
- flag whether the occupation (and thus all the limits) are in bytes or number of objectsstorageClassParams
- additional parameters for creating a new instance of the storageClassjava.lang.IllegalArgumentException
- if public LocalBucket createBucket(java.lang.Class<? extends LocalBucket> storageClass, java.util.Map<java.lang.String,java.lang.Object> storageClassParams, long capacity, long softCapacity, long lowOccupation) throws BucketStorageException, java.lang.IllegalArgumentException
storageClass
- the class that represents the bucket implementation to usestorageClassParams
- additional parameters for creating a new instance of the storageClasscapacity
- the hard capacity of the new bucketsoftCapacity
- the soft capacity of the new bucket (soft <= hard must hold otherwise hard is set to soft)lowOccupation
- the low-occupation limit for the new bucketBucketStorageException
- if the maximal number of buckets is already allocatedjava.lang.IllegalArgumentException
- if public LocalBucket createBucket() throws BucketStorageException, java.lang.IllegalArgumentException
BucketStorageException
- if the maximal number of buckets is already allocatedjava.lang.IllegalArgumentException
- if public LocalBucket createBucket(java.lang.Class<? extends LocalBucket> storageClass) throws BucketStorageException, java.lang.IllegalArgumentException
storageClass
- the class that represents the bucket implementation to useBucketStorageException
- if the maximal number of buckets is already allocatedjava.lang.IllegalArgumentException
- if public LocalBucket createBucket(java.lang.Class<? extends LocalBucket> storageClass, java.util.Map<java.lang.String,java.lang.Object> storageClassParams) throws BucketStorageException, java.lang.IllegalArgumentException
storageClass
- the class that represents the bucket implementation to usestorageClassParams
- additional parameters for creating a new instance of the storageClassBucketStorageException
- if the maximal number of buckets is already allocatedjava.lang.IllegalArgumentException
- if public LocalBucket createBucket(long capacity, long softCapacity, long lowOccupation) throws BucketStorageException, java.lang.IllegalArgumentException
capacity
- the hard capacity of the new bucketsoftCapacity
- the soft capacity of the new bucket (soft <= hard must hold otherwise hard is set to soft)lowOccupation
- the low-occupation limit for the new bucketBucketStorageException
- if the maximal number of buckets is already allocatedjava.lang.IllegalArgumentException
- if public LocalBucket addBucket(LocalBucket bucket) throws java.lang.IllegalStateException, BucketStorageException
bucket
- the bucket to add to this dispatcherjava.lang.IllegalStateException
- if the bucket is already maintained by another oneBucketStorageException
- if the maximal number of buckets is already allocatedpublic LocalBucket removeBucket(int bucketID, boolean destroyBucket) throws java.util.NoSuchElementException
destroyBucket == false
),
the bucket will be no longer maintained by this dispatcher, but no objects
are deleted from the bucket.bucketID
- the ID of the bucket to deletedestroyBucket
- if true, all the objects in the bucket are destroyed.java.util.NoSuchElementException
- if there is no bucket with the specified IDpublic void removeBucket(int bucketID) throws java.util.NoSuchElementException
destroyed
,
i.e. all objects are deleted and
However, statistics for the bucket are destroyed.bucketID
- the ID of the bucket to deletejava.util.NoSuchElementException
- if there is no bucket with the specified IDpublic LocalBucket moveBucket(int bucketID, BucketDispatcher targetDispatcher) throws java.util.NoSuchElementException, BucketStorageException
bucketID
- the ID of the bucket to movetargetDispatcher
- the target dispatcher to move the bucket tojava.util.NoSuchElementException
- if there is no bucket with the specified IDBucketStorageException
- if the maximal number of buckets is already allocatedpublic java.lang.String toString()
toString
in class java.lang.Object