List of usage examples for com.google.common.util.concurrent AbstractCheckedFuture AbstractCheckedFuture
protected AbstractCheckedFuture(ListenableFuture<V> delegate)
From source file:org.apache.drill.exec.rpc.user.UserClient.java
private CheckedFuture<Void, IOException> connect(final UserToBitHandshake handshake, final DrillbitEndpoint endpoint) { final SettableFuture<Void> connectionSettable = SettableFuture.create(); final CheckedFuture<Void, IOException> connectionFuture = new AbstractCheckedFuture<Void, IOException>( connectionSettable) {/* w ww . j a va2 s.c om*/ @Override protected IOException mapException(Exception e) { if (e instanceof SaslException) { return (SaslException) e; } else if (e instanceof ExecutionException) { final Throwable cause = Throwables.getRootCause(e); if (cause instanceof SaslException) { return (SaslException) cause; } } return RpcException.mapException(e); } }; final RpcConnectionHandler<UserToBitConnection> connectionHandler = new RpcConnectionHandler<UserToBitConnection>() { @Override public void connectionSucceeded(UserToBitConnection connection) { connectionSettable.set(null); } @Override public void connectionFailed(FailureType type, Throwable t) { // Don't wrap NonTransientRpcException inside RpcException, since called should not retry to connect in // this case if (t instanceof NonTransientRpcException || t instanceof SaslException) { connectionSettable.setException(t); } else if (t instanceof RpcException) { final Throwable cause = t.getCause(); if (cause instanceof SaslException) { connectionSettable.setException(cause); return; } connectionSettable.setException(t); } else { connectionSettable.setException( new RpcException(String.format("%s : %s", type.name(), t.getMessage()), t)); } } }; connectAsClient(queryResultHandler.getWrappedConnectionHandler(connectionHandler), handshake, endpoint.getAddress(), endpoint.getUserPort()); return connectionFuture; }