Solve task 1.2 (maybe?)

This commit is contained in:
Oystein Kristoffer Tveit 2022-11-11 16:42:06 +01:00
parent cdc81b5dae
commit 9c93da087d
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 30 additions and 3 deletions

View File

@ -3,14 +3,41 @@ class Bank(val allowedAttempts: Integer = 3) {
private val transactionsQueue: TransactionQueue = new TransactionQueue()
private val processedTransactions: TransactionQueue = new TransactionQueue()
def addTransactionToQueue(from: Account, to: Account, amount: Double): Unit = ???
def addTransactionToQueue(from: Account, to: Account, amount: Double): Unit = {
transactionsQueue.push(new Transaction(
transactionsQueue,
processedTransactions,
from,
to,
amount,
10,
))
Main.thread(processTransaction(transactionsQueue.pop()))
}
// TODO
// project task 2
// create a new transaction object and put it in the queue
// spawn a thread that calls processTransactions
private def processTransactions: Unit = ???
// TOO
// There are mixed instructions for this method.
// It's called `processTransactions`, indicating that it should
// process all lists, the part in the assigment pdf indicates this as well.
// However the comment below is written as if there is only one transaction to
// be processed, and the fact that `addTransactionToQueue` calls this method every
// time something is added, supports that theory as well.
// We just went with the most logical option...
private def processTransactions(trx: Transaction): Unit = {
// thread = Main.thread(trx)
// thread.join()
trx()
if (trx.status == TransactionStatus.PENDING && trx.attempt < trx.allowedAttemps) {
processTransactions(trx)
} else {
processedTransactions.push(trx);
}
}
// TODO
// project task 2
// Function that pops a transaction from the queue
// and spawns a thread to execute the transaction.