Giter Club home page Giter Club logo

retry's Introduction

retry

Build Status codecov Maven Central

retry is a small, dependency-free Java library for configuring retry strategies. It is heavily inspired by guava-retrying, without its dependency on Guava.

Setup

retry is available via Maven Central. To include it in a Gradle project, add the following dependency:

compile "org.joeyb.retry:retry:$retryVersion"

Usage

A Retry<V> instance is configured with a particular retry strategy, and can be used by passing a Callable<V> to its call method:

Retry<V> retry = ...

V result = retry.call(() -> service.performUnreliableRequest());

The retry strategy is dictated by 5 basic components:

Accept

The acceptance strategy (defined by the Accept interface) is used to specify whether or not the result from an attempted execution of the underlying Callable<V> should be accepted. For example, Accepts.any() returns an Accept instance that accepts any value.

Attempt Listener

The attempt listener (defined as a Consumer<Attempt<V>>) is used to give the consumer a notification of failed attempts. This is useful for logging failures or keeping metrics of failed attempt counts.

Block

The blocking strategy (defined by the Block interface) is used to specify how the retryer should block its thread while waiting for the next attempt. The default is a Thread.sleep()-based implementation, which should be sufficient for most use-cases.

Stop

The stopping strategy (defined by the Stop interface) is used to specify when the retryer should give up. The Stops class provides some common implementations, including stopping based on a maximum number of attempts or a maximum time since start.

Wait

The wait strategy (defined by the Wait interface) is used to specify how long the retryer should wait between each attempt.

Retry<V> Builder

The Retry<V> class provides a fluent builder for constructing retry strategies. For example, you can build a simple retry strategy that retries indefinitely, with no waiting between attempts, until it gets back a non-null value like this:

Retry<Long> retry = Retry.<Long>newBuilder()
  .acceptNonNullResult()
  .build()

retry's People

Contributors

joeyb avatar

Stargazers

Ben Aiken avatar

Watchers

 avatar James Cloos avatar Ben Aiken avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.