Main Page | Class Hierarchy | Alphabetical List | Class List | 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)
 ~this ()
int getBufferSize ()
FilePath getFilePath ()
synchronized long length ()
synchronized void[] get (char[] key)
synchronized void remove (char[] key)
synchronized void put (char[] key, void[] data)
synchronized void close ()

Public Attributes

 HalfK = {512-1}
 OneK = {1024*1-1}
 TwoK = {1024*2-1}
 FourK = {1024*4-1}
 EightK = {1024*8-1}
 SixteenK = {1024*16-1}
 ThirtyTwoK = {1024*32-1}
 SixtyFourK = {1024*64-1}

Static Public Attributes

const BlockSize EighthK = {128-1}

Private Attributes

FilePath path
BlockSize block
FileConduit file
Record[char[]] map
Buffer buffer
long fileSize
long waterLine

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 82 of file FileBucket.d.


Constructor & Destructor Documentation

~this  )  [inline]
 

Destructor tries to close the file, if not already done.

Definition at line 175 of file FileBucket.d.

References close().


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 135 of file FileBucket.d.

References block.

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 150 of file FileBucket.d.

References block, FileBucket::BlockSize::capacity, file, FileConduit, fileSize, FileConduit::seek(), and Buffer::setConduit().

int getBufferSize  )  [inline]
 

Return the block-size in use for this FileBucket

Reimplemented from IBitBucket.

Definition at line 186 of file FileBucket.d.

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

FilePath getFilePath  )  [inline]
 

Return where the FileBucket is located

Definition at line 197 of file FileBucket.d.

synchronized long length  )  [inline]
 

Return the currently populated size of this FileBucket

Reimplemented from IBitBucket.

Definition at line 208 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 220 of file FileBucket.d.

References FileBucket::Record::read().

Referenced by testFileBucket().

synchronized void remove char[]  key  )  [inline]
 

Remove the provided key from this FileBucket.

Reimplemented from IBitBucket.

Definition at line 238 of file FileBucket.d.

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 257 of file FileBucket.d.

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

Referenced by testFileBucket().

synchronized void close  )  [inline]
 

Close this FileBucket -- all content is lost.

Definition at line 275 of file FileBucket.d.

References file.

Referenced by testFileBucket(), testVirtualCache(), and ~this().


Member Data Documentation

FilePath path [private]
 

Definition at line 96 of file FileBucket.d.

Referenced by FileBucket::Record::eof().

BlockSize block [private]
 

Definition at line 99 of file FileBucket.d.

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

FileConduit file [private]
 

Definition at line 102 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 105 of file FileBucket.d.

Buffer buffer [private]
 

Definition at line 108 of file FileBucket.d.

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

long fileSize [private]
 

Definition at line 111 of file FileBucket.d.

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

long waterLine [private]
 

Definition at line 114 of file FileBucket.d.

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

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

Definition at line 117 of file FileBucket.d.

HalfK = {512-1}
 

Definition at line 118 of file FileBucket.d.

OneK = {1024*1-1}
 

Definition at line 119 of file FileBucket.d.

TwoK = {1024*2-1}
 

Definition at line 120 of file FileBucket.d.

FourK = {1024*4-1}
 

Definition at line 121 of file FileBucket.d.

EightK = {1024*8-1}
 

Definition at line 122 of file FileBucket.d.

SixteenK = {1024*16-1}
 

Definition at line 123 of file FileBucket.d.

ThirtyTwoK = {1024*32-1}
 

Definition at line 124 of file FileBucket.d.

SixtyFourK = {1024*64-1}
 

Definition at line 125 of file FileBucket.d.


The documentation for this class was generated from the following file:
Generated on Sun Nov 7 19:07:02 2004 for Mango by doxygen 1.3.6