@Override public T call() throws IOException { return request.execute(); } }
@Override public T call() throws IOException { return request.execute(); } }
private static <T> T executeNullIfNotFound(AbstractGoogleClientRequest<T> request) throws IOException { try { return request.execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() == SC_NOT_FOUND) { return null; } else { throw e; } } } }
@VisibleForTesting static <T> T executeWithRetries( AbstractGoogleClientRequest<T> request, String errorMessage, Sleeper sleeper, BackOff backoff, SerializableFunction<IOException, Boolean> shouldRetry) throws IOException, InterruptedException { Exception lastException = null; do { try { return request.execute(); } catch (IOException e) { lastException = e; if (!shouldRetry.apply(e)) { break; } LOG.info("Ignore the error and retry the request.", e); } } while (nextBackOff(sleeper, backoff)); throw new IOException(errorMessage, lastException); }
@Override protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(method, properties); try { TypeConverter typeConverter = getEndpoint().getCamelContext().getTypeConverter(); for (Entry<String, Object> p : properties.entrySet()) { IntrospectionSupport.setProperty(typeConverter, request, p.getKey(), p.getValue()); } return request.execute(); } catch (Exception e) { throw new RuntimeCamelException(e); } }
@Override protected Object doInvokeMethod(Map<String, Object> properties) throws RuntimeCamelException { AbstractGoogleClientRequest request = (AbstractGoogleClientRequest) super.doInvokeMethod(properties); try { TypeConverter typeConverter = getEndpoint().getCamelContext().getTypeConverter(); for (Entry<String, Object> p : properties.entrySet()) { IntrospectionSupport.setProperty(typeConverter, request, p.getKey(), p.getValue()); } return request.execute(); } catch (Exception e) { throw new RuntimeCamelException(e); } }
@Override protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException { AbstractGoogleClientRequest<?> request = (AbstractGoogleClientRequest)super.doInvokeMethod(method, properties); try { TypeConverter typeConverter = getEndpoint().getCamelContext().getTypeConverter(); for (Entry<String, Object> p : properties.entrySet()) { IntrospectionSupport.setProperty(typeConverter, request, p.getKey(), p.getValue()); } return request.execute(); } catch (Exception e) { throw new RuntimeCamelException(e); } }
@Override protected Object doInvokeMethod(Map<String, Object> properties) throws RuntimeCamelException { AbstractGoogleClientRequest<?> request = (AbstractGoogleClientRequest) super.doInvokeMethod(properties); try { TypeConverter typeConverter = getEndpoint().getCamelContext().getTypeConverter(); for (Entry<String, Object> p : properties.entrySet()) { IntrospectionSupport.setProperty(typeConverter, request, p.getKey(), p.getValue()); } return request.execute(); } catch (Exception e) { throw new RuntimeCamelException(e); } } }
public static <T> T executeWithBackOff(AbstractGoogleClientRequest<T> client, String error) throws IOException, InterruptedException { Sleeper sleeper = Sleeper.DEFAULT; BackOff backOff = BackOffAdapter.toGcpBackOff( FluentBackoff.DEFAULT .withMaxRetries(MAX_RETRIES).withInitialBackoff(INITIAL_BACKOFF_TIME).backoff()); T result = null; while (true) { try { result = client.execute(); break; } catch (IOException e) { LOG.error("{}", error, e); if (!BackOffUtils.next(sleeper, backOff)) { String errorMessage = String.format( "%s Failing to execute job after %d attempts.", error, MAX_RETRIES + 1); LOG.error("{}", errorMessage, e); throw new IOException(errorMessage, e); } } } return result; }