Ejemplo n.º 1
0
 public K3pElement NextTransactionK3pElement(KmodTransaction transaction)
 {
     Debug.Assert(transaction == m_curTransaction);
     Debug.Assert(IsTransactionExecuting());
     Debug.Assert(IsThreadReadyForUserCommand());
     Debug.Assert(m_curCommand != null);
     Debug.Assert(m_curCommand.ResultReadyFlag);
     return(m_curThread.GetNextK3pElement());
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Set the current transaction status to finished, clear the current
        /// transaction and command.
        /// </summary>
        private void EndCurrentTransaction()
        {
            if (m_curTransaction != null)
            {
                m_curTransaction.Status = KmodTransactionStatus.Finished;
                m_curTransaction        = null;
            }

            m_curCommand = null;
        }
Ejemplo n.º 3
0
        public void PostTransactionCommand(KmodTransaction transaction, K3pMsg msg, bool haveResultFlag)
        {
            Debug.Assert(transaction == m_curTransaction);
            Debug.Assert(IsTransactionExecuting());
            Debug.Assert(IsThreadReadyForUserCommand());
            KmodThreadCommand cmd = new KmodThreadCommand(m_curThread, msg, haveResultFlag);

            m_curThread.PostToWorker(cmd);
            m_curCommand = haveResultFlag ? cmd : null;
        }
Ejemplo n.º 4
0
 public void SubmitTransaction(KmodTransaction transaction)
 {
     Debug.Assert(transaction.Status == KmodTransactionStatus.None);
     Debug.Assert(!m_transactionQueue.Contains(transaction));
     Debug.Assert(m_curTransaction != transaction);
     transaction.Status = KmodTransactionStatus.Queued;
     transaction.Broker = this;
     transaction.Ex     = null;
     m_transactionQueue.Add(transaction);
     RequestRun();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Stop the KMOD thread and kill all pending and executing
        /// transactions.
        /// </summary>
        private void Killall(Exception ex)
        {
            // Get the list of failing transactions and clear the current data
            // structures.
            List <KmodTransaction> list = new List <KmodTransaction>();

            list.AddRange(m_transactionQueue);
            m_transactionQueue.Clear();

            if (m_curTransaction != null)
            {
                list.Add(m_curTransaction);
                m_curTransaction = null;
            }

            // Mark the transactions as failing.
            foreach (KmodTransaction transaction in list)
            {
                transaction.Status = KmodTransactionStatus.Failing;
            }

            // Stop the thread if it is running.
            StopKmodThread();

            // Kill all transactions.
            foreach (KmodTransaction transaction in list)
            {
                if (transaction.Status != KmodTransactionStatus.Failing)
                {
                    continue;
                }
                transaction.Status = KmodTransactionStatus.Finished;
                transaction.Ex     = ex;
                if (ex != null)
                {
                    Logging.LogException(ex);
                }

                try
                {
                    transaction.Run(KmodTransactionReason.Error);
                }

                catch (Exception ex2)
                {
                    Base.HandleException(ex2, true);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Run the broker state machine. Only call RequestRun() to execute
        /// this method.
        /// </summary>
        public void Run()
        {
            Debug.Assert(m_wakeUpMsg != null);

            try
            {
                // Loop until our state stabilize.
                while (WantToRunNow())
                {
                    Debug.Assert(m_curTransaction == null);
                    Debug.Assert(m_curCommand == null);

                    // We're disabled. Kill all transactions.
                    if (!m_enabledFlag)
                    {
                        Killall(new Exception("KMOD broker disabled"));
                    }

                    // Execute the next transaction.
                    else
                    {
                        m_curTransaction = m_transactionQueue[0];
                        m_transactionQueue.RemoveAt(0);
                        Debug.Assert(m_curTransaction.Status == KmodTransactionStatus.Queued);
                        m_curTransaction.Status = KmodTransactionStatus.Executing;

                        // We have to start KMOD.
                        if (m_curThread == null)
                        {
                            StartKmodThread();
                        }

                        // Execute the current transaction.
                        else
                        {
                            StartCurrentTransaction();
                        }
                    }
                }
            }

            // We cannot recover from these errors.
            catch (Exception ex)
            {
                Base.HandleException(ex, true);
            }

            m_wakeUpMsg = null;
        }
Ejemplo n.º 7
0
        public void CancelTransaction(KmodTransaction transaction)
        {
            KmodTransactionStatus prevStatus = transaction.Status;

            transaction.Status = KmodTransactionStatus.Finished;
            transaction.Ex     = new Exception("transaction cancelled");

            // Cancel a queued transaction.
            if (prevStatus == KmodTransactionStatus.Queued)
            {
                m_transactionQueue.Remove(transaction);
            }

            // Cancel an executing transaction. We have to stop KMOD since the
            // transaction is under way.
            else if (prevStatus == KmodTransactionStatus.Executing)
            {
                Debug.Assert(transaction == m_curTransaction);
                EndCurrentTransaction();
                StopKmodThread();
                RequestRun();
            }
        }