Naanou.LookupService
Class Cache

Manages the node cache. Node cache resolves BasicAddresses to NodeAddress instances (which in turn hold RemoteNode instances). Nodes expire, and are removed from cache as it approaches full utilisation. Nodes can also be foricibly removed from cache. More commonly accessed nodes will be kept longer.

External entities only have read-only access

Field Summary
System.Collections.Hashtable hash
         Hash of CachedNode structs, keyed by address id
float largestSize
         Keeps track of the largest size hash has been. This will be bounded by MAX_SIZE obviously
int MAX_SIZE
         Maximum size for queue. Set to same as the how large finger tables to minimise thrashing
Naanou.LookupService.Node node
System.Collections.Queue queue
         Queued NodeAddresses (can contain duplicate addresses)
Naanou.Common.Hash selfId

Constructor Summary
Cache(Naanou.LookupService.Node node)
         Constructor

Property Summary
Naanou.LookupService.NodeAddress[] Addresses
         Gets all addresses stored by cache
int Count
         Returns the number of entries in the cache
float LargestCount
         Returns the total number of entries (may be duplicate) that have flowed through the cache
int QueueCount
         Returns the number of entries in the queue
string Stats
         Gets short stats about cache (util, count, queue count, largest count)
double Utilisation
         Returns utilisation

Method Summary
void Add(Naanou.LookupService.NodeAddress address)
         Adds an address to the cache. NodeAddress should be local Cache will ensure address is not already in storage, and keeps size under MAX_SIZE
void Clear(Naanou.LookupService.Node node)
         Clears cache of all data (does not trigger events)
bool Contains(Naanou.Common.Address address)
         Does cache contain an address?
string Dump()
         Returns a string represention of cache, dumping out all the contents
void FreshenAddress(Naanou.LookupService.CachedNode cachedNode)
         This will reinsert address in queue. This will cause duplicate addresses to be held within the queue. Hash still maintains 'maximum one' semantics.
Naanou.LookupService.NodeAddress GetAddress(Naanou.Common.BasicAddress address)
         Returns a previously created Naanou.LookupService.NodeAddress instance for a address, or returns a new one
void PopOff()
         Takes the oldest item off the list. Triggers Naanou.LookupService.Cache.Expired event.
void Remove(Naanou.LookupService.NodeAddress address)
         Forcibly remove a address from the cache
void Remove(Naanou.Common.BasicAddress address)
         Forcibly remove a address from the cache
string ToString()
         Returns a string representation of object

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone

Event Summary
Naanou.LookupService.CacheAddEventHandler Added
         Triggered when a new unique node has been added to cache
Naanou.LookupService.CacheExpiryEventHandler Expired
         Triggered when a node expires from cache
Naanou.LookupService.CacheHitEventHandler Hit
         Triggered whenever the cache returns an existing node
Naanou.LookupService.CacheRemoveEventHandler Removed
         Triggered when a node is forcibly removed from cache


Field Detail

hash

private System.Collections.Hashtable hash

Hash of CachedNode structs, keyed by address id


largestSize

private float largestSize

Keeps track of the largest size hash has been. This will be bounded by MAX_SIZE obviously


MAX_SIZE

public int MAX_SIZE

Maximum size for queue. Set to same as the how large finger tables to minimise thrashing


node

private Naanou.LookupService.Node node


queue

private System.Collections.Queue queue

Queued NodeAddresses (can contain duplicate addresses)


selfId

private Naanou.Common.Hash selfId

Constructor Detail

Cache

internal Cache(Naanou.LookupService.Node node)

Constructor

Property Detail

Addresses

public Naanou.LookupService.NodeAddress[] Addresses

Gets all addresses stored by cache


Count

public int Count

Returns the number of entries in the cache


LargestCount

public float LargestCount

Returns the total number of entries (may be duplicate) that have flowed through the cache


QueueCount

public int QueueCount

Returns the number of entries in the queue


Stats

public string Stats

Gets short stats about cache (util, count, queue count, largest count)


Utilisation

public double Utilisation

Returns utilisation

Method Detail

Add

internal void Add(Naanou.LookupService.NodeAddress address)

Adds an address to the cache. NodeAddress should be local Cache will ensure address is not already in storage, and keeps size under MAX_SIZE

Parameters:
address - Address to add

Clear

internal void Clear(Naanou.LookupService.Node node)

Clears cache of all data (does not trigger events)

Parameters:
node -

Contains

public bool Contains(Naanou.Common.Address address)

Does cache contain an address?

Address is not matched on instance, rather the address id

Parameters:
address - Address to check
Returns:
Boolean indicating whether cache contains an address

Dump

public string Dump()

Returns a string represention of cache, dumping out all the contents

Returns:
String represention of cache

FreshenAddress

private void FreshenAddress(Naanou.LookupService.CachedNode cachedNode)

This will reinsert address in queue. This will cause duplicate addresses to be held within the queue. Hash still maintains 'maximum one' semantics.

Parameters:
cachedNode - Address

GetAddress

public Naanou.LookupService.NodeAddress GetAddress(Naanou.Common.BasicAddress address)

Returns a previously created Naanou.LookupService.NodeAddress instance for a address, or returns a new one

Parameters:
address - Address
Returns:
NodeAddress for BasicAddress

PopOff

private void PopOff()

Takes the oldest item off the list. Triggers Naanou.LookupService.Cache.Expired event.


Remove

internal void Remove(Naanou.LookupService.NodeAddress address)

Forcibly remove a address from the cache

Address is not matched on instance, rather the address id. Address may persist in queue after removal - removal time from queue would be lengthy.

Parameters:
address - Address to remove

Remove

internal void Remove(Naanou.Common.BasicAddress address)

Forcibly remove a address from the cache

Address is not matched on instance, rather the address id. Address may persist in queue after removal - removal time from queue would be lengthy.

Parameters:
address - Address to remove

ToString

public string ToString()

Returns a string representation of object

Returns:
Event Detail

Added

public Naanou.LookupService.CacheAddEventHandler Added

Triggered when a new unique node has been added to cache


Expired

public Naanou.LookupService.CacheExpiryEventHandler Expired

Triggered when a node expires from cache


Hit

public Naanou.LookupService.CacheHitEventHandler Hit

Triggered whenever the cache returns an existing node


Removed

public Naanou.LookupService.CacheRemoveEventHandler Removed

Triggered when a node is forcibly removed from cache