public override void GenerateTree(Channel q, MapReduceArgs mr_args)
{
ArrayList gen_list = mr_args.GenArg as ArrayList;
string start_range = gen_list[0] as string;
AHAddress start_addr = (AHAddress) AddressParser.Parse(start_range);
AHAddress end_addr;
string end_range;
/// If users do not specify an end range, this method understands
/// that users intend to broadcasting the whole range.
/// Thus, the address of end range is set to (start_address - 2),
/// the farthest address from the start_addr.
if (gen_list.Count < 2) {
BigInteger start_int = start_addr.ToBigInteger();
BigInteger end_int = start_int -2;
end_addr = new AHAddress(end_int);
end_range = end_addr.ToString();
}
else {
end_range = gen_list[1] as string;
end_addr = (AHAddress) AddressParser.Parse(end_range);
}
Log("generating child tree, range start: {0}, range end: {1}.", start_range, end_range);
//we are at the start node, here we go:
ConnectionTable tab = _node.ConnectionTable;
ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
List<MapReduceInfo> retval = new List<MapReduceInfo>();
if (InRange(_this_addr, start_addr, end_addr)) {
if (structs.Count > 0) {
//make connection list in the range.
//left connection list is a list of neighbors which are in the range (this node, end of range)
//right connection list is a list of neighbors which are in the range (start of range, this node)
Brunet.Collections.Pair<List<Connection>,List<Connection>> cons = GetConnectionInfo(_this_addr, start_addr, end_addr, structs);
List<Connection> left_cons = cons.First as List<Connection>;
List<Connection> right_cons = cons.Second as List<Connection>;
//PrintConnectionList(left_cons);
//PrintConnectionList(right_cons);
retval = GenerateTreeInRange(start_addr, end_addr, left_cons, true, mr_args);
List<MapReduceInfo> ret_right = GenerateTreeInRange(start_addr, end_addr, right_cons, false, mr_args);
retval.AddRange(ret_right);
}
else { //this node is a leaf node.
//MapReduceInfo mr_info = null;
//retval.Add(mr_info);
//Console.WriteLine("no connection in the range: return null info");
}
}
else { // _node is out of range. Just pass it to the closest to the middle of range.
retval = GenerateTreeOutRange(start_addr, end_addr, mr_args);
}
q.Enqueue( retval.ToArray());
}