use of com.alipay.sofa.jraft.test.atomic.command.GetCommand in project sofa-jraft by sofastack.
the class AtomicClient method get.
public long get(PeerId peer, String key, boolean readFromQuorum, boolean readByStateMachine) throws KeyNotFoundException, InterruptedException {
try {
final GetCommand request = new GetCommand(key);
request.setReadFromQuorum(readFromQuorum);
request.setReadByStateMachine(readByStateMachine);
final Object response = this.rpcClient.invokeSync(peer.getEndpoint(), request, cliOptions.getRpcDefaultTimeout());
final BooleanCommand cmd = (BooleanCommand) response;
if (cmd.isSuccess()) {
return ((ValueCommand) cmd).getVlaue();
} else {
if (cmd.getErrorMsg().equals("key not found")) {
throw new KeyNotFoundException();
} else {
throw new IllegalStateException("Server error:" + cmd.getErrorMsg());
}
}
} catch (final Throwable t) {
t.printStackTrace();
throw new IllegalStateException("Remoting error:" + t.getMessage());
}
}
Aggregations