Beispiel #1
0
 /// <summary>
 /// Increases each value in the time stamp to the larger of either
 /// the current value or the corresponding value in the specified
 /// time stamp.
 /// </summary>
 /// <param name="other">Time Stamp to compare to.</param>
 public void max(TransportableVectorTimeStamp other)
 {
     for (int i = 0; i < members.Count; i++)
     {
         members.SetByIndex(i, Math.Max((int)members.GetByIndex(i), other.MessagesSent[i]));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Calculates if the value is causally next to the current value.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="diag"></param>
        /// <returns></returns>
        public bool causallyNext(TransportableVectorTimeStamp other, out string diag)
        {
            diag = "";
            if (other == null)
            {
                return(false);
            }
            int senderIndex   = other.SenderPosition;
            int receiverIndex = ownerIndex;

            int[] sender   = other.MessagesSent;
            int[] receiver = getValues();

            bool nextCasualFromSender = false;
            bool nextCasual           = true;

            diag  = "Sender = " + senderIndex + "	Receiver = "+ receiverIndex;
            diag += "	[";
            foreach (int i in sender)
            {
                diag += i + ",";
            }
            diag += "]	[";
            foreach (int j in receiver)
            {
                diag += j + ",";
            }
            diag += "]\n";

            if (receiverIndex == senderIndex)
            {
                return(true);
            }

            for (int k = 0; k < receiver.Length; k++)
            {
                if ((k == senderIndex) && (sender[k] == receiver[k] + 1))
                {
                    nextCasualFromSender = true;
                    continue;
                }
                if (k == receiverIndex)
                {
                    continue;
                }
                if (sender[k] > receiver[k])
                {
                    nextCasual = false;
                }
            }
            return(nextCasualFromSender && nextCasual);
        }
Beispiel #3
0
        private void addToQueue(TransportableVectorTimeStamp vts)
        {
            int i;

            for (i = 0; i < delayQueue.Count; i++)
            {
                if (!((TransportableVectorTimeStamp)delayQueue[i]).lessThanOrEquals(vts))
                {
                    break;
                }
            }
            delayQueue.Insert(i, vts);
        }
        /// <summary>
        /// A vector time stamp, A, is lequal to another vector time stamp, B,
        /// if each element in A is equal to the corresponding element in B.
        /// </summary>
        /// <param name="vStamp2"></param>
        /// <returns></returns>
        public bool equals(TransportableVectorTimeStamp vStamp2)
        {
            bool equal = true;

            for (int i = 0; i < messagesSent.Length; i++)
            {
                if (vStamp2.MessagesSent[i] != messagesSent[i])
                {
                    equal = false;
                    break;
                }
            }
            return(equal);
        }
        /// <summary>
        /// A vector time stamp, A, is less than or equal to another vector time stamp, B,
        /// if each element in A is less than or equal to the corresponding element in B.
        /// </summary>
        /// <param name="vStamp2">The vector time stamp to compare to</param>
        /// <returns>True if the specified arguement is greater than the object</returns>
        public bool lessThanOrEquals(TransportableVectorTimeStamp vStamp2)
        {
            bool lessThanOrEqual = true;

            for (int i = 0; i < messagesSent.Length; i++)
            {
                if (messagesSent[i] > vStamp2.MessagesSent[i])
                {
                    lessThanOrEqual = false;
                    break;
                }
            }
            return(lessThanOrEqual);
        }
        /// <summary>
        /// Calculates if the value is causally next to the current value.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="diag"></param>
        /// <returns></returns>
        public bool causallyNext(TransportableVectorTimeStamp other, out string diag)
        {
            diag = "";
            if(other==null)
                return false;
            int senderIndex = other.SenderPosition;
            int receiverIndex = ownerIndex;

            int[] sender = other.MessagesSent;
            int[] receiver = getValues();

            bool nextCasualFromSender = false;
            bool nextCasual = true;

            diag = "Sender = " + senderIndex + "	Receiver = " + receiverIndex;
            diag += "	[";
            foreach(int i in sender)
                diag +=i + ",";
            diag +="]	[";
            foreach(int j in receiver)
                diag +=j + ",";
            diag += "]\n";

            if (receiverIndex == senderIndex)
                return true;

            for (int k = 0; k < receiver.Length; k++)
            {
                if ((k == senderIndex) && (sender[k] == receiver[k] + 1))
                {
                    nextCasualFromSender = true;
                    continue;
                }
                if (k == receiverIndex)
                    continue;
                if (sender[k] > receiver[k])
                    nextCasual = false;
            }
            return (nextCasualFromSender && nextCasual);
        }
Beispiel #7
0
 private void addToQueue(TransportableVectorTimeStamp vts)
 {
     int i;
     for(i = 0; i< delayQueue.Count ;i++)
     {
         if(!((TransportableVectorTimeStamp)delayQueue[i]).lessThanOrEquals(vts))
             break;
     }
     delayQueue.Insert(i,vts);
 }
 /// <summary>
 /// Increases each value in the time stamp to the larger of either
 /// the current value or the corresponding value in the specified 
 /// time stamp.
 /// </summary>
 /// <param name="other">Time Stamp to compare to.</param>
 public void max(TransportableVectorTimeStamp other)
 {
     for(int i = 0;i<members.Count;i++)
         members.SetByIndex(i,Math.Max((int)members.GetByIndex(i),other.MessagesSent[i]));
 }
Beispiel #9
0
 /// <summary>
 /// Constructor: Deserialises the information and recreates the instance.
 /// </summary>
 /// <param name="info">Standard <c>SerializationInfo</c> object</param>
 /// <param name="ctxt">Standard <c>StreamingContext</c> object</param>
 public CausalHeader(SerializationInfo info, StreamingContext ctxt)
 {
     vStamp = (TransportableVectorTimeStamp)info.GetValue("vStamp", typeof(object));
 }
Beispiel #10
0
 /// <summary>Constructor</summary>
 /// <param name="vStamp">Vector time stamp</param>
 public CausalHeader(TransportableVectorTimeStamp vStamp)
 {
     this.vStamp = vStamp;
 }
Beispiel #11
0
 /// <summary>
 /// Constructor: Deserialises the information and recreates the instance.
 /// </summary>
 /// <param name="info">Standard <c>SerializationInfo</c> object</param>
 /// <param name="ctxt">Standard <c>StreamingContext</c> object</param>
 public CausalHeader(SerializationInfo info, StreamingContext ctxt)
 {
     vStamp = (TransportableVectorTimeStamp)info.GetValue("vStamp",typeof(object));
 }
Beispiel #12
0
 /// <summary>Constructor</summary>
 /// <param name="vStamp">Vector time stamp</param>
 public CausalHeader(TransportableVectorTimeStamp vStamp)
 {
     this.vStamp = vStamp;
 }
 /// <summary>
 /// A vector time stamp, A, is lequal to another vector time stamp, B,
 /// if each element in A is equal to the corresponding element in B.
 /// </summary>
 /// <param name="vStamp2"></param>
 /// <returns></returns>
 public bool equals(TransportableVectorTimeStamp vStamp2)
 {
     bool equal = true;
     for(int i =0; i< messagesSent.Length;i++)
     {
         if(vStamp2.MessagesSent[i]!=messagesSent[i])
         {
             equal=false;
             break;
         }
     }
     return equal;
 }
 /// <summary>
 /// A vector time stamp, A, is less than or equal to another vector time stamp, B,
 /// if each element in A is less than or equal to the corresponding element in B.
 /// </summary>
 /// <param name="vStamp2">The vector time stamp to compare to</param>
 /// <returns>True if the specified arguement is greater than the object</returns>
 public bool lessThanOrEquals(TransportableVectorTimeStamp vStamp2)
 {
     bool lessThanOrEqual = true;
     for(int i =0; i < messagesSent.Length;i++)
     {
         if(messagesSent[i] > vStamp2.MessagesSent[i])
         {
             lessThanOrEqual=false;
             break;
         }
     }
     return lessThanOrEqual;
 }
Beispiel #15
0
        /// <summary>
        /// Processes <c>Events</c> traveling up the stack
        /// </summary>
        /// <param name="evt">The Event to be processed</param>
        public override void up(Event evt)
        {
            switch (evt.Type)
            {
            case Event.SET_LOCAL_ADDRESS:
                localAddress = (Address)evt.Arg;
                localStamp   = new VectorTimeStamp(localAddress);
                delayQueue   = new ArrayList();
                break;

            case Event.VIEW_CHANGE:
                ArrayList newViewMembers = ((View)evt.Arg).getMembers();
                localStamp.merge((ArrayList)newViewMembers.Clone());
                localStamp.reset();
                break;

            case Event.MSG:
                Message msg = (Message)evt.Arg;
                Header  hdr = msg.getHeader(getName());

                //Check that the correct header is available
                if (hdr == null || !(hdr is CausalHeader))
                {
                    if (Trace.trace)
                    {
                        Trace.error("Causal.up()", "No Causal Header Found!");
                    }
                    passUp(evt);
                    return;
                }

                CausalHeader cHdr = (CausalHeader)hdr;

                //Pass message up if it is causually next
                String diag = "";
                bool   next = localStamp.causallyNext(cHdr.VectorTime, out diag);
                //passUp(new Event(Event.MSG, new Message(null,localAddress,diag)));
                if (Trace.trace)
                {
                    Trace.info("CAUSAL.up()", diag + "Causally Next = " + next);
                }
                if (next)
                {
                    if (Trace.trace)
                    {
                        Trace.info("CAUSAL.up()", "Message received in sequence.");
                    }
                    passUp(evt);
                    localStamp.max(cHdr.VectorTime);
                }
                else                         //Else add to the delayed queue
                {
                    if (Trace.trace)
                    {
                        Trace.warn("CAUSAL.up()", "Message received out of sequence.");
                    }
                    cHdr.VectorTime.AssosicatedMessage = msg;
                    addToQueue(cHdr.VectorTime);
                }
                //Check the delayed queue removing all items that can be passed up
                TransportableVectorTimeStamp queuedVector = null;
                while ((delayQueue.Count > 0) &&
                       localStamp.causallyNext((queuedVector = (TransportableVectorTimeStamp)delayQueue[0]), out diag))
                {
                    delayQueue.Remove(queuedVector);
                    passUp(new Event(Event.MSG, queuedVector.AssosicatedMessage));
                    localStamp.max(queuedVector);
                }
                return;
            }
            passUp(evt);
        }