Exemplo n.º 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);
        }
Exemplo n.º 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);
        }