Sirikata
Classes | Public Member Functions | Protected Member Functions | Private Attributes
Sirikata::Transfer::DiskCacheLayer Class Reference

Disk Cache keeps track of what files are on disk, and manages a helper thread to retrieve it. More...

#include <DiskCacheLayer.hpp>

Inheritance diagram for Sirikata::Transfer::DiskCacheLayer:
Collaboration diagram for Sirikata::Transfer::DiskCacheLayer:

List of all members.

Classes

struct  CacheData
struct  DiskRequest

Public Member Functions

void workerThread ()
void unserialize ()
void readDataFromDisk (const Fingerprint &fileId, const Range &requestedRange, const TransferCallback &callback)
void serializeRanges (const RangeList &list, std::string &out)
void unserializeRanges (RangeList &rlist, std::istream &iranges)
 DiskCacheLayer (CachePolicy *policy, const std::string &prefix, CacheLayer *tryNext)
virtual ~DiskCacheLayer ()
virtual void purgeFromCache (const Fingerprint &fileId)
 Purges this hash from all subsequent caches.
virtual void getData (const Fingerprint &fileId, const Range &requestedRange, const TransferCallback &callback)
 Query this cache layer.

Protected Member Functions

virtual void populateCache (const Fingerprint &fileId, const DenseDataPtr &data)
 Goes up the heirararchy of cache layers filling in data.
virtual void destroyCacheEntry (const Fingerprint &fileId, CacheEntry *cacheLayerData, cache_usize_type releaseSize)
 Called after a cache entry has been destroyed-- Does not remove the item from other caches in the chain.

Private Attributes

ThreadSafeQueue
< std::tr1::shared_ptr
< DiskRequest > > 
mRequestQueue
ThreadmWorkerThread
CacheMap mFiles
std::string mPrefix
boost::mutex destroyLock
boost::condition_variable destroyCV
bool mCleaningUp

Detailed Description

Disk Cache keeps track of what files are on disk, and manages a helper thread to retrieve it.


Constructor & Destructor Documentation

Sirikata::Transfer::DiskCacheLayer::DiskCacheLayer ( CachePolicy policy,
const std::string &  prefix,
CacheLayer tryNext 
)
virtual Sirikata::Transfer::DiskCacheLayer::~DiskCacheLayer ( ) [inline, virtual]

Member Function Documentation

virtual void Sirikata::Transfer::DiskCacheLayer::destroyCacheEntry ( const Fingerprint fileId,
CacheEntry cacheLayerData,
cache_usize_type  releaseSize 
) [inline, protected, virtual]

Called after a cache entry has been destroyed-- Does not remove the item from other caches in the chain.

Should be called only from CacheMap.

Reimplemented from Sirikata::Transfer::CacheLayer.

References Sirikata::SHA256::convertToHexString().

virtual void Sirikata::Transfer::DiskCacheLayer::getData ( const Fingerprint fileId,
const Range requestedRange,
const TransferCallback callback 
) [inline, virtual]

Query this cache layer.

If successful, call callback with the data and also call populateCache in order to populate the previous cache levels.

Parameters:
fidA unique identifier corresponding to the file (contains a hash).
requestedRangeA Range object specifying a single range that you need.
callbackTo be called with the data if successful, or NULL if failed.
Returns:
false, if the callback happened synchronously (i.e. in memory cache)

Reimplemented from Sirikata::Transfer::CacheLayer.

References Sirikata::Transfer::DiskCacheLayer::CacheData::contains(), Sirikata::Transfer::CacheMap::read_iterator::find(), Sirikata::Transfer::CacheLayer::getData(), and Sirikata::Transfer::CacheMap::read_iterator::use().

Referenced by workerThread().

virtual void Sirikata::Transfer::DiskCacheLayer::populateCache ( const Fingerprint fileId,
const DenseDataPtr data 
) [inline, protected, virtual]

Goes up the heirararchy of cache layers filling in data.

Parameters:
fileIdthe Fingerprint to store this data in CacheMap.
dataData to be stored in this CacheLayer.

Reimplemented from Sirikata::Transfer::CacheLayer.

References Sirikata::Transfer::CacheLayer::populateParentCaches().

virtual void Sirikata::Transfer::DiskCacheLayer::purgeFromCache ( const Fingerprint fileId) [inline, virtual]

Purges this hash from all subsequent caches.

In general, it is not useful to do this manually, since the CachePolicy handles freeing extra data, and it is usually assumed that the cache is correct.

Validity checking should probably be added elsewhere--though it is not really feasable for incomplete downloads if we used a range.

Reimplemented from Sirikata::Transfer::CacheLayer.

References Sirikata::Transfer::CacheMap::write_iterator::erase(), Sirikata::Transfer::CacheMap::write_iterator::find(), and Sirikata::Transfer::CacheLayer::purgeFromCache().

void Sirikata::Transfer::DiskCacheLayer::readDataFromDisk ( const Fingerprint fileId,
const Range requestedRange,
const TransferCallback callback 
) [inline]
void Sirikata::Transfer::DiskCacheLayer::serializeRanges ( const RangeList list,
std::string &  out 
) [inline]

Referenced by workerThread().

void Sirikata::Transfer::DiskCacheLayer::unserialize ( )
void Sirikata::Transfer::DiskCacheLayer::unserializeRanges ( RangeList rlist,
std::istream &  iranges 
) [inline]
void Sirikata::Transfer::DiskCacheLayer::workerThread ( )

Member Data Documentation

boost::condition_variable Sirikata::Transfer::DiskCacheLayer::destroyCV [private]

Referenced by workerThread().

Referenced by workerThread().

Referenced by workerThread().

Referenced by DiskCacheLayer().


The documentation for this class was generated from the following files: