/* * Map method to add CachEntry to CacheList * @param map_arg [content,alpha,start,end] */ public override object Map(object map_arg) { ArrayList arg = map_arg as ArrayList; string input = arg[0] as string; double alpha = (double)arg[1]; //replication factor string st = arg[2] as string; // start brunet address of range string ed = arg[3] as string; // end brunet address of range AHAddress a,b; try { a = (AHAddress)AddressParser.Parse(st); b = (AHAddress)AddressParser.Parse(ed); } catch(Exception e) { throw e; } CacheEntry ce = new CacheEntry(input, alpha, a, b); int result = 0; // if caching is successful, result will set to 1. int previous_count = _cl.Count; try { _cl.Insert(ce); //result = 1; } catch { //insertion failed. } if (_cl.Count > previous_count) { result = 1; } IDictionary my_entry = new ListDictionary(); my_entry["count"]=1; my_entry["height"]=1; my_entry["success"]=result; return my_entry; }
/* <summary></summay>Object insertion method.</summary> <param name="ce">A CacheEntry which is inserted to this node.</param> */ public void Insert(CacheEntry ce) { string Key = ce.Content; if (!_data.ContainsKey(Key) ) { _data.Add(Key,ce); if(CacheList.DeetooLog.Enabled) { ProtocolLog.Write(CacheList.DeetooLog, String.Format( "data {0} added to node {1}", Key, _node.Address)); } } else { //Console.WriteLine("An element with Key = {0} already exists.",Key); } //Console.WriteLine("_data.Count: {0}", _data.Count); }
/** <summary>This provides translation for Rpc methods.<\summary> <param name="caller">The ISender who made the request.<\param> <param name="method">The method requested.</param> <param name="args">A list of arguments to pass to the method.</param> <param name="req_state">The return state sent back to the RpcManager so that it knows who to return the result to.</param> <exception>Thrown when there the method is not pre-defined</exception> <remark>This handler is registered in CacheList constructor.<\remark> */ public void HandleRpc(ISender caller, string method, IList args, object req_state) { object result = null; try { if (method == "InsertHandler") { string content = (string)args[0]; double alpha = (double)args[1]; AHAddress start = (AHAddress)AddressParser.Parse((string)args[2]); AHAddress end = (AHAddress)AddressParser.Parse((string)args[3]); CacheEntry ce = new CacheEntry(content, alpha, start, end); result = InsertHandler(ce); //_rpc.SendResult(req_state,result); } else if (method == "count") { result = _cl.Count; //_rpc.SendResult(req_state,result); } else if (method == "getestimatedsize") { result = _local_network_size; //result = _network_size; //_rpc.SendResult(req_state,result); } else if (method == "medianestimatedsize") { //EstimateNetworkMean(req_state); result = _median_network_size; //_rpc.SendResult(req_state,result); } /* else if (method == "updatenetworksize") { NetworkSize = (int)(args[0]); } */ else { throw new Exception("DeetooHandler.Exception: No Handler for method: " + method); } } catch (Exception e) { result = new AdrException(-32602, e); } _rpc.SendResult(req_state,result); }
/** public CacheEntry(Hashtable ht) { Content = (string)ht["content"]; Alpha = (double)ht["alpha"]; Start = (Address)ht["start"]; End = (Address)ht["end"]; } */ /** <summary>Compares the hashcodes for two Entrys.</summary> <returns>True if they are equal, false otherwise.</returns> */ public bool Equal(CacheEntry ce) { if (this.Content == ce.Content) { return true; } else { return false; } }
/** <summary>Overrided method for insertion, create new CacheEntry with inputs, then, insert CacheEntry to the CacheList.</summary> <param name="str">Content, this is key of hashtable.<param> <param name="alpha">replication factor.<param> <param name="a">start address of range.<param> <param name="b">end address of range.<param> */ public void Insert(string str, double alpha, Address a, Address b) { CacheEntry ce = new CacheEntry(str, alpha, a, b); if (!_data.ContainsKey(str)) { _data.Add(str,ce); if(CacheList.DeetooLog.Enabled) { ProtocolLog.Write(CacheList.DeetooLog, String.Format( "data {0} added to node {1}", str, _node.Address)); } } else { if(CacheList.DeetooLog.Enabled) { ProtocolLog.Write(CacheList.DeetooLog, String.Format( "node: {1}, An element with Key = {0} already exists.",str, _node.Address)); } } //Console.WriteLine("_data.Count: {0}", _data.Count); }