public Routing[] GetSomeLocations() { List<Routing> returnSome; Routing[] routes; lock(Locations) { returnSome = Locations.Take(ReturnAmount).ToList(); Locations.RemoveAll(x => returnSome.Contains(x)); } int position = 0; int itemCount = returnSome.Count(); if (itemCount > 0) { routes = new Routing[ReturnAmount]; for (int i = 0; i < ReturnAmount; i++) { if (position >= itemCount) { position = 0; } routes[i] = returnSome[position++]; } } else { routes = new Routing[0]; } return routes; }
private void SendWork(MappedAnswer[] ma, TaskInfoCurrentlyWorking ticw, Routing Route) { ReduceList.AddNew(ticw.ID, ma[0]); if (ma[1] != null) { ma[1].Sent(); ma[1].ReduceKey = ma[0].ReduceKey; } CreateAndSendMessage(ma, ticw, Route); }
private void CreateAndSendMessage(MappedAnswer[] ma, TaskInfoCurrentlyWorking ticw, Routing Route) { ReduceMessage rm = new ReduceMessage(); rm.Port = ManagerActor.LocalPort; rm.ReduceDLL = ticw.WorkDLL; rm.TaskID = ticw.ID; rm.Data = ma; rm.ReduceID = ma[0].ReduceKey; new NetworkResponseActor(rm, Route.Port, Route.IP).Start(); }
public bool SendReduce(Routing Route) { bool sentMessage = false; if(ReduceTasks.Count() > 0) { //Console.WriteLine("Reduce Count --------------- : " + ReduceTasks.tasks.First().Value.task.Count()); TaskInfoCurrentlyWorking ticw = ReduceTasks.GetTaskInfo(); MappedAnswer work = ticw.GetPieceToWork(); MappedAnswer work2 = ticw.GetPieceToWork(); if(work != null && work2 != null) { work.Sent(); if (CheckReduceIDs(work, work2) && work != work2) { SendWork(new MappedAnswer[] { work, work2 }, ticw, Route); } else { work2 = ticw.MatchReduceKey(work.ReduceKey, work); if (work2 != null) { SendWork(new MappedAnswer[] { work, work2 }, ticw, Route); } } Console.WriteLine("Sent Reduce Message."); sentMessage = true; } CheckReduceTasksForFinished(ticw.ID); } return sentMessage; }
public bool SendMapReduce(Routing Route) { bool sentMessage = false; if (CurrentTasks.Count() > 0) { //Console.WriteLine("Current Mapped Count : " + CurrentTasks.tasks.First().Value.task.Count()); TaskInfoCurrentlyWorking ticw = CurrentTasks.GetTaskInfo(); MappedAnswer work = ticw.GetPieceToWork(); MappedAnswer work2 = ticw.GetPieceToWork(); // i got rid of the check if work comes back and work2 doesn't........ if (work != null) { work.Sent(); work.isFromMapPart = true; if (CheckReduceIDs(work, work2) && work != work2) { work2.isFromMapPart = true; } else { ReduceList.AddNew(ticw.ID, work); work2 = ticw.MatchReduceKey(work.ReduceKey, work); if (work2 != null) { work2.isFromMapPart = true; } } Console.WriteLine("Sent Reduce from Mapped."); SendWork(new MappedAnswer[] { work, work2 }, ticw, Route); sentMessage = true; } if (OriginalTasks.Count() > 0) { OriginalTasks.CheckForDone(ticw.ID); } } return sentMessage; }
public bool SendMap(Routing Route) { bool sentMessage = false; if (OriginalTasks.Count() > 0) { TaskInfoOriginal taskToWork = OriginalTasks.GetPieceToWork(); TaskIdentifier individualTask = taskToWork.GetPieceToWork(Route.IP); if (individualTask != null) { individualTask.SentItem(); MapMessage mapMessage = new MapMessage(); mapMessage.MapDLL = taskToWork.WorkDLL; mapMessage.Piece = taskToWork.position; mapMessage.Port = ManagerActor.LocalPort; mapMessage.TaskNumber = taskToWork.ID; mapMessage.Data = individualTask.DataObject; new NetworkResponseActor(mapMessage, Route.Port, Route.IP).Start(); Console.WriteLine("Sent a Map job out."); sentMessage = true; } } return sentMessage; }