in tchannel-example/src/main/java/com/uber/tchannel/thrift/KeyValueClient.java [86:120]
public static String getValue(
SubChannel subChannel,
String key
) throws NotFoundError, ExecutionException, InterruptedException, TChannelError {
KeyValue.getValue_args getValue = new KeyValue.getValue_args(key);
TFuture<ThriftResponse<KeyValue.getValue_result>> future = subChannel
.send(
new ThriftRequest.Builder<KeyValue.getValue_args>("keyvalue-service", "KeyValue::getValue")
.setTimeout(1000)
.setBody(getValue)
.build(),
TChannelUtilities.getCurrentIp(),
8888
);
try (ThriftResponse<KeyValue.getValue_result> getResult = future.get()) {
if (getResult.isError()) {
System.out.println("getValue failed due to: " + getResult.getError().getMessage());
return null;
} else {
System.out.println("getValue succeeded");
}
String value = getResult.getBody(KeyValue.getValue_result.class).getSuccess();
NotFoundError err = getResult.getBody(KeyValue.getValue_result.class).getNotFound();
if (value == null) {
throw err;
}
return value;
}
}