protected <V> V supplyWithRetries(Supplier<V> supplier) { return Retries.supplyWithRetries(supplier, retryStrategy, IS_RETRYABLE); }
protected <V> V supplyWithRetries(Supplier<V> supplier) { return Retries.supplyWithRetries(supplier, retryStrategy, IS_RETRYABLE); }
/** * The same as calling {@link #supplyWithRetries(Supplier, RetryStrategy, Predicate)} where a retryable failure * is defined as a {@link RetryableException}. * * @param supplier the callable to run * @param retryStrategy the retry strategy to use if the supplier throws a {@link RetryableException} * @param <V> the type of object returned by the supplier * @return the return value of the supplier * @throws RuntimeException if the supplier failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <V> V supplyWithRetries(Supplier<V> supplier, RetryStrategy retryStrategy) { return supplyWithRetries(supplier, retryStrategy, DEFAULT_PREDICATE); }
/** * The same as calling {@link #supplyWithRetries(Supplier, RetryStrategy, Predicate)} where a retryable failure * is defined as a {@link RetryableException}. * * @param supplier the callable to run * @param retryStrategy the retry strategy to use if the supplier throws a {@link RetryableException} * @param <V> the type of object returned by the supplier * @return the return value of the supplier * @throws RuntimeException if the supplier failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <V> V supplyWithRetries(Supplier<V> supplier, RetryStrategy retryStrategy) { return supplyWithRetries(supplier, retryStrategy, DEFAULT_PREDICATE); }
@Override public int waitFor() throws InterruptedException { RetryStrategy retry = RetryStrategies.fixDelay(100, TimeUnit.MILLISECONDS); return Retries.supplyWithRetries(this::exitValue, retry, IllegalThreadStateException.class::isInstance); }
@Override public int waitFor() throws InterruptedException { RetryStrategy retry = RetryStrategies.fixDelay(100, TimeUnit.MILLISECONDS); return Retries.supplyWithRetries(this::exitValue, retry, IllegalThreadStateException.class::isInstance); }
@Override public int waitFor(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException { RetryStrategy retry = RetryStrategies.timeLimit(timeout, unit, RetryStrategies.fixDelay(100, TimeUnit.MILLISECONDS)); try { return Retries.supplyWithRetries(this::exitValue, retry, IllegalThreadStateException.class::isInstance); } catch (IllegalThreadStateException e) { throw new TimeoutException("Process is still running"); } }
@Override public int waitFor(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException { RetryStrategy retry = RetryStrategies.timeLimit(timeout, unit, RetryStrategies.fixDelay(100, TimeUnit.MILLISECONDS)); try { return Retries.supplyWithRetries(this::exitValue, retry, IllegalThreadStateException.class::isInstance); } catch (IllegalThreadStateException e) { throw new TimeoutException("Process is still running"); } }
@Override protected void startUp() throws Exception { final DatasetId serviceStoreDatasetInstanceId = NamespaceId.SYSTEM.dataset(Constants.Service.SERVICE_INSTANCE_TABLE_NAME); table = Retries.supplyWithRetries(() -> { try { return DatasetsUtil.getOrCreateDataset(dsFramework, serviceStoreDatasetInstanceId, NoTxKeyValueTable.class.getName(), DatasetProperties.EMPTY, null); } catch (Exception e) { // Throwing RetryableException here is just to make it retry getting the dataset // an exception here usually means there is an hbase problem LOG.warn("Error getting service store dataset {}. Will retry after some time: {}", serviceStoreDatasetInstanceId, e.getMessage()); throw new RetryableException(e); } }, RetryStrategies.exponentialDelay(1, 30, TimeUnit.SECONDS)); }
@Override protected void startUp() throws Exception { final DatasetId serviceStoreDatasetInstanceId = NamespaceId.SYSTEM.dataset(Constants.Service.SERVICE_INSTANCE_TABLE_NAME); table = Retries.supplyWithRetries(() -> { try { return DatasetsUtil.getOrCreateDataset(dsFramework, serviceStoreDatasetInstanceId, NoTxKeyValueTable.class.getName(), DatasetProperties.EMPTY, null); } catch (Exception e) { // Throwing RetryableException here is just to make it retry getting the dataset // an exception here usually means there is an hbase problem LOG.warn("Error getting service store dataset {}. Will retry after some time: {}", serviceStoreDatasetInstanceId, e.getMessage()); throw new RetryableException(e); } }, RetryStrategies.exponentialDelay(1, 30, TimeUnit.SECONDS)); }
private void publishMessage(EntityId entityId, MetadataMessage.Type type, Object payload) { MetadataMessage message = new MetadataMessage(type, entityId, GSON.toJsonTree(payload)); LOG.trace("Publishing message: {}", message); try { Retries.supplyWithRetries( () -> { try { messagingContext.getMessagePublisher().publish(NamespaceId.SYSTEM.getNamespace(), topic.getTopic(), GSON.toJson(message)); } catch (TopicNotFoundException | ServiceUnavailableException e) { throw new RetryableException(e); } catch (IOException e) { throw Throwables.propagate(e); } return null; }, retryStrategy); } catch (Exception e) { throw new RuntimeException(String.format("Failed to publish profile metadata request for entity id %s", entityId), e); } } }
private void publishMessage(EntityId entityId, MetadataMessage.Type type, Object payload) { MetadataMessage message = new MetadataMessage(type, entityId, GSON.toJsonTree(payload)); try { Retries.supplyWithRetries( () -> { try { messagingContext.getMessagePublisher().publish(NamespaceId.SYSTEM.getNamespace(), topic.getTopic(), GSON.toJson(message)); } catch (TopicNotFoundException | ServiceUnavailableException e) { throw new RetryableException(e); } catch (IOException e) { throw Throwables.propagate(e); } return null; }, retryStrategy); } catch (Exception e) { throw new RuntimeException(String.format("Failed to publish profile metadata request for entity id %s", entityId), e); } } }
private void publish(Map<String, String> properties) { final StoreRequest storeRequest = StoreRequestBuilder.of(topic) .addPayload(GSON.toJson(new Notification(Notification.Type.PROGRAM_STATUS, properties))) .build(); Retries.supplyWithRetries( () -> { try { messagingService.publish(storeRequest); } catch (TopicNotFoundException e) { throw new RetryableException(e); } catch (IOException e) { throw Throwables.propagate(e); } return null; }, retryStrategy); } }
private void publish(Map<String, String> properties) { final StoreRequest storeRequest = StoreRequestBuilder.of(topic) .addPayload(GSON.toJson(new Notification(Notification.Type.PROGRAM_STATUS, properties))) .build(); Retries.supplyWithRetries( () -> { try { messagingService.publish(storeRequest); } catch (TopicNotFoundException e) { throw new RetryableException(e); } catch (IOException e) { throw Throwables.propagate(e); } return null; }, retryStrategy); } }