コード例 #1
0
        /**
         * Remove locked tuples from LockedTuples List, and add them back to the tuple space
         * acts as a release for the "lock" of a take request
         */
        private void ReleaseLockedTuples(int takeRequestSeqNum)
        {
            // remove from LockedTuples
            bool isRemoved = LockedTuples.TryRemove(takeRequestSeqNum, out List <Tuple> tuples);

            // add back to TupleSpace
            if (isRemoved)
            {
                foreach (Tuple tuple in tuples)
                {
                    TupleSpace.Write(tuple);
                }
            }
        }
コード例 #2
0
        /**
         * Remove the selected tuple and add the remaining locked tuples back to the tuplespace
         */
        private Message ProcessTakeRemove(Message message)
        {
            TakeRemove takeRemove = (TakeRemove)message;

            LockedTuples.TryRemove(takeRemove.TakeRequestSeqNumber, out List <Tuple> lockedTuples);

            // remove the selected tuple specified in the request
            if (lockedTuples != null && takeRemove.SelectedTuple != null)
            {
                lockedTuples.Remove(takeRemove.SelectedTuple);

                // add back the remaining tuples to the tuple space
                foreach (Tuple tuple in lockedTuples)
                {
                    TupleSpace.Write(tuple);
                }
            }

            // Send back an Ack of the remove
            Ack ack = new Ack(EndpointURL, takeRemove);

            SendMessageToRemoteURL(takeRemove.SrcRemoteURL, ack);
            return(ack);
        }
コード例 #3
0
 private void Write(Tuple tuple)
 {
     TupleSpace.Write(tuple);
     Log("Wrote : " + tuple);
 }
コード例 #4
0
        public Message ProcessRequest(Request request)
        {
            var tupleSchema = new TupleSchema(request.Tuple);

            if (request.GetType() == typeof(WriteRequest))
            {
                TupleSpace.Write(request.Tuple);

                // notify a blocked thread that tried to read/take this tuple before
                Request readOrTakeRequest = GetAndRemoveSinglePendingRequest(request.Tuple);
                if (readOrTakeRequest != null)
                {
                    PulseMessage(readOrTakeRequest);
                }

                // Send back an Ack of the write
                return(new Ack(EndpointURL, request));
            }

            if (request.GetType() == typeof(ReadRequest))
            {
                List <Tuple> tuples = TupleSpace.Read(tupleSchema);

                while (!tuples.Any())
                {
                    lock (PendingRequestList){
                        PendingRequestList.Add(request);
                    }
                    WaitMessage(request, View.Nodes);
                    tuples = TupleSpace.Read(tupleSchema);
                }

                Response response = new Response(request, tuples, EndpointURL);
                return(response);
            }

            if (request.GetType() == typeof(TakeRequest))
            {
                tupleSchema = new TupleSchema(request.Tuple);
                List <Tuple> resultTuples = TupleSpace.Take(tupleSchema);
                Response     response     = null;

                while (!resultTuples.Any())
                {
                    lock (PendingRequestList){
                        PendingRequestList.Add(request);
                    }
                    WaitMessage(request, View.Nodes);
                    resultTuples = TupleSpace.Take(tupleSchema);
                }

                // "lock" the tuples taken from the tuple space
                LockedTuples.TryAdd(request.SeqNum, resultTuples);
                response = new Response(request, resultTuples, EndpointURL);
                SendMessageToRemoteURL(request.SrcRemoteURL, response);

                return(response);
            }

            throw new NotImplementedException();
        }
コード例 #5
0
 public void Write1(Tuple tuple)
 {
     _tupleSpace.Write(tuple);
 }