use of org.apache.ratis.examples.arithmetic.expression.Expression in project incubator-ratis by apache.
the class ArithmeticStateMachine method query.
@Override
public CompletableFuture<Message> query(Message request) {
final Expression q = Expression.Utils.bytes2Expression(request.getContent().toByteArray(), 0);
final Double result;
try (AutoCloseableLock readLock = readLock()) {
result = q.evaluate(variables);
}
final Expression r = Expression.Utils.double2Expression(result);
LOG.debug("QUERY: {} = {}", q, r);
return CompletableFuture.completedFuture(Expression.Utils.toMessage(r));
}
use of org.apache.ratis.examples.arithmetic.expression.Expression in project incubator-ratis by apache.
the class Get method operation.
@Override
protected void operation(RaftClient client) throws IOException {
RaftClientReply getValue = client.io().sendReadOnly(Expression.Utils.toMessage(new Variable(name)));
Expression response = Expression.Utils.bytes2Expression(getValue.getMessage().getContent().toByteArray(), 0);
System.out.println(String.format("%s=%s", name, (DoubleValue) response).toString());
}
Aggregations