public void Write(DomainObject o, List <string> replicas)
        {
            Entity ent = new QuorunRead().Read(o.ID, replicas);

            if (ent == null)
            {
                ent       = new Entity();
                ent.Value = o;
            }
            else
            {
                ent.Timestamp++;
                ent.Value = o;
            }

            List <Thread> callers  = new List <Thread>();
            int           majority = (int)(Config.Instance.NumberOfReplicas / 2.0);

            foreach (string addr in replicas)
            {
                ThreadedWrite tw     = new ThreadedWrite(ent, addr, this);
                Thread        thread = new Thread(tw.RemoteWrite);
                callers.Add(thread);
                thread.Start();
            }

            lock (this)
            {
                while (countSuccessfulWrites < majority && countAnswers < callers.Count)
                {
                    Monitor.Wait(this);
                }
            }

            foreach (Thread t in callers)
            {
                if (t.IsAlive)
                {
                    t.Abort();
                }
            }

            if (countSuccessfulWrites < majority)
            {
                throw new ServiceUnavailableException("Could not write to a majority");
            }

            ServerManager.Instance.ServerInstance.SimpleWriteEntity(ent);
        }
        public void Write(DomainObject o, List<string> replicas)
        {
            Entity ent = new QuorunRead().Read(o.ID, replicas);
            if (ent == null)
            {
                ent = new Entity();
                ent.Value = o;
            }
            else
            {
                ent.Timestamp++;
                ent.Value = o;
            }

            List<Thread> callers = new List<Thread>();
            int majority = (int)(Config.Instance.NumberOfReplicas / 2.0);

            foreach (string addr in replicas)
            {
                ThreadedWrite tw = new ThreadedWrite(ent, addr, this);
                Thread thread = new Thread(tw.RemoteWrite);
                callers.Add(thread);
                thread.Start();
            }

            lock (this)
            {
                while (countSuccessfulWrites < majority && countAnswers < callers.Count)
                    Monitor.Wait(this);
            }

            foreach (Thread t in callers)
                if (t.IsAlive)
                    t.Abort();

            if (countSuccessfulWrites < majority)
                throw new ServiceUnavailableException("Could not write to a majority");

            ServerManager.Instance.ServerInstance.SimpleWriteEntity(ent);
        }
 public ThreadedRead(string entityID, string address, QuorunRead quorunRead)
 {
     this.entityID = entityID;
     this.address = address;
     this.quorunRead = quorunRead;
 }
 public ThreadedRead(string entityID, string address, QuorunRead quorunRead)
 {
     this.entityID   = entityID;
     this.address    = address;
     this.quorunRead = quorunRead;
 }
示例#5
0
 public DomainObject ReadDomainObject(string id)
 {
     Entity e = new QuorunRead().Read(id, replicas);
     if (e != null)
         return e.Value;
     return null;
 }