Exemple #1
0
        public override void QueryHandler(NameRequestReader request, ResultWriter responseBuff)
        {
            try
            {
                int slave_count = Global.SlaveCount;
                Global.CloudStorage.SearchToSlave(Global.CloudStorage.GetSlaveIDByCellID(1),
                    new NameRequestWriter(request.hop, request.name, request.neighbours));

                int reports_total = ReportsCount(slave_count);
                Console.WriteLine("Waiting for {0} reports", reports_total);
                //waiting for 40 reports
                while (report_num != reports_total)
                {
                    Thread.Sleep(1000);
                }
                responseBuff.matchPersons = matches.ToList<long>();
                report_num = 0;
                matches.Clear();

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #2
0
        public override void QueryHandler(NameRequestReader request, ResultWriter responseBuff)
        {
            try
            {
                int slave_count = Global.SlaveCount;
                Global.CloudStorage.SearchToMySlave(Global.CloudStorage.GetSlaveIdByCellId(1),
                                                    new NameRequestWriter(request.hop, request.name, request.neighbours));

                int reports_total = ReportsCount(slave_count);
                Console.WriteLine("Waiting for {0} reports", reports_total);
                //waiting for 40 reports
                while (report_num != reports_total)
                {
                    Thread.Sleep(1000);
                }
                responseBuff.matchPersons = matches.ToList <long>();
                report_num = 0;
                matches.Clear();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #3
0
        public override void SearchHandler(NameRequestReader request)
        {
            string queryname   = request.name;
            int    hop         = request.hop;
            int    hop_next    = hop + 1;
            int    slave_count = Global.SlaveCount;

            HashSet <long>[] buckets = new HashSet <long> [slave_count];
            for (int i = 0; i < slave_count; ++i)
            {
                buckets[i] = new HashSet <long>();
            }

            HashSet <long> matches = new HashSet <long>();

            request.neighbours.ForEach(candidate =>
            {
                using (var person = Global.LocalStorage.UsePerson(candidate))
                {
                    //find partial results
                    string friendname = person.name;
                    if (friendname.ToLower().Contains(queryname.ToLower()))
                    {
                        matches.Add(candidate);
                    }
                    //group each candidate's friends by their hosting slave
                    if (hop < 3)
                    {
                        person.friends.ForEach(neighbour =>
                        {
                            buckets[Global.CloudStorage.GetSlaveIdByCellId(neighbour)].Add(neighbour);
                        }
                                               );
                    }
                }
            }
                                       );

            //send partial result first
            Global.CloudStorage.ReportToMyProxy(0, new ResultWriter(matches.ToList()));

            //propagate
            if (hop < 3)
            {
                for (int i = 0; i < slave_count; ++i)
                {
                    Global.CloudStorage.SearchToMySlave(i, new NameRequestWriter(hop_next, queryname, buckets[i].ToList()));
                }
            }
        }
Exemple #4
0
        public override void SearchHandler(NameRequestReader request)
        {
            string queryname = request.name;
            int hop = request.hop;
            int hop_next = hop + 1;
            int slave_count = Global.SlaveCount;
            HashSet<long>[] buckets = new HashSet<long>[slave_count];
            for (int i = 0; i < slave_count; ++i)
            {
                buckets[i] = new HashSet<long>();
            }

            HashSet<long> matches = new HashSet<long>();
            request.neighbours.ForEach(candidate =>
                {
                    using (var person = Global.LocalStorage.UsePerson(candidate))
                    {
                        //find partial results
                        string friendname = person.name;
                        if (friendname.ToLower().Contains(queryname.ToLower()))
                        {
                            matches.Add(candidate);
                        }
                        //group each candidate's friends by their hosting slave
                        if (hop < 3)
                        {
                            person.friends.ForEach(neighbour =>
                                {
                                    buckets[Global.CloudStorage.GetSlaveIDByCellID(neighbour)].Add(neighbour);
                                }
                            );
                        }
                    }
                }
            );

            //send partial result first
            Global.CloudStorage.ReportToProxy(0, new ResultWriter(matches.ToList()));

            //propagate
            if (hop < 3)
            {
                for (int i = 0; i < slave_count; ++i)
                {
                    Global.CloudStorage.SearchToSlave(i, new NameRequestWriter(hop_next, queryname, buckets[i].ToList()));
                }
            }
        }