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()); }
/// <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; }
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; }
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(); }
/// <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) { KLogging.LogException(ex); } try { transaction.Run(KmodTransactionReason.Error); } catch (Exception ex2) { KBase.HandleException(ex2, true); } } }
/// <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) { KBase.HandleException(ex, true); } m_wakeUpMsg = null; }
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(); } }
/// <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) KLogging.LogException(ex); try { transaction.Run(KmodTransactionReason.Error); } catch (Exception ex2) { KBase.HandleException(ex2, true); } } }
/// <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) { KBase.HandleException(ex, true); } m_wakeUpMsg = null; }
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(); }
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(); } }