org.springframework.retry.backoff.FixedBackOffPolicy Java Examples
The following examples show how to use
org.springframework.retry.backoff.FixedBackOffPolicy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpBlockchainEventBroadcasterTest.java From eventeum with Apache License 2.0 | 6 votes |
@Before public void init() { final HttpBroadcasterSettings settings = new HttpBroadcasterSettings(); settings.setBlockEventsUrl("http://localhost:8082/consumer/block-event"); settings.setContractEventsUrl("http://localhost:8082/consumer/contract-event"); RetryTemplate retryTemplate = new RetryTemplate(); FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(3000l); retryTemplate.setBackOffPolicy(fixedBackOffPolicy); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(3); retryTemplate.setRetryPolicy(retryPolicy); underTest = new HttpBlockchainEventBroadcaster(settings, retryTemplate); }
Example #2
Source File: DefaultRetryTemplateConverterTest.java From distributed-lock with MIT License | 6 votes |
private void assertRetryTemplateConstruction(final RetryTemplate retryTemplate, final long timeout, final long backOff) { final var wrapper = PropertyAccessorFactory.forDirectFieldAccess(retryTemplate); assertThat(wrapper.getPropertyValue("retryPolicy")).isInstanceOf(CompositeRetryPolicy.class); assertThat((RetryPolicy[]) wrapper.getPropertyValue("retryPolicy.policies")) .hasSize(2) .anyMatch(policy1 -> { if (policy1 instanceof TimeoutRetryPolicy) { final var timeoutRetryPolicy = (TimeoutRetryPolicy) policy1; assertThat(timeoutRetryPolicy.getTimeout()).isEqualTo(timeout); return true; } return false; }) .anyMatch(policy2 -> { if (policy2 instanceof SimpleRetryPolicy) { final var simpleRetryPolicy = (SimpleRetryPolicy) policy2; assertThat(simpleRetryPolicy.getMaxAttempts()).isEqualTo(Integer.MAX_VALUE); return true; } return false; }); assertThat(wrapper.getPropertyValue("backOffPolicy")).isInstanceOf(FixedBackOffPolicy.class); assertThat(((FixedBackOffPolicy) wrapper.getPropertyValue("backOffPolicy")).getBackOffPeriod()).isEqualTo(backOff); }
Example #3
Source File: InteractiveQueryService.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
/** * Retrieve and return a queryable store by name created in the application. * @param storeName name of the queryable store * @param storeType type of the queryable store * @param <T> generic queryable store * @return queryable store. */ public <T> T getQueryableStore(String storeName, QueryableStoreType<T> storeType) { RetryTemplate retryTemplate = new RetryTemplate(); KafkaStreamsBinderConfigurationProperties.StateStoreRetry stateStoreRetry = this.binderConfigurationProperties.getStateStoreRetry(); RetryPolicy retryPolicy = new SimpleRetryPolicy(stateStoreRetry.getMaxAttempts()); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(stateStoreRetry.getBackoffPeriod()); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.setRetryPolicy(retryPolicy); return retryTemplate.execute(context -> { T store = null; final Set<KafkaStreams> kafkaStreams = InteractiveQueryService.this.kafkaStreamsRegistry.getKafkaStreams(); final Iterator<KafkaStreams> iterator = kafkaStreams.iterator(); Throwable throwable = null; while (iterator.hasNext()) { try { store = iterator.next().store(storeName, storeType); } catch (InvalidStateStoreException e) { // pass through.. throwable = e; } } if (store != null) { return store; } throw new IllegalStateException("Error when retrieving state store: j " + storeName, throwable); }); }
Example #4
Source File: ClusterScaleProcessServiceImpl.java From cymbal with Apache License 2.0 | 5 votes |
public ClusterScaleProcessServiceImpl() { SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(ENLARGE_MAX_ATTEMPTS); retryTemplate.setRetryPolicy(retryPolicy); // 失败后补偿策略 FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(MIGRATE_BACKOFF_PERIOD); retryTemplate.setBackOffPolicy(backOffPolicy); }
Example #5
Source File: MailServiceImpl.java From cymbal with Apache License 2.0 | 5 votes |
public MailServiceImpl() { SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(MAIL_MAX_ATTEMPTS); retryTemplate.setRetryPolicy(retryPolicy); // 失败后补偿策略 FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(MAIL_BACKOFF_PERIOD); retryTemplate.setBackOffPolicy(backOffPolicy); }
Example #6
Source File: EternalRetryTemplateConfiguration.java From eventeum with Apache License 2.0 | 5 votes |
@Bean public RetryTemplate eternalRetryTemplate() { RetryTemplate retryTemplate = new RetryTemplate(); FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(DEFAULT_BACKOFF_TIME); retryTemplate.setBackOffPolicy(fixedBackOffPolicy); AlwaysRetryPolicy retryPolicy = new AlwaysRetryPolicy(); retryTemplate.setRetryPolicy(retryPolicy); return retryTemplate; }
Example #7
Source File: RetryInterceptor.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
private static RetryTemplate createRetryTemplate(RetryPolicy policy) { RetryTemplate template = new RetryTemplate(); // 重试策略 SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(policy.getMaxAttempts()); // 设置间隔策略 FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(policy.getSleepMillis()); template.setRetryPolicy(retryPolicy); template.setBackOffPolicy(backOffPolicy); return template; }
Example #8
Source File: WebserviceDocumentItemProcessor.java From CogStack-Pipeline with Apache License 2.0 | 5 votes |
private RetryTemplate getRetryTemplate(){ TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy(); retryPolicy.setTimeout(retryTimeoutMs); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(retryBackoffMs); RetryTemplate template = new RetryTemplate(); template.setRetryPolicy(retryPolicy); template.setBackOffPolicy(backOffPolicy); return template; }
Example #9
Source File: CleanupBean.java From CogStack-Pipeline with Apache License 2.0 | 5 votes |
public RetryTemplate getRetryTemplate(){ // TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy(); // retryPolicy.setTimeout(Long.valueOf(env.getProperty("shutdownTimeout"))); AlwaysRetryPolicy retryPolicy = new AlwaysRetryPolicy(); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(5000); RetryTemplate template = new RetryTemplate(); template.setRetryPolicy(retryPolicy); template.setBackOffPolicy(backOffPolicy); return template; }
Example #10
Source File: RetryExampleApplication.java From blog-examples with Apache License 2.0 | 5 votes |
@Bean public RetryTemplate retryTemplate() { SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(5); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(1500); // 1.5 seconds RetryTemplate template = new RetryTemplate(); template.setRetryPolicy(retryPolicy); template.setBackOffPolicy(backOffPolicy); return template; }
Example #11
Source File: CmApiRetryTemplateConfig.java From cloudbreak with Apache License 2.0 | 5 votes |
@Bean public RetryTemplate cmApiRetryTemplate() { RetryTemplate retryTemplate = new RetryTemplate(); FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(BACK_OFF_PERIOD); retryTemplate.setBackOffPolicy(fixedBackOffPolicy); retryTemplate.setRetryPolicy(new ApiExceptionRetryPolicy()); return retryTemplate; }
Example #12
Source File: JpaDeploymentManagement.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
private static RetryTemplate createRetryTemplate() { final RetryTemplate template = new RetryTemplate(); final FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(Constants.TX_RT_DELAY); template.setBackOffPolicy(backOffPolicy); final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(Constants.TX_RT_MAX, Collections.singletonMap(ConcurrencyFailureException.class, true)); template.setRetryPolicy(retryPolicy); return template; }
Example #13
Source File: FixedBackoffRetryFactory.java From tutorials with MIT License | 4 votes |
@Override public BackOffPolicy createBackOffPolicy(String service) { FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(2000); return fixedBackOffPolicy; }
Example #14
Source File: AmqpContextConfig.java From sinavi-jfw with Apache License 2.0 | 4 votes |
/** * リトライ間隔を設定し、{@link SleepingBackOffPolicy}のインスタンスを生成します。 * @return {@link FixedBackOffPolicy}のインスタンス */ protected SleepingBackOffPolicy<FixedBackOffPolicy> backOffPolicy() { FixedBackOffPolicy policy = new FixedBackOffPolicy(); policy.setBackOffPeriod(backOffPeriod); return policy; }
Example #15
Source File: CuratorKafkaMonitor.java From Kafdrop with Apache License 2.0 | 4 votes |
public CuratorKafkaMonitor(CuratorFramework curatorFramework, CuratorKafkaMonitorProperties properties, ObjectMapper objectMapper) throws Exception { this.curatorFramework = curatorFramework; this.properties = properties; this.objectMapper = objectMapper; try { kafkaVersion = new Version(properties.getKafkaVersion()); } catch (Exception ex) { throw new IllegalStateException("Invalid kafka version: " + properties.getKafkaVersion(), ex); } threadPool = new ForkJoinPool(properties.getThreadPoolSize()); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(properties.getRetry().getBackoffMillis()); final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(properties.getRetry().getMaxAttempts(), ImmutableMap.of(InterruptedException.class, false, Exception.class, true)); retryTemplate = new RetryTemplate(); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.setRetryPolicy(retryPolicy); cacheInitCounter.set(4); brokerPathCache = new PathChildrenCache(curatorFramework, ZkUtils.BrokerIdsPath(), true); brokerPathCache.getListenable().addListener(new BrokerListener()); brokerPathCache.getListenable().addListener((f, e) -> { if (e.getType() == PathChildrenCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Broker cache initialized"); } }); brokerPathCache.start(StartMode.POST_INITIALIZED_EVENT); topicConfigPathCache = new PathChildrenCache(curatorFramework, ZkUtils.TopicConfigPath(), true); topicConfigPathCache.getListenable().addListener((f, e) -> { if (e.getType() == PathChildrenCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Topic configuration cache initialized"); } }); topicConfigPathCache.start(StartMode.POST_INITIALIZED_EVENT); topicTreeCache = new TreeCache(curatorFramework, ZkUtils.BrokerTopicsPath()); topicTreeCache.getListenable().addListener((client, event) -> { if (event.getType() == TreeCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Topic tree cache initialized"); } }); topicTreeCache.start(); consumerTreeCache = new TreeCache(curatorFramework, ZkUtils.ConsumersPath()); consumerTreeCache.getListenable().addListener((client, event) -> { if (event.getType() == TreeCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Consumer tree cache initialized"); } }); consumerTreeCache.start(); controllerNodeCache = new NodeCache(curatorFramework, ZkUtils.ControllerPath()); controllerNodeCache.getListenable().addListener(this::updateController); controllerNodeCache.start(true); updateController(); }
Example #16
Source File: ClickingStepDefinitions.java From IridiumApplicationTesting with MIT License | 4 votes |
/** * Clicks a link that may or may not be visible on the page * * @param alias If this word is found in the step, it means the linkContent is found from the data * set. * @param linkContent The text content of the link we are clicking * @param timesAlias If this word is found in the step, it means the times is found from the * data set. * @param times If this text is set, the click operation will be repeated the specified number of times. * @param exists If this text is set, an error that would be thrown because the element was not found * is ignored. Essentially setting this text makes this an optional statement. */ @When("^I click (?:a|an|the) hidden link with the text content( alias)? of \"([^\"]*)\"(?:( alias)? \"(.*?)\" times)?( if it exists)?$") public void clickHiddenLinkStep( final String alias, final String linkContent, final String timesAlias, final String times, final String exists) { try { final Integer fixedTimes = countConverter.convertCountToInteger(timesAlias, times); final String text = autoAliasUtils.getValue( linkContent, StringUtils.isNotBlank(alias), State.getFeatureStateForThread()); checkState(text != null, "the aliased link content does not exist"); final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread(); for (int i = 0; i < fixedTimes; ++i) { final RetryTemplate template = new RetryTemplate(); final SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(Constants.WEBDRIVER_ACTION_RETRIES); template.setRetryPolicy(policy); final FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); template.setBackOffPolicy(fixedBackOffPolicy); template.execute(context -> { final WebElement element = browserInteropUtils.getLinkByText(webDriver, text); mouseMovementUtils.mouseGlide( webDriver, (JavascriptExecutor) webDriver, element, Constants.MOUSE_MOVE_TIME, Constants.MOUSE_MOVE_STEPS); final JavascriptExecutor js = (JavascriptExecutor) webDriver; js.executeScript("arguments[0].click();", element); return null; }); sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep()); } } catch (final TimeoutException | NoSuchElementException ex) { if (StringUtils.isBlank(exists)) { throw ex; } } }
Example #17
Source File: ClickingStepDefinitions.java From IridiumApplicationTesting with MIT License | 4 votes |
/** * Clicks a link on the page * * @param alias If this word is found in the step, it means the linkContent is found from the data * set. * @param linkContent The text content of the link we are clicking * @param timesAlias If this word is found in the step, it means the times is found from the * data set. * @param times If this text is set, the click operation will be repeated the specified number of times. * @param exists If this text is set, an error that would be thrown because the element was not found * is ignored. Essentially setting this text makes this an optional statement. */ @When("^I click (?:a|an|the) link with the text content of( alias)? \"([^\"]*)\"(?:( alias)? \"(.*?)\" times)?( if it exists)?$") public void clickLinkStep( final String alias, final String linkContent, final String timesAlias, final String times, final String exists) { try { final Integer fixedTimes = countConverter.convertCountToInteger(timesAlias, times); final String text = autoAliasUtils.getValue( linkContent, StringUtils.isNotBlank(alias), State.getFeatureStateForThread()); checkState(text != null, "the aliased link content does not exist"); final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread(); for (int i = 0; i < fixedTimes; ++i) { final WebElement element = browserInteropUtils.getLinkByText(webDriver, text); mouseMovementUtils.mouseGlide( webDriver, (JavascriptExecutor) webDriver, element, Constants.MOUSE_MOVE_TIME, Constants.MOUSE_MOVE_STEPS); final RetryTemplate template = new RetryTemplate(); final SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(Constants.WEBDRIVER_ACTION_RETRIES); template.setRetryPolicy(policy); final FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); template.setBackOffPolicy(fixedBackOffPolicy); template.execute(context -> { element.click(); return null; }); sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep()); } } catch (final TimeoutException | NoSuchElementException ex) { if (StringUtils.isBlank(exists)) { throw ex; } } }
Example #18
Source File: DefaultRetryTemplateConverter.java From distributed-lock with MIT License | 4 votes |
private FixedBackOffPolicy resolveBackOffPolicy(final Locked locked) { final var fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(intervalConverter.toMillis(locked.retry())); return fixedBackOffPolicy; }