Optimistic locking option
This commit is contained in:
33
src/main/kotlin/nl/astraeus/persistence/TransactionLog.kt
Normal file
33
src/main/kotlin/nl/astraeus/persistence/TransactionLog.kt
Normal file
@@ -0,0 +1,33 @@
|
||||
package nl.astraeus.nl.astraeus.persistence
|
||||
|
||||
import java.io.File
|
||||
import java.io.ObjectInputStream
|
||||
|
||||
class TransactionLog(
|
||||
val directory: File,
|
||||
) {
|
||||
val fileManager = FileManager(directory)
|
||||
|
||||
fun showTransactions() {
|
||||
fileManager.findLastSnapshot().let { (after, snapshot) ->
|
||||
println("Last snapshot: $snapshot")
|
||||
|
||||
val transactions = fileManager.findTransactionsAfter(after ?: 0L)
|
||||
|
||||
println("Transactions:")
|
||||
transactions?.forEach { transaction ->
|
||||
transaction.inputStream().use { input ->
|
||||
ObjectInputStream(input).use { ois ->
|
||||
val versionNumber = ois.readInt()
|
||||
check(versionNumber == 1) { "Unsupported version number: $versionNumber" }
|
||||
val transactionNumber = ois.readLong()
|
||||
val actions = ois.readObject() as Set<Action>
|
||||
println("[$versionNumber] $transactionNumber - ${actions.joinToString(",")}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user