Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
giannislelekas committed Mar 18, 2019
1 parent 3223484 commit cd1a8cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 82 deletions.
11 changes: 0 additions & 11 deletions src/main/scala/rover/rdo/AtomicObjectState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@ import rover.rdo.client.{Log, LogRecord}

// TODO: make ctor private
class AtomicObjectState[A](private val value: A, private[rdo] val log: Log[A]) extends ObjectState {

type Op = A => A

// Initialization of the record with the current state and empyt list of ops

// FIXME: if we start with some initial first state, the log is empty, need to add "initial value op" or something
// private val log: Log[A] = new Log[A]()

def immutableState: A = value

// The -1 corresponds to the initial state where no operation is yet applied
// def numOperations: Long = this.record.recordSize() - 1

// def getImmutableStates: List[A] = this.record.getImmutableStates

def applyOp(operation: Op): AtomicObjectState[A] = {
// Operation must apply itself to the state
// but we want the state to take in the operations
Expand Down
75 changes: 4 additions & 71 deletions src/main/scala/rover/rdo/client/RdObject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,7 @@ import rover.rdo.AtomicObjectState
//FIXME: use hashes instead of Longs/Strings?
class RdObject[A](var state: AtomicObjectState[A]) {

// var state: AtomicObjectState[A] = null

// def this(state: AtomicObjectState[A]) = {
// this()
// this.state = state
// }

/**
* The current version of the RDO instance, if current == stable
* then the RDO does not contain any unsaved state changes
* @return The current version of the RDO state
*/
// def currentVersion: Long = {
// return state.numOperations
// }

//FIXME: this is a crude method of ectractingthe version; we need a better method
//two states are equivalent here if merely the same amount of operations are performed
// def currentVersion(cstate: AtomicObjectState[A]): Long = {
// return cstate.numOperations
// }

/**
* The persisted (on master) version this RDO instance was based on
* initially.
* @return Version of persisted RDO state the instance has started with
*/
// def stableVersion: Long = {
// // TODO: determine from state
// null
// }


// def getImmutableStates: List[A] = state.getImmutableStates

// TODO: "is up to date" or "version" methods

protected final def modifyState(op: AtomicObjectState[A]#Op): Unit = {
state = state.applyOp(op)
Expand Down Expand Up @@ -68,12 +34,9 @@ class CommonAncestor[A](private val one: RdObject[A], private val other: RdObjec
def commonAncestor: RdObject[A] = {
// determine here... & probably cache or is that not needed in scala? :S
// FIXME: currently we return just the atomic state..what about the outstanding operations?
// can there be a fork in the history of the provided RDOs?
// since client RDOs apply tentative updates there shouldn't be any, apart from the common ancestor
// FIXME: might need to keep track of history from the last stable point
for (i <- one.state.log.asList.reverse) {
for (j <- other.state.log.asList.reverse) {
// if (currentVersion(new AtomicObjectState[A](i)) == currentVersion(new AtomicObjectState[A](j))) {

println()
println("I:" + i)
println("J:" + j)
Expand All @@ -87,41 +50,11 @@ class CommonAncestor[A](private val one: RdObject[A], private val other: RdObjec
}
}
}
throw new RuntimeException("HENK IS DEAD")
// return new RdObject[A]()
// FIXME: typed exception, better error logs
throw new RuntimeException("Failed to determine a common ancestor")
}

override def toString: String = {
commonAncestor.state.toString
}


// override def currentVersion: Long = {
// commonAncestor.currentVersion
// }
//
// override def stableVersion: Long = {
// commonAncestor.stableVersion
// }
//
// // FIXME: determine what to do with this, fix return value/type
// def hasDiverged: Long = {
// // FIXME: non-logical result
// if (this.currentVersion != other.currentVersion){
// commonAncestor.currentVersion
// }
// else{
// println("Non-divergent objects")
// this.currentVersion
// }
// }
}

class updateRDO(){
//TODO: apply tentative updates to RDO

}

class revertRDO(){
//TOD: also revert changes
}

0 comments on commit cd1a8cf

Please sign in to comment.