use of org.apache.ratis.proto.RaftProtos.RaftPeerRole in project incubator-ratis by apache.
the class ArithmeticStateMachine method applyTransaction.
@Override
public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
final LogEntryProto entry = trx.getLogEntry();
final AssignmentMessage assignment = new AssignmentMessage(entry.getStateMachineLogEntry().getLogData());
final long index = entry.getIndex();
final Double result;
try (AutoCloseableLock writeLock = writeLock()) {
result = assignment.evaluate(variables);
updateLastAppliedTermIndex(entry.getTerm(), index);
}
final Expression r = Expression.Utils.double2Expression(result);
final CompletableFuture<Message> f = CompletableFuture.completedFuture(Expression.Utils.toMessage(r));
final RaftPeerRole role = trx.getServerRole();
if (role == RaftPeerRole.LEADER) {
LOG.info("{}:{}-{}: {} = {}", role, getId(), index, assignment, r);
} else {
LOG.debug("{}:{}-{}: {} = {}", role, getId(), index, assignment, r);
}
if (LOG.isTraceEnabled()) {
LOG.trace("{}-{}: variables={}", getId(), index, variables);
}
return f;
}
Aggregations