-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StateMachine in charge of lastAppliedIndex persistence
- Loading branch information
1 parent
8556ae3
commit 8f790d0
Showing
8 changed files
with
130 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package ckite.statemachine | ||
|
||
import ckite.rpc.Command | ||
import ckite.rpc.WriteCommand | ||
import ckite.rpc.ReadCommand | ||
|
||
class CommandExecutor(stateMachine: StateMachine) { | ||
|
||
val applyPartialFunction = stateMachine.apply | ||
|
||
def apply(command: Command): Any = { | ||
if (applyPartialFunction.isDefinedAt(command)) applyPartialFunction(command) | ||
else throw new UnsupportedOperationException("No command handler in StateMachine") | ||
|
||
val writeFunction = stateMachine.applyWrite | ||
val readFunction = stateMachine.applyRead | ||
|
||
def applyWrite(index: Long, write: WriteCommand): Any = { | ||
val params = (index, write) | ||
if (writeFunction.isDefinedAt(params)) writeFunction(params) | ||
} | ||
|
||
def applyRead(read: ReadCommand): Any = { | ||
if (readFunction.isDefinedAt(read)) readFunction(read) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters