+ /**
+ * schedule a new election
+ *
+ * @param interval
+ */
+ protected void scheduleElection(FiniteDuration interval) {
+ stopElection();
+
+ // Schedule an election. When the scheduler triggers an ElectionTimeout
+ // message is sent to itself
+ electionCancel =
+ context.getActorSystem().scheduler().scheduleOnce(interval,
+ context.getActor(), new ElectionTimeout(),
+ context.getActorSystem().dispatcher(), context.getActor());
+ }
+
+ /**
+ * Get the current term
+ * @return
+ */
+ protected long currentTerm() {
+ return context.getTermInformation().getCurrentTerm();
+ }
+
+ /**
+ * Get the candidate for whom we voted in the current term
+ * @return
+ */
+ protected String votedFor() {
+ return context.getTermInformation().getVotedFor();
+ }
+
+ /**
+ * Get the actor associated with this behavior
+ * @return
+ */
+ protected ActorRef actor() {
+ return context.getActor();
+ }
+
+ /**
+ * Get the term from the last entry in the log
+ *
+ * @return
+ */
+ protected long lastTerm() {
+ return context.getReplicatedLog().lastTerm();
+ }
+
+ /**
+ * Get the index from the last entry in the log
+ *
+ * @return
+ */
+ protected long lastIndex() {
+ return context.getReplicatedLog().lastIndex();
+ }
+
+ /**
+ * Find the client request tracker for a specific logIndex
+ *
+ * @param logIndex
+ * @return
+ */
+ protected ClientRequestTracker findClientRequestTracker(long logIndex) {
+ return null;
+ }
+
+ /**
+ * Find the client request tracker for a specific logIndex
+ *
+ * @param logIndex
+ * @return
+ */
+ protected ClientRequestTracker removeClientRequestTracker(long logIndex) {
+ return null;
+ }
+
+
+ /**
+ * Find the log index from the previous to last entry in the log
+ *
+ * @return
+ */
+ protected long prevLogIndex(long index){
+ ReplicatedLogEntry prevEntry =
+ context.getReplicatedLog().get(index - 1);
+ if (prevEntry != null) {
+ return prevEntry.getIndex();