Esempio n. 1
0
        public void ExecuteRead(ReadExecutor readExecutor)
        {
            Log.Debug($"Requesting Read({readExecutor.Tuple}) to Tuple Space.");
            TupleSpace.Tuple readTuple = this.replicaState.TupleSpace.Read(readExecutor.Tuple);

            // increment commit number
            int commitNumber = this.replicaState.IncrementCommitNumber();
            int viewNumber   = this.replicaState.ViewNumber;

            ClientResponse clientResponse;

            if (readTuple == null)
            {
                clientResponse = new ClientResponse(commitNumber, viewNumber, null);
            }
            else
            {
                clientResponse = new ClientResponse(commitNumber, viewNumber, readTuple.ToString());
            }
            // update client table
            lock (this.replicaState) {
                this.replicaState.ClientTable[readExecutor.ClientId] =
                    new Tuple <int, ClientResponse>(readExecutor.RequestNumber, clientResponse);
            }

            // Signal waiting thread that the execution is done
            readExecutor.Executed.Set();
            this.replicaState.HandlersCommits.Set();
            this.replicaState.HandlersCommits.Reset();

            // commit execution
            this.SendCommit(viewNumber, commitNumber);
        }
Esempio n. 2
0
        public void ExecuteRead(ReadExecutor readExecutor)
        {
            Log.Debug($"Requesting Read({readExecutor.Tuple}) to Tuple Space.");
            TupleSpace.Tuple readTuple = this.replicaState.TupleSpace.Read(readExecutor.Tuple);

            int viewNumber = this.replicaState.ViewNumber;

            string tuple = null;

            if (readTuple != null)
            {
                tuple = readTuple.ToString();
            }
            ClientResponse clientResponse = new ClientResponse(readExecutor.RequestNumber, viewNumber, tuple);

            // update client table
            this.UpdateClientTable(readExecutor, clientResponse);
            this.replicaState.IncrementCommitNumber();
        }
        /// <summary>
        /// Execute the read and seek loop for the track. </summary>
        /// <param name="readExecutor"> Callback for reading the track </param>
        /// <param name="seekExecutor"> Callback for performing a seek on the track, may be null on a non-seekable track </param>
        public virtual void executeProcessingLoop(ReadExecutor readExecutor, SeekExecutor seekExecutor)
        {
            bool proceed = true;

            checkPendingSeek(seekExecutor);

            while (proceed)
            {
                state.set(AudioTrackState.PLAYING);
                proceed = false;

                try
                {
                    // An interrupt may have been placed while we were handling the previous one.
                    if (java.lang.Thread.interrupted() && !handlePlaybackInterrupt(null, seekExecutor))
                    {
                        break;
                    }

                    InterruptibleForSeek = true;
                    readExecutor.performRead();
                    InterruptibleForSeek = false;

                    // Must not finish before terminator frame has been consumed the user may still want to perform seeks until then
                    waitOnEnd();
                }
                catch (System.Exception e)
                {
                    InterruptibleForSeek = false;
                    InterruptedException interruption = findInterrupt(e);

                    if (interruption != null)
                    {
                        proceed = handlePlaybackInterrupt(interruption, seekExecutor);
                    }
                    else
                    {
                        throw ExceptionTools.wrapUnfriendlyExceptions("Something went wrong when decoding the track.", FAULT, e);
                    }
                }
            }
        }