Naanou.LookupService
Class KeyStorage

Holds Naanou.Common.KeyContainer. Manages the storing and expiry of keys stored by a node by other network peers.

External entities only have read-only access to storage

Field Summary
System.Collections.Hashtable hash
         Hashtable of ArrayList or Naanou.Common.KeyContainer. Keyed by the KeyContainer's key.
int INITIAL_SIZE
         Initial number of entries for hashtable
Naanou.LookupService.Node node
int peakSize
         Keeps track of the largest size seen of the storage
int QUERY_PROGRESS_LENGTH
         How many entries to buffer before sending off to client

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

Property Summary
int Count
         Gets the number of keys stored
double PeakUtilisation
         Gets the peak utilisation (%) of key storage
double Utilisation
         Gets the utilisation (%) of key storage

Method Summary
void Add(Naanou.Common.KeyContainer key)
         Adds a key.
void CacheKey(Naanou.Common.KeyContainer key)
void Clear()
         Clears all keys
bool Contains(Naanou.Common.KeyContainer key)
bool Contains(Naanou.Common.KeyContainer key, bool reInsert)
         Checks whether storage contains a key.
string Dump()
         Dumps data into a string
System.Collections.ArrayList DumpKeys()
         Dumps all keys into one giant ArrayList
Naanou.Common.Search.SearchResult GetContentHashResult(Naanou.Common.KeyContainer key, Naanou.Common.Search.SearchPart part)
Naanou.Common.KeyContainer[] GetKeys(Naanou.Common.Hash id)
         Returns a set of keys that have a certain id, without caring about who put them there
Naanou.Common.KeyContainer[] GetKeys(Naanou.Common.Hash id, Naanou.Common.Hash inserter)
         Returns a set of keys that have a certain id and were inserted by a particular id
Naanou.Common.Search.SearchResult GetOtherResult(Naanou.Common.KeyContainer key, Naanou.Common.Search.SearchPart part)
void Maintain(int found, int removed, int cached)
         Weeds out expired keys as well as performs caching of keys
void NeighbourSync()
         Attempts to synchronise to neighbours by getting their keys and inserting locally
void Query(Naanou.Common.Search.SearchPart part, Naanou.Common.QueryProgressDelegate callback, string clientIdSerial, string requestSerial)
         Query (sync). Called by Node
void RemoveKey(Naanou.Common.Hash id, Naanou.Common.Hash inserter, Naanou.LookupService.KeyRemoveReason reason)
         Removes key. Removals of non-existent keys is silent
void RemoveList(System.Collections.ArrayList list, Naanou.Common.Hash id, bool maintainenceRun, Naanou.LookupService.KeyRemoveReason reason, int removedCount, int found, int cached)
         Removes a particular key from a list, and also is used by Maintain method to do GCing and caching
string ToString()
         Returns a string representation of key storage, including usage information

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

Event Summary
Naanou.LookupService.KeyAddedEventHandler KeyAdded
         Key has been added
Naanou.LookupService.KeyRemovedEventHandler KeyRemoved
         Key has been removed
Naanou.LookupService.KeysClearedEventHandler KeysCleared
         Keys have been cleared


Field Detail

hash

private System.Collections.Hashtable hash

Hashtable of ArrayList or Naanou.Common.KeyContainer. Keyed by the KeyContainer's key.


INITIAL_SIZE

private int INITIAL_SIZE

Initial number of entries for hashtable


node

private Naanou.LookupService.Node node


peakSize

private int peakSize

Keeps track of the largest size seen of the storage


QUERY_PROGRESS_LENGTH

public int QUERY_PROGRESS_LENGTH

How many entries to buffer before sending off to client

Constructor Detail

KeyStorage

public KeyStorage(Naanou.LookupService.Node node)

Constructor

Property Detail

Count

public int Count

Gets the number of keys stored


PeakUtilisation

public double PeakUtilisation

Gets the peak utilisation (%) of key storage


Utilisation

public double Utilisation

Gets the utilisation (%) of key storage

Method Detail

Add

internal void Add(Naanou.Common.KeyContainer key)

Adds a key.

Fires Naanou.LookupService.KeyStorage.KeyAdded event

Parameters:
key - Key to store
Throws:
System.ArgumentNullException - If key is empty
System.ArgumentException - If key exists

CacheKey

private void CacheKey(Naanou.Common.KeyContainer key)


Clear

internal void Clear()

Clears all keys


Contains

public bool Contains(Naanou.Common.KeyContainer key)


Contains

public bool Contains(Naanou.Common.KeyContainer key,
                     bool reInsert)

Checks whether storage contains a key.

Parameters:
key - Key to lookup
Returns:
True if storage contains key

Dump

public string Dump()

Dumps data into a string

Returns:
Data storage contains

DumpKeys

public System.Collections.ArrayList DumpKeys()

Dumps all keys into one giant ArrayList

Returns:

GetContentHashResult

private Naanou.Common.Search.SearchResult GetContentHashResult(Naanou.Common.KeyContainer key,
                                                               Naanou.Common.Search.SearchPart part)


GetKeys

public Naanou.Common.KeyContainer[] GetKeys(Naanou.Common.Hash id)

Returns a set of keys that have a certain id, without caring about who put them there

Parameters:
id - Id
Returns:
A set of keys that match the alias

GetKeys

public Naanou.Common.KeyContainer[] GetKeys(Naanou.Common.Hash id,
                                            Naanou.Common.Hash inserter)

Returns a set of keys that have a certain id and were inserted by a particular id

Parameters:
id - Id
inserter - Inserter (can be null)
Returns:
A set of keys that match the alias
Throws:
System.ArgumentNullException - If id is null

GetOtherResult

private Naanou.Common.Search.SearchResult GetOtherResult(Naanou.Common.KeyContainer key,
                                                         Naanou.Common.Search.SearchPart part)


Maintain

public void Maintain(int found,
                     int removed,
                     int cached)

Weeds out expired keys as well as performs caching of keys

Parameters:
found - Number of keys found to be stored
removed - Number of keys removed
cached - Number of keys cached

NeighbourSync

public void NeighbourSync()

Attempts to synchronise to neighbours by getting their keys and inserting locally


Query

internal void Query(Naanou.Common.Search.SearchPart part,
                    Naanou.Common.QueryProgressDelegate callback,
                    string clientIdSerial,
                    string requestSerial)

Query (sync). Called by Node

Parameters:
part - What we're after
callback - Callback for results
clientIdSerial - Client id serial

RemoveKey

internal void RemoveKey(Naanou.Common.Hash id,
                        Naanou.Common.Hash inserter,
                        Naanou.LookupService.KeyRemoveReason reason)

Removes key. Removals of non-existent keys is silent

Parameters:
id - Id
inserter - Inserter who's key we wish to remove
reason - Reason for removal

RemoveList

private void RemoveList(System.Collections.ArrayList list,
                        Naanou.Common.Hash id,
                        bool maintainenceRun,
                        Naanou.LookupService.KeyRemoveReason reason,
                        int removedCount,
                        int found,
                        int cached)

Removes a particular key from a list, and also is used by Maintain method to do GCing and caching

Parameters:
list - List
id - Id to remove (or null)
reason - Reason for removal
removedCount - Number of keys removed
found - Number of keys found
cached - Number keys cached
maintainenceRun - Set to true if crawling as part of a maintainence run

ToString

public string ToString()

Returns a string representation of key storage, including usage information

Returns:
String representation of key storage, including usage information
Event Detail

KeyAdded

public Naanou.LookupService.KeyAddedEventHandler KeyAdded

Key has been added


KeyRemoved

public Naanou.LookupService.KeyRemovedEventHandler KeyRemoved

Key has been removed


KeysCleared

public Naanou.LookupService.KeysClearedEventHandler KeysCleared

Keys have been cleared