Tag: 番石榴的

如何正确处理来自ListenableFuture番石榴的exception?

我有一个库,我已经为我们的客户提供了两种方法,sync和async。 他们可以调用他们认为适合他们目的的任何方法。 executeSynchronous() – 等到我有结果,返回结果。 executeAsynchronous() – 立即返回一个Future,如果需要,可以在其他事情完成后处理。 它们将传递具有用户标识的DataKey对象。 我们将根据用户ID确定调用哪台机器。 因此,我们将使用AsyncRestTemplate对URL进行http调用,然后根据它是否成功将响应发送给它们。 以下是我的界面: public interface Client { // for synchronous public DataResponse executeSync(final DataKey key); // for asynchronous public Future executeAsync(final DataKey key); } 以下是我的实施: public class DataClient implements IClient { // does this have to be final? private final AsyncRestTemplate restTemplate = new AsyncRestTemplate(); @Override […]