C# Класс 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.
Наследование: IRpcHandler
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
_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

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Описание методов

ConnectionHandler() защищенный Метод

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.
Результат void

DepartureHandler() защищенный Метод

Called when Node.Disconnect is triggered stopping transfer states and preventing any more transfers.
protected DepartureHandler ( ) : void
Результат void

Get() публичный Метод

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
Результат IList

HandleRpc() публичный Метод

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.
Результат void

Put() публичный Метод

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.
Результат bool

PutHandler() публичный Метод

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.
Результат bool

StateChangeHandler() защищенный Метод

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.
Результат void

TableServer() публичный Метод

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.
Результат System

Описание свойств

_data защищенное свойство

The data store for this dht server
protected TableServerData,Brunet.Services.Dht _data
Результат TableServerData

_left_addr защищенное свойство

Our left neighbors address.
protected Address,Brunet _left_addr
Результат Brunet.Address

_left_transfer_state защищенное свойство

The current transfer state to our left.
protected TransferState _left_transfer_state
Результат TransferState

_node защищенное свойство

The node the dht is serving from.
protected Node,Brunet _node
Результат Brunet.Node

_online защищенное свойство

Do not allow dht operations until StructuredConnectionOverlord is connected.
protected bool _online
Результат bool

_right_addr защищенное свойство

Our right neighbors address.
protected Address,Brunet _right_addr
Результат Brunet.Address

_right_transfer_state защищенное свойство

The current transfer state to our right.
protected TransferState _right_transfer_state
Результат TransferState

_rpc защищенное свойство

The RpcManager the dht is serving from.
protected RpcManager _rpc
Результат RpcManager

_sync защищенное свойство

Used to lock the TableServerData.
protected Object _sync
Результат Object

_transfer_sync защищенное свойство

Used to lock connection and transfer state.
protected Object _transfer_sync
Результат Object