public void PeerGone(string IPPort)
{
try
{
List<string> temp = new List<string>();
foreach (DictionaryEntry item in ParallelPortions)
{
if (item.Value.ToString() == IPPort)
{
temp.Add(item.Key.ToString());
}
}
if (temp.Count > 0)
{
// first get the portion that is not finished
string IndexRange = temp[0];
string startIndex = IndexRange.Substring(0, IndexRange.IndexOf(':'));
string endIndex = IndexRange.Substring(IndexRange.IndexOf(':') + 1);
int startNumber = Int32.Parse(startIndex);
int endNumber = Int32.Parse(endIndex);
int numberofStatements = endNumber - startNumber + 1;
int numberofComputers = permissions.Count;
List<int> lhs = new List<int>();
List<int> rhs = new List<int>();
int numberOfTasks = splitIndex(startNumber, endNumber, numberofComputers, out lhs, out rhs);
Console.WriteLine("(PeerGone)Tasks are re-splitted as follows:");
for (int i = 0; i < lhs.Count; ++i)
{
Console.WriteLine(lhs[i].ToString() + " " + rhs[i].ToString());
}
Hashtable rescheduleParallelPortions = new Hashtable();
ParallelPortions.Remove(IndexRange);
try
{
int count = 0;
foreach (DictionaryEntry Permitted in permissions)
{
if (count < numberOfTasks)
{
string key = lhs[count].ToString() + ":" + rhs[count].ToString();
rescheduleParallelPortions.Add(key, Permitted.Key.ToString());
ParallelPortions.Add(key, Permitted.Key.ToString());
++count;
}
}
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message, "first for.");
}
//int nextStatement = 0;
//int numberofStatements = temp.Count;
//int numberofComputers = permissions.Count;
//int StatementPerComputer;
//if ((numberofStatements % numberofComputers) == 0)
// StatementPerComputer = (int)(numberofStatements / numberofComputers);
//else
// StatementPerComputer = (int)(numberofStatements / numberofComputers + 1);
////split the codes
//foreach (DictionaryEntry Permitted in permissions)
//{
// for (int i = 0; i < StatementPerComputer; i++)
// {
// ParallelPortions[temp[nextStatement]] = Permitted.Key.ToString();
// if (nextStatement >= temp.Count)
// break;
// else
// nextStatement++;
// }
// if (nextStatement >= temp.Count)
// break;
//}
foreach (DictionaryEntry item in rescheduleParallelPortions)
{
//if (temp.Contains(item.Key.ToString()))
{
string theIP = item.Value.ToString();
theIP = theIP.Substring(0, theIP.IndexOf(':'));
string thePort = item.Value.ToString();
thePort = thePort.Substring(thePort.IndexOf(':') + 1);
string tmpIndexRange = item.Key.ToString();
string tmpStartIndex = tmpIndexRange.Substring(0, tmpIndexRange.IndexOf(':'));
string tmpEndIndex = tmpIndexRange.Substring(tmpIndexRange.IndexOf(':') + 1);
AsynchronousClient client = new AsynchronousClient();
client.SetSingleMsg(theIP, thePort, createParallelDistributionMessage(tmpStartIndex, tmpEndIndex));
Thread t = new Thread(new ThreadStart(client.SendSingleClient));
t.IsBackground = true;
t.Start();
}
}
}
}
catch (Exception e)
{ Console.WriteLine(e.ToString()); }
}
public void incomingResult(string result, string index)