+ /**
+ *
+ * @return the log entry index for the given index or -1 if not found
+ */
+ protected long getLogEntryIndex(long index){
+ if(index == context.getReplicatedLog().getSnapshotIndex()){
+ return context.getReplicatedLog().getSnapshotIndex();
+ }
+
+ ReplicatedLogEntry entry = context.getReplicatedLog().get(index);
+ if(entry != null){
+ return entry.getIndex();
+ }
+
+ return -1;
+ }
+
+ /**
+ * @return the log entry term for the given index or -1 if not found
+ */
+ protected long getLogEntryTerm(long index){
+ if(index == context.getReplicatedLog().getSnapshotIndex()){
+ return context.getReplicatedLog().getSnapshotTerm();
+ }
+
+ ReplicatedLogEntry entry = context.getReplicatedLog().get(index);
+ if(entry != null){
+ return entry.getTerm();
+ }
+
+ return -1;
+ }
+
+ /**
+ * Apply the provided index to the state machine
+ *
+ * @param index a log index that is known to be committed
+ */
+ protected void applyLogToStateMachine(final long index) {
+ long newLastApplied = context.getLastApplied();