Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public ThreadedRead(string entityID, string address, QuorunRead quorunRead)
 {
     this.entityID = entityID;
     this.address = address;
     this.quorunRead = quorunRead;
 }
Пример #4
0
 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;
 }