Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

FileBucket Class Reference

Inheritance diagram for FileBucket:

IBitBucket List of all members.

Public Member Functions

 this (FilePath path, BlockSize block)
 this (FilePath path, BlockSize block, uint initialRecords)
int getBufferSize ()
FilePath getFilePath ()
synchronized ulong length ()
synchronized void[] get (char[] key)
synchronized void remove (char[] key)
synchronized void put (char[] key, void[] data)
synchronized void close ()

Static Public Attributes

static const BlockSize EighthK = {128-1}

Private Attributes

FilePath path
BlockSize block
FileConduit file
Record[char[]] map
ulong fileSize
ulong waterLine

Classes

struct  BlockSize
class  Record

Detailed Description

FileBucket implements a simple mechanism to store and recover a large quantity of data for the duration of the hosting process. It is intended to act as a local-cache for a remote data-source, or as a spillover area for large in-memory cache instances.

Note that any and all stored data is rendered invalid the moment a FileBucket object is garbage-collected.

The implementation follows a fixed-capacity record scheme, where content can be rewritten in-place until said capacity is reached. At such time, the altered content is moved to a larger capacity record at end-of-file, and a hole remains at the prior location. These holes are not collected, since the lifespan of a FileBucket is limited to that of the host process.

All index keys must be unique. Writing to the FileBucket with an existing key will overwrite any previous content. What follows is a contrived example:

        char[] text = "this is a test";

        FileBucket bucket = new FileBucket (new FilePath("bucket.bin"), FileBucket.HalfK);

        // insert some data, and retrieve it again
        bucket.put ("a key", text);
        char[] b = cast(char[]) bucket.get ("a key");

        assert (b == text);
        bucket.close();

Definition at line 83 of file FileBucket.d.


Member Function Documentation

this FilePath  path,
BlockSize  block
[inline]
 

Construct a FileBucket with the provided path and record- size. Selecting a record size that roughly matches the serialized content will limit 'thrashing'.

Definition at line 133 of file FileBucket.d.

References block, and path.

this FilePath  path,
BlockSize  block,
uint  initialRecords
[inline]
 

Construct a FileBucket with the provided path, record-size, and inital record count. The latter causes records to be pre-allocated, saving a certain amount of growth activity. Selecting a record size that roughly matches the serialized content will limit 'thrashing'.

Definition at line 148 of file FileBucket.d.

References block, FileBucket::BlockSize::capacity, file, FileConduit, fileSize, path, and ISeekable::seek().

int getBufferSize  )  [inline]
 

Return the block-size in use for this FileBucket

Reimplemented from IBitBucket.

Definition at line 168 of file FileBucket.d.

References block, and FileBucket::BlockSize::capacity.

FilePath getFilePath  )  [inline]
 

Return where the FileBucket is located

Definition at line 179 of file FileBucket.d.

References path.

synchronized ulong length  )  [inline]
 

Return the currently populated size of this FileBucket

Reimplemented from IBitBucket.

Definition at line 190 of file FileBucket.d.

References waterLine.

synchronized void [] get char[]  key  )  [inline]
 

Return the serialized data for the provided key. Returns null if the key was not found.

Reimplemented from IBitBucket.

Definition at line 202 of file FileBucket.d.

References map, and FileBucket::Record::read().

synchronized void remove char[]  key  )  [inline]
 

Remove the provided key from this FileBucket.

Reimplemented from IBitBucket.

Definition at line 220 of file FileBucket.d.

References map.

synchronized void put char[]  key,
void[]  data
[inline]
 

Write a serialized block of data, and associate it with the provided key. All keys must be unique, and it is the responsibility of the programmer to ensure this. Reusing an existing key will overwrite previous data.

Note that data is allowed to grow within the occupied bucket until it becomes larger than the allocated space. When this happens, the data is moved to a larger bucket at the file tail.

Reimplemented from IBitBucket.

Definition at line 239 of file FileBucket.d.

References block, map, and FileBucket::Record::write().

synchronized void close  )  [inline]
 

Close this FileBucket -- all content is lost.

Definition at line 258 of file FileBucket.d.

References DeviceConduit::close(), file, and map.


Member Data Documentation

FilePath path [private]
 

Definition at line 97 of file FileBucket.d.

Referenced by FileBucket::Record::eof(), getFilePath(), and this().

BlockSize block [private]
 

Definition at line 100 of file FileBucket.d.

Referenced by getBufferSize(), put(), and this().

FileConduit file [private]
 

Definition at line 103 of file FileBucket.d.

Referenced by close(), FileBucket::Record::createBucket(), FileBucket::Record::read(), this(), and FileBucket::Record::write().

Record [char[]] map [private]
 

Definition at line 106 of file FileBucket.d.

Referenced by close(), get(), put(), and remove().

ulong fileSize [private]
 

Definition at line 109 of file FileBucket.d.

Referenced by FileBucket::Record::createBucket(), and this().

ulong waterLine [private]
 

Definition at line 112 of file FileBucket.d.

Referenced by FileBucket::Record::createBucket(), and length().

const BlockSize EighthK = {128-1} [static]
 

Definition at line 115 of file FileBucket.d.

HalfK = {512-1} []
 

Definition at line 116 of file FileBucket.d.

OneK = {1024*1-1} []
 

Definition at line 117 of file FileBucket.d.

TwoK = {1024*2-1} []
 

Definition at line 118 of file FileBucket.d.

FourK = {1024*4-1} []
 

Definition at line 119 of file FileBucket.d.

EightK = {1024*8-1} []
 

Definition at line 120 of file FileBucket.d.

SixteenK = {1024*16-1} []
 

Definition at line 121 of file FileBucket.d.

ThirtyTwoK = {1024*32-1} []
 

Definition at line 122 of file FileBucket.d.

SixtyFourK = {1024*64-1} []
 

Definition at line 123 of file FileBucket.d.


The documentation for this class was generated from the following file:
Generated on Sat Dec 24 17:28:38 2005 for Mango by  doxygen 1.4.0