Brunet.Services.Dht.TableServer.Put C# (CSharp) Метод

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
    public bool Put(MemBlock key, MemBlock value, int ttl, bool unique, object rs) {
      if(value.Length > MAX_BYTES) {
        throw new Exception(String.Format(
          "Dht only supports storing data smaller than {0} bytes.", MAX_BYTES));
      }
      PutHandler(key, value, ttl, unique);
      Channel remote_put = new Channel();
      remote_put.CloseAfterEnqueue();
      remote_put.CloseEvent += delegate(Object o, EventArgs eargs) {
        object result = false;
        try {
          result = remote_put.Dequeue();
          RpcResult rpcResult = (RpcResult) result;
          result = rpcResult.Result;
          if(result.GetType() != typeof(bool)) {
            throw new Exception("Incompatible return value.");
          }
          else if(!(bool) result) {
            throw new Exception("Unknown error!");
          }
        }
        catch (Exception e) {
          lock(_sync) {
            _data.RemoveEntry(key, value);
          }
          result = new AdrException(-32602, e);
        }
        _rpc.SendResult(rs, result);
      };

      try {
        Address key_address = new AHAddress(key);
        ISender s = null;
        var structs =
        _node.ConnectionTable.GetConnections(ConnectionType.Structured);
        // We need to forward this to the appropriate node!
        if(((AHAddress)_node.Address).IsLeftOf((AHAddress) key_address)) {
          var con = structs.GetRightNeighborOf(_node.Address);
          s = con.Edge;
        }
        else {
          var con = structs.GetLeftNeighborOf(_node.Address);
          s = con.Edge;
        }
        _rpc.Invoke(s, remote_put, "dht.PutHandler", key, value, ttl, unique);
      }
      catch (Exception) {
        lock(_sync) {
          _data.RemoveEntry(key, value);
        }
        throw;
      }
      return true;
    }