public static JepsenLockClient<LockRefreshToken> create(MetricRegistry metricRegistry, List<String> hosts) { return new SynchronousLockClient(TimelockUtils.createClient(metricRegistry, hosts, LockService.class)); }
public static AsyncLockClient create(MetricRegistry metricRegistry, List<String> hosts) { return new AsyncLockClient(TimelockUtils.createClient(metricRegistry, hosts, TimelockService.class)); }
/** * Returns a Feign {@link Client} wrapping an {@link okhttp3.OkHttpClient}. This {@link Client} recreates * itself in the event that either {@link CounterBackedRefreshingClient#DEFAULT_REQUEST_COUNT_BEFORE_REFRESH} * requests have been made, or if {@link ExceptionCountingRefreshingClient#DEFAULT_EXCEPTION_COUNT_BEFORE_REFRESH} * consecutive exceptions have been thrown by the underlying client. */ public static Client newRefreshingOkHttpClient( Optional<TrustContext> trustContext, Optional<ProxySelector> proxySelector, String userAgent) { Supplier<Client> clientSupplier = () -> CounterBackedRefreshingClient.createRefreshingClient( () -> newOkHttpClient(trustContext, proxySelector, userAgent)); return ExceptionCountingRefreshingClient.createRefreshingClient(clientSupplier); }
private boolean shouldSwitchNode(ExceptionRetryBehaviour retryBehaviour, long failures) { return retryBehaviour.shouldBackoffAndTryOtherNodes() || (!retryBehaviour.shouldRetryInfinitelyManyTimes() && failures >= failuresBeforeSwitching); }
private static Response.ResponseBuilder encode503ResponseInternal(Exception exception) { return encodeExceptionResponse(exception, 503); }
@Test public void refreshableIsInitializedWithTheSupplierValue() { PollingRefreshable<Long> pollingRefreshable = createPollingRefreshableWithTestScheduler(() -> 1L); assertRefreshableContainsAndClear(pollingRefreshable.getRefreshable(), 1L); }
private void registerExceptionMappers() { registrar.accept(new BlockingTimeoutExceptionMapper()); registrar.accept(new NotCurrentLeaderExceptionMapper()); registrar.accept(new TooManyRequestsExceptionMapper()); }
public static Client createRefreshingClient(Supplier<Client> baseClientSupplier) { return new ExceptionCountingRefreshingClient(baseClientSupplier, DEFAULT_EXCEPTION_COUNT_BEFORE_REFRESH); }
public static <T> PollingRefreshable<T> create(Supplier<T> supplier) { return create(supplier, DEFAULT_REFRESH_INTERVAL); }
private void simulateRequest(FailoverFeignTarget target) { // This method is called as a part of a request being invoked. // We need to update the mostRecentServerIndex, for the FailoverFeignTarget to track failures properly. target.url(); }
private <T> PollingRefreshable<T> createPollingRefreshableWithTestScheduler(Supplier<T> supplier) { return PollingRefreshable.createWithSpecificPoller(supplier, REFRESH_INTERVAL, scheduler); }
@Override public Response toResponse(NotInitializedException exception) { return ExceptionMappers.encode503ResponseWithoutRetryAfter(exception); } }
/** * Returns a 503 response, with body corresponding to the serialized exception. */ @Override public Response toResponse(NotCurrentLeaderException exception) { return ExceptionMappers.encode503ResponseWithRetryAfter(exception); } }
@SuppressWarnings({"checkstyle:NoClone", "checkstyle:SuperClone"}) @Override public Retryer clone() { return new InterruptHonoringRetryer(); } }
public static <T> T createClient(MetricRegistry metricRegistry, List<String> hosts, Class<T> type) { List<String> endpointUris = hostnamesToEndpointUris(hosts); return createFromUris(metricRegistry, endpointUris, type); }
@Override public Set<String> refresh(Set<String> strings) throws InterruptedException { return delegate.refresh(strings); } }
@Override public Set<String> unlock(Set<String> strings) throws InterruptedException { return delegate.unlock(strings); }
public static TimestampService create(MetricRegistry metricRegistry, List<String> hosts) { return TimelockUtils.createClient(metricRegistry, hosts, TimestampService.class); } }
@Override public String lock(String client, String lockName) throws InterruptedException { return delegate.lock(client, lockName); }
@Override public Response toResponse(BlockingTimeoutException exception) { return ExceptionMappers.encode503ResponseWithoutRetryAfter(exception); } }