@Override public R call() throws Exception { return _pool.execute(retryPolicy, callback); } });
@Override public int getNumBadEndPoints() { return _pool.getNumBadEndPoints(); } }
@Override public Integer getValue() { return getNumValidEndPoints(); } });
DefaultHealthCheckResults aggregate = new DefaultHealthCheckResults(); Iterable<ServiceEndPoint> allEndPoints = getAllEndPoints(); if (Iterables.isEmpty(allEndPoints)) { Iterable<ServiceEndPoint> validEndPoints = getValidEndPoints(allEndPoints); if (Iterables.isEmpty(validEndPoints)) { while (!endPoints.isEmpty()) { ServiceEndPoint endPoint = chooseEndPoint(endPoints, PartitionContextBuilder.empty()); if (endPoint == null) { HealthCheckResult result = checkHealth(endPoint); aggregate.addHealthCheckResult(result); if (exception == null || isRetriableException(exception)) { LOG.info("Unhealthy end point discovered. End point {}", endPoint); endPoints.remove(endPoint); markEndPointAsBad(endPoint); continue;
Iterable<ServiceEndPoint> allEndPoints = getAllEndPoints(); if (Iterables.isEmpty(allEndPoints)) { throw (lastException == null) ? new NoAvailableHostsException(String.format("No endpoints discovered for service %s", getServiceName())) : new NoAvailableHostsException(lastException.getMessage(), lastException); Iterable<ServiceEndPoint> validEndPoints = getValidEndPoints(allEndPoints); if (Iterables.isEmpty(validEndPoints)) { throw (lastException == null) ? new OnlyBadHostsException(String.format("No valid endpoints discovered for service %s, all endpoints: %s", getServiceName(), allEndPoints)) : new OnlyBadHostsException(lastException.getMessage(), lastException); ServiceEndPoint endPoint = chooseEndPoint(validEndPoints, partitionContext); if (endPoint == null) { throw (lastException == null) ? new NoSuitableHostsException(String.format("No suitable endpoint discovered for service %s from valid endpoints %s", getServiceName(), validEndPoints)) : new NoSuitableHostsException(lastException); R result = executeOnEndPoint(endPoint, callback); _numExecuteSuccesses.mark(); return result; if (!isRetriableException(e)) { throw Throwables.propagate(e);
@Override public R call() throws Exception { Timer.Context timer = _executionTime.time(); final long start = _ticker.read(); int numAttempts = 0; try { Exception lastException; do { try { R result = _pool.executeOnEndPoint(endPoint, callback); _numExecuteSuccesses.mark(); return result; } catch (Exception e) { _numExecuteFailures.mark(); // Don't retry if exception is too severe. if (!_pool.isRetriableException(e)) { throw e; } lastException = e; LOG.info("Retriable exception from end point: " + endPoint, e); } } while (retry.allowRetry(++numAttempts, TimeUnit.NANOSECONDS.toMillis(_ticker.read() - start))); throw new MaxRetriesException(lastException); } finally { timer.stop(); } } });
Collection<Future<R>> futures = Lists.newArrayList(); Iterable<ServiceEndPoint> endPoints = _pool.getAllEndPoints(); if (Iterables.isEmpty(endPoints)) { throw new NoAvailableHostsException(String.format("No hosts discovered for service %s", _pool.getServiceName()));
@Override public void close() throws IOException { if (_shutdownExecutorOnClose) { _executor.shutdown(); } if (_shutdownPoolOnClose) { _pool.close(); } _metrics.close(); }
AsyncServicePool(Ticker ticker, ServicePool<S> pool, boolean shutdownPoolOnClose, ExecutorService executor, boolean shutdownExecutorOnClose, MetricRegistry metrics) { _ticker = checkNotNull(ticker); _pool = checkNotNull(pool); _shutdownPoolOnClose = shutdownPoolOnClose; _executor = checkNotNull(executor); _shutdownExecutorOnClose = shutdownExecutorOnClose; _metrics = Metrics.forInstance(metrics, this, _pool.getServiceName()); _executionTime = _metrics.timer("execution-time"); _numExecuteSuccesses = _metrics.meter("num-execute-successes"); _numExecuteFailures = _metrics.meter("num-execute-failures"); _executeBatchSize = _metrics.histogram("execute-batch-size"); }
ServicePool<S> servicePool = new ServicePool<>(Ticker.systemTicker(), hostDiscovery, _closeHostDiscovery, _serviceFactory, _cachingPolicy, _partitionFilter, _loadBalanceAlgorithm, _healthCheckExecutor, shutdownHealthCheckExecutorOnClose, _healthCheckRetryDelay, _metrics);
DefaultHealthCheckResults aggregate = new DefaultHealthCheckResults(); Iterable<ServiceEndPoint> allEndPoints = getAllEndPoints(); if (Iterables.isEmpty(allEndPoints)) { Iterable<ServiceEndPoint> validEndPoints = getValidEndPoints(allEndPoints); if (Iterables.isEmpty(validEndPoints)) { while (!endPoints.isEmpty()) { ServiceEndPoint endPoint = chooseEndPoint(endPoints, PartitionContextBuilder.empty()); if (endPoint == null) { HealthCheckResult result = checkHealth(endPoint); aggregate.addHealthCheckResult(result); if (exception == null || isRetriableException(exception)) { LOG.info("Unhealthy end point discovered. End point {}", endPoint); endPoints.remove(endPoint); markEndPointAsBad(endPoint); continue;
Iterable<ServiceEndPoint> allEndPoints = getAllEndPoints(); if (Iterables.isEmpty(allEndPoints)) { throw (lastException == null) ? new NoAvailableHostsException(String.format("No endpoints discovered for service %s", getServiceName())) : new NoAvailableHostsException(lastException.getMessage(), lastException); Iterable<ServiceEndPoint> validEndPoints = getValidEndPoints(allEndPoints); if (Iterables.isEmpty(validEndPoints)) { throw (lastException == null) ? new OnlyBadHostsException(String.format("No valid endpoints discovered for service %s, all endpoints: %s", getServiceName(), allEndPoints)) : new OnlyBadHostsException(lastException.getMessage(), lastException); ServiceEndPoint endPoint = chooseEndPoint(validEndPoints, partitionContext); if (endPoint == null) { throw (lastException == null) ? new NoSuitableHostsException(String.format("No suitable endpoint discovered for service %s from valid endpoints %s", getServiceName(), validEndPoints)) : new NoSuitableHostsException(lastException); R result = executeOnEndPoint(endPoint, callback); _numExecuteSuccesses.mark(); return result; if (!isRetriableException(e)) { throw Throwables.propagate(e);
@Override public R call() throws Exception { Timer.Context timer = _executionTime.time(); final long start = _ticker.read(); int numAttempts = 0; try { Exception lastException; do { try { R result = _pool.executeOnEndPoint(endPoint, callback); _numExecuteSuccesses.mark(); return result; } catch (Exception e) { _numExecuteFailures.mark(); // Don't retry if exception is too severe. if (!_pool.isRetriableException(e)) { throw e; } lastException = e; LOG.info("Retriable exception from end point: " + endPoint, e); } } while (retry.allowRetry(++numAttempts, TimeUnit.NANOSECONDS.toMillis(_ticker.read() - start))); throw new MaxRetriesException(lastException); } finally { timer.stop(); } } });
Collection<Future<R>> futures = Lists.newArrayList(); Iterable<ServiceEndPoint> endPoints = _pool.getAllEndPoints(); if (Iterables.isEmpty(endPoints)) { throw new NoAvailableHostsException(String.format("No hosts discovered for service %s", _pool.getServiceName()));
@Override public void close() throws IOException { if (_shutdownExecutorOnClose) { _executor.shutdown(); } if (_shutdownPoolOnClose) { _pool.close(); } _metrics.close(); }
AsyncServicePool(Ticker ticker, ServicePool<S> pool, boolean shutdownPoolOnClose, ExecutorService executor, boolean shutdownExecutorOnClose, MetricRegistry metrics) { _ticker = checkNotNull(ticker); _pool = checkNotNull(pool); _shutdownPoolOnClose = shutdownPoolOnClose; _executor = checkNotNull(executor); _shutdownExecutorOnClose = shutdownExecutorOnClose; _metrics = Metrics.forInstance(metrics, this, _pool.getServiceName()); _executionTime = _metrics.timer("execution-time"); _numExecuteSuccesses = _metrics.meter("num-execute-successes"); _numExecuteFailures = _metrics.meter("num-execute-failures"); _executeBatchSize = _metrics.histogram("execute-batch-size"); }
ServicePool<S> servicePool = new ServicePool<>(Ticker.systemTicker(), hostDiscovery, _closeHostDiscovery, _serviceFactory, _cachingPolicy, _partitionFilter, _loadBalanceAlgorithm, _healthCheckExecutor, shutdownHealthCheckExecutorOnClose, _healthCheckRetryDelay, _metrics);
@Override public R call() throws Exception { return _pool.execute(partitionContext, retryPolicy, callback); } });
@Override public int getNumBadEndPoints() { return _pool.getNumBadEndPoints(); } }
@Override public Integer getValue() { return getNumValidEndPoints(); } });