C# Class Brunet.Services.Dht.TableServer

The TableServer provides the Dht server end point.
Besides providing entry points for dht operations such as Get, Put, and Create; it also contains the logic necessary to transfer keys when there is churn in the system, this is implemented in ConnectionHandler, DepartureHandler, and TransferState.
Inheritance: IRpcHandler
Afficher le fichier Open project: johnynek/brunet Class Usage Examples

Protected Properties

Свойство Type Description
_data TableServerData
_left_addr Brunet.Address
_left_transfer_state TransferState
_node Brunet.Node
_online bool
_right_addr Brunet.Address
_right_transfer_state TransferState
_rpc RpcManager
_sync Object
_transfer_sync Object

Méthodes publiques

Méthode Description
Get ( MemBlock key, byte token ) : IList

Retrieves data from the Dht.

First old entries for the key are deleted from the dht, second a look up is performed, and finally using the token a range of data is selectively returned.

HandleRpc ( ISender caller, string method, IList args, object rs ) : void

This provides faster translation for Rpc methods as well as allows for Asynchronous Rpc calls which are required for Puts and Creates.

Put ( MemBlock key, MemBlock value, int ttl, bool unique, object rs ) : bool

Called by a Dht client to store data here, this supports both Puts and Creates by using the unique parameter.

Puts will store the value no matter what, Creates will only store the value if they are the first ones to store data on that key. This is the first part of a Put operation. This calls PutHandler on itself and the neighbor nearest to the key, which actually places the data into the store. The result is returned to the client upon completion of the call to the neighbor, if that fails the data is removed locally and an exception is sent to the client indicating failure.

PutHandler ( MemBlock key, MemBlock value, int ttl, bool unique ) : bool

Attempts to store the key:value pair into this server.

First the dht deletes any expired entries stored at the key, second it retrieves the entries from the data store. If it is empty it creates a new entry and returns. Otherwise, it looks for the value in the list and updates the lease time. If there is no entry for that key:value pair it either adds it in the case of a put or throws an exception if it is a create.

TableServer ( Node node ) : System

Creates a new TableServer object and registers it to the "dht" handler in the node's RpcManager.

Méthodes protégées

Méthode Description
ConnectionHandler ( object o, EventArgs eargs ) : void

This is called whenever there is a disconnect or a connect, the idea is to determine if there is a new left or right node, if there is and here is a pre-existing transfer, we must interupt it, and start a new transfer.

The possible scenarios where this would be active: - no change on left - new left node with no previous node (from disc or new node) - left disconnect and new left ready - left disconnect and no one ready - no change on right - new right node with no previous node (from disc or new node) - right disconnect and new right ready - right disconnect and no one ready

DepartureHandler ( ) : void

Called when Node.Disconnect is triggered stopping transfer states and preventing any more transfers.

StateChangeHandler ( Node n, Node state ) : void

If we are or were connected in the right place, we accept DHT messages otherwise we ignore them.

Method Details

ConnectionHandler() protected méthode

This is called whenever there is a disconnect or a connect, the idea is to determine if there is a new left or right node, if there is and here is a pre-existing transfer, we must interupt it, and start a new transfer.
The possible scenarios where this would be active: - no change on left - new left node with no previous node (from disc or new node) - left disconnect and new left ready - left disconnect and no one ready - no change on right - new right node with no previous node (from disc or new node) - right disconnect and new right ready - right disconnect and no one ready
protected ConnectionHandler ( object o, EventArgs eargs ) : void
o object Unimportant
eargs System.EventArgs Contains the ConnectionEventArgs, which lets us know if this was a Structured Connection change and if it is, we should check the state of the system to see if we have a new left or right neighbor.
Résultat void

DepartureHandler() protected méthode

Called when Node.Disconnect is triggered stopping transfer states and preventing any more transfers.
protected DepartureHandler ( ) : void
Résultat void

Get() public méthode

Retrieves data from the Dht.
First old entries for the key are deleted from the dht, second a look up is performed, and finally using the token a range of data is selectively returned.
public Get ( MemBlock key, byte token ) : IList
key MemBlock The index used to look up. Contains the data necessary to do follow up look ups if all the data stored in a key is to big for MAX_BYTES.
token byte
Résultat IList

HandleRpc() public méthode

This provides faster translation for Rpc methods as well as allows for Asynchronous Rpc calls which are required for Puts and Creates.
Thrown when there the method is not Put, PutHandler, Get, Dump, or Count
public HandleRpc ( ISender caller, string method, IList args, object rs ) : void
caller ISender The ISender who made the request.
method string The method requested.
args IList A list of arguments to pass to the method.
rs object The return state sent back to the RpcManager so that it knows who to return the result to.
Résultat void

Put() public méthode

Called by a Dht client to store data here, this supports both Puts and Creates by using the unique parameter.
Puts will store the value no matter what, Creates will only store the value if they are the first ones to store data on that key. This is the first part of a Put operation. This calls PutHandler on itself and the neighbor nearest to the key, which actually places the data into the store. The result is returned to the client upon completion of the call to the neighbor, if that fails the data is removed locally and an exception is sent to the client indicating failure.
Data is too large, unresolved remote issues, or the create is no successful
public Put ( MemBlock key, MemBlock value, int ttl, bool unique, object rs ) : bool
key MemBlock The index to store the data at.
value MemBlock Data to store at the key.
ttl int Dht lease time in seconds
unique bool True if this should perform a create, false otherwise.
rs object The return state sent back to the RpcManager so that it knows who to return the result to.
Résultat bool

PutHandler() public méthode

Attempts to store the key:value pair into this server.
First the dht deletes any expired entries stored at the key, second it retrieves the entries from the data store. If it is empty it creates a new entry and returns. Otherwise, it looks for the value in the list and updates the lease time. If there is no entry for that key:value pair it either adds it in the case of a put or throws an exception if it is a create.
Data is too large, unresolved remote issues, or the create is no successful
public PutHandler ( MemBlock key, MemBlock value, int ttl, bool unique ) : bool
key MemBlock The index to store the data at.
value MemBlock Data to store at the key.
ttl int Dht lease time in seconds
unique bool True if this should perform a create, false otherwise.
Résultat bool

StateChangeHandler() protected méthode

If we are or were connected in the right place, we accept DHT messages otherwise we ignore them.
protected StateChangeHandler ( Node n, Node state ) : void
n Brunet.Node The node for this event.
state Brunet.Node The new state.
Résultat void

TableServer() public méthode

Creates a new TableServer object and registers it to the "dht" handler in the node's RpcManager.
public TableServer ( Node node ) : System
node Brunet.Node The node the dht is to serve from.
Résultat System

Property Details

_data protected_oe property

The data store for this dht server
protected TableServerData,Brunet.Services.Dht _data
Résultat TableServerData

_left_addr protected_oe property

Our left neighbors address.
protected Address,Brunet _left_addr
Résultat Brunet.Address

_left_transfer_state protected_oe property

The current transfer state to our left.
protected TransferState _left_transfer_state
Résultat TransferState

_node protected_oe property

The node the dht is serving from.
protected Node,Brunet _node
Résultat Brunet.Node

_online protected_oe property

Do not allow dht operations until StructuredConnectionOverlord is connected.
protected bool _online
Résultat bool

_right_addr protected_oe property

Our right neighbors address.
protected Address,Brunet _right_addr
Résultat Brunet.Address

_right_transfer_state protected_oe property

The current transfer state to our right.
protected TransferState _right_transfer_state
Résultat TransferState

_rpc protected_oe property

The RpcManager the dht is serving from.
protected RpcManager _rpc
Résultat RpcManager

_sync protected_oe property

Used to lock the TableServerData.
protected Object _sync
Résultat Object

_transfer_sync protected_oe property

Used to lock connection and transfer state.
protected Object _transfer_sync
Résultat Object