messif.buckets.impl
Class DiskBlockBucket

java.lang.Object
  extended by messif.buckets.Bucket
      extended by messif.buckets.LocalBucket
          extended by messif.buckets.impl.DiskBlockBucket
All Implemented Interfaces:
java.io.Serializable, ObjectProvider<LocalAbstractObject>

public class DiskBlockBucket
extends LocalBucket
implements java.io.Serializable

A disk-oriented implementation of LocalBucket. It stores all objects in a specified blocks of a file. The storage is persistent, even if the process using this bucket quits, the bucket can be opened afterwards. Note that this bucket only saves the name of the file when serialized, thus the file must exist when the bucket is deserialized.

See Also:
BucketDispatcher, LocalBucket, DiskBlockObjectKeyBucket, Serialized Form

Field Summary
protected static java.lang.String FILENAME_PREFIX
          The prefix for auto-generated filenames
protected static java.lang.String FILENAME_SUFFIX
          The suffix for auto-generated filenames
protected  ModifiableIndex<LocalAbstractObject> objects
          Object storage
 
Fields inherited from class messif.buckets.LocalBucket
counterBucketAddObject, counterBucketDelObject, counterBucketRead
 
Constructor Summary
DiskBlockBucket(long capacity, long softCapacity, long lowOccupation, java.io.File file)
          Constructs a new DiskBlockBucket instance with 16k direct-buffered input.
DiskBlockBucket(long capacity, long softCapacity, long lowOccupation, java.io.File file, int bufferSize, boolean directBuffers, boolean memoryMap, BinarySerializator serializator)
          Constructs a new DiskBlockBucket instance.
 
Method Summary
 void destroy()
          Destroy this bucket.
 void finalize()
          Finalize this bucket.
static DiskBlockBucket getBucket(long capacity, long softCapacity, long lowOccupation, boolean occupationAsBytes, java.util.Map<java.lang.String,java.lang.Object> parameters)
          Creates a bucket.
protected  ModifiableIndex<LocalAbstractObject> getModifiableIndex()
          Returns the index (including storage) for this bucket.
 
Methods inherited from class messif.buckets.LocalBucket
addObject, addObject, addObjectErrCode, deleteAllObjects, deleteObject, deleteObject, deleteObject, deregisterFilter, getAllObjects, getBucketID, getCapacity, getFilter, getIndex, getLowOccupation, getObject, getObject, getObject, getObjectCount, getOccupation, getOccupationRatio, getSoftCapacity, isBucketStandalone, isSoftCapacityExceeded, registerFilter, setLowOccupation, setSoftCapacity, toString
 
Methods inherited from class messif.buckets.Bucket
addObjects, addObjects, deleteObject, deleteObjects, processQuery, provideObjects, split
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILENAME_PREFIX

protected static final java.lang.String FILENAME_PREFIX
The prefix for auto-generated filenames

See Also:
Constant Field Values

FILENAME_SUFFIX

protected static final java.lang.String FILENAME_SUFFIX
The suffix for auto-generated filenames

See Also:
Constant Field Values

objects

protected final ModifiableIndex<LocalAbstractObject> objects
Object storage

Constructor Detail

DiskBlockBucket

public DiskBlockBucket(long capacity,
                       long softCapacity,
                       long lowOccupation,
                       java.io.File file)
                throws java.io.IOException
Constructs a new DiskBlockBucket instance with 16k direct-buffered input. A generic MultiClassSerializator is used to serialize objects and the occupation is counted in bytes.

Parameters:
capacity - maximal capacity of the bucket - cannot be exceeded
softCapacity - maximal soft capacity of the bucket
lowOccupation - a minimal occupation for deleting objects - cannot be lowered
file - the file where the bucket will be stored
Throws:
java.io.IOException - if there was a problem opening or creating the bucket file

DiskBlockBucket

public DiskBlockBucket(long capacity,
                       long softCapacity,
                       long lowOccupation,
                       java.io.File file,
                       int bufferSize,
                       boolean directBuffers,
                       boolean memoryMap,
                       BinarySerializator serializator)
                throws java.io.IOException
Constructs a new DiskBlockBucket instance. Occupation is counted in bytes.

Parameters:
capacity - maximal capacity of the bucket - cannot be exceeded
softCapacity - maximal soft capacity of the bucket
lowOccupation - a minimal occupation for deleting objects - cannot be lowered
file - the file where the bucket will be stored
bufferSize - the size of the buffer used for I/O operations
directBuffers - flag whether to use the direct buffers
memoryMap - flag whether to use memory-mapped I/O
serializator - the binary serializator used to store objects
Throws:
java.io.IOException - if there was a problem opening or creating the bucket file
Method Detail

finalize

public void finalize()
              throws java.lang.Throwable
Description copied from class: LocalBucket
Finalize this bucket. All transient resources associated with this bucket are released. After this method is called, the bucket methods' behavior is unpredictable. This method is called by the BucketDispatcher when it is finalized.

Overrides:
finalize in class LocalBucket
Throws:
java.lang.Throwable - if there was an error while cleaning

destroy

public void destroy()
             throws java.lang.Throwable
Description copied from class: LocalBucket
Destroy this bucket. This method releases all resources (transient and persistent) associated with this bucket (e.g. the statistics and all objects are deleted). After this method is called, the bucket methods' behavior is unpredictable. This method is called by the BucketDispatcher when the bucket is removed from the dispatcher.

Overrides:
destroy in class LocalBucket
Throws:
java.lang.Throwable - if there was an error while cleaning

getBucket

public static DiskBlockBucket getBucket(long capacity,
                                        long softCapacity,
                                        long lowOccupation,
                                        boolean occupationAsBytes,
                                        java.util.Map<java.lang.String,java.lang.Object> parameters)
                                 throws java.io.IOException,
                                        java.lang.InstantiationException,
                                        java.lang.ClassNotFoundException
Creates a bucket. For the description of additional parameters that can be specified in the parameters map see DiskStorage.create(java.lang.Class, java.util.Map).

Parameters:
capacity - maximal capacity of the bucket - cannot be exceeded
softCapacity - maximal soft capacity of the bucket
lowOccupation - a minimal occupation for deleting objects - cannot be lowered
occupationAsBytes - flag whether the occupation (and thus all the limits) are in bytes or number of objects
parameters - list of named parameters (see above)
Returns:
a new SimpleDiskBucket instance
Throws:
java.io.IOException - if something goes wrong when working with the filesystem
java.lang.InstantiationException - if the parameters specified are invalid (non existent directory, null values, etc.)
java.lang.ClassNotFoundException - if the parameter class could not be resolved or is not a descendant of LocalAbstractObject

getModifiableIndex

protected ModifiableIndex<LocalAbstractObject> getModifiableIndex()
Description copied from class: LocalBucket
Returns the index (including storage) for this bucket. The index provides the access to the underlying storage of objects in this bucket.

Specified by:
getModifiableIndex in class LocalBucket
Returns:
the index for this bucket