Example #1
0
        //public Dictionary<string, Dictionary<string, string>> entity = new Dictionary<string, Dictionary<string, string>>();

        public static void Isis_Start()
        {
            IsisSystem.Start();
            g = new Group("pb476_cs5412");
            int myRank = 0;


            g.ViewHandlers += (ViewHandler) delegate(View v)
            {
                IsisSystem.WriteLine("New View: " + v);
                myRank = v.GetMyRank();

                if (v.members.Length == 5)
                {
                    go.Release(1);
                }
            };
            g.Handlers[UPDATE] += (Action <string, string, string>) delegate(string key, string value, string attkey)
            {
                Dictionary <string, string> attr = new Dictionary <string, string>();
                if (value == "null")
                {
                    entity.Remove(key);
                }
                else if (entity.ContainsKey(key))
                {
                    entity[key] = attr;
                    attr[key]   = attkey;
                }
                else
                {
                    entity.Add(key, attr);
                }
                //collection cp = new collection();
                CS5412_Service cp = new CS5412_Service();
                cp.Set(key, value, attkey);
                IsisSystem.WriteLine("New collection: " + key + "/" + value + "/" + attkey);
            };
            g.Handlers[LOOKUP] += (Action <string>) delegate(string key)
            {
                Dictionary <string, string> attr = new Dictionary <string, string>();
                string result = null;
                //attr = entity;

                if (entity.ContainsKey(key))
                {
                    result = attr[key];
                }


                IsisSystem.WriteLine("=== Query for arg=" + key + "Result" + result);

                /*List<string> answer = new List<string>();
                 * //foreach (collection tp in database)
                 *  if (Get(key) == key)
                 *  {
                 *      IsisSystem.WriteLine("Including " + Get(key) + "/" + GetType());
                 *      answer.Add(Get(key));
                 *  }*/

                g.Reply(result);
            };
            g.Join();
            IsisSystem.WriteLine("Time elapsed is " + stopwatch.Elapsed);

            IsisSystem.WriteLine("Wait until database is full!");
            dbFull.WaitOne();
            IsisSystem.WriteLine("Database is fully populated!");
        }