All Projects → alexpanov → retries

alexpanov / retries

Licence: other
Forget about your retry boilerplate

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to retries

waiter
Delayed iteration for polling and retries.
Stars: ✭ 17 (+21.43%)
Mutual labels:  retry, wait
Tenacity
Retrying library for Python
Stars: ✭ 3,472 (+24700%)
Mutual labels:  retry, failure
Toxy
Hackable HTTP proxy for resiliency testing and simulated network conditions
Stars: ✭ 2,698 (+19171.43%)
Mutual labels:  retry, failure
Gollback
Go asynchronous simple function utilities, for managing execution of closures and callbacks
Stars: ✭ 55 (+292.86%)
Mutual labels:  retry
Guzzle retry middleware
Middleware for Guzzle v6+ that automatically retries HTTP requests on 429, 503 responses.
Stars: ✭ 90 (+542.86%)
Mutual labels:  retry
Rehttp
Package rehttp implements a Go HTTP transport that handles retries.
Stars: ✭ 170 (+1114.29%)
Mutual labels:  retry
await
28Kb, small memory footprint, single binary that run list of commands in parallel and waits for their termination
Stars: ✭ 73 (+421.43%)
Mutual labels:  wait
Routine
go routine control, abstraction of the Main and some useful Executors.如果你不会管理Goroutine的话,用它
Stars: ✭ 40 (+185.71%)
Mutual labels:  retry
Afnetworking Retrypolicy
Nice category that adds the ability to set the retry interval, retry count and progressiveness.
Stars: ✭ 197 (+1307.14%)
Mutual labels:  retry
Safely
Safely is a Clojure's circuit-breaker library for handling retries in an elegant declarative way.
Stars: ✭ 152 (+985.71%)
Mutual labels:  retry
Toolkit
Collection of useful patterns
Stars: ✭ 137 (+878.57%)
Mutual labels:  retry
Job
JOB, make your short-term command as a long-term job. 将命令行规划成任务的工具
Stars: ✭ 98 (+600%)
Mutual labels:  retry
Resilient.js
Fault tolerant and reactive HTTP client for node.js and browsers
Stars: ✭ 172 (+1128.57%)
Mutual labels:  retry
Async Retry
Retrying made simple, easy and async
Stars: ✭ 1,262 (+8914.29%)
Mutual labels:  retry
Mug
A small Java 8 util library, complementary to Guava (BiStream, Substring, MoreStreams, Parallelizer).
Stars: ✭ 236 (+1585.71%)
Mutual labels:  retry
Batchman
This library for Android will take any set of events and batch them up before sending it to the server. It also supports persisting the events on disk so that no event gets lost because of an app crash. Typically used for developing any in-house analytics sdk where you have to make a single api call to push events to the server but you want to optimize the calls so that the api call happens only once per x events, or say once per x minutes. It also supports exponential backoff in case of network failures
Stars: ✭ 50 (+257.14%)
Mutual labels:  retry
Retry4j
Lightweight Java library for retrying unreliable logic
Stars: ✭ 179 (+1178.57%)
Mutual labels:  retry
View Load Retry
这个加载框架有点不一样,针对View进行加载,加载页面还保持了原View的属性,侧重点在灵活,哪里需要加载哪里,加载状态页面完全自定义,无任何限制,针对加载结果可以按需配置对应页面,LeakCanary检测无内存泄漏
Stars: ✭ 119 (+750%)
Mutual labels:  retry
Kotlin Retry
A higher-order function for retrying operations that may fail.
Stars: ✭ 159 (+1035.71%)
Mutual labels:  retry
esa-httpclient
An asynchronous event-driven HTTP client based on netty.
Stars: ✭ 82 (+485.71%)
Mutual labels:  retry

Build Status Windows Build Status Coverage

Retries

You need to make a call that may fail. You need to wait for a value that meets your criteria. You write your own retry boilerplate. Why? Throw it away. You need not to support it anymore.

Motivation

Have you ever written a retry/wait code that looks like this?

private String computeWithRetries() {
    int numberOfTries = 10;
    int sleepTimeout = 1000; // one sec
    for (int i = 0; i < numberOfTries; i++) {
        try {
            String value = computeValue();
        } catch (Exception e) {
            try {
                Thread.sleep(sleepTimeout);
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }
            continue;
        }
        if (value != null && !value.startsWith("B")) {
            return value;
        }
    }
    throw new RuntimeException("Could not compute anything");
}

Ugh. That's terrible and you know it. It's hard to figure out what's going on, hard to extend, hard to reuse and easy to get it wrong. Luckily, there is an alternative.

Build tools

Add retries to your dependencies. Note that Guava is automatically added too.

Maven:

<dependency>
    <groupId>me.alexpanov</groupId>
    <artifactId>retries</artifactId>
    <version>0.0.3</version>
</dependency>

Gradle:

compile "me.alexpanov:retries:0.0.3"

Getting started

Create a retryable:

//Nasty call that returns so much nulls
Retryable<String> retryable = new Retryable<String>() {
            @Override
            public String tryOnce() throws Exception {
                return null;
            }
        };

One call, one failure, RetryException is thrown

String resultAfterRetries = new Retries<String>(retryable).stopOnMaxFailures(1).perform();

Code above will throw a subclass of RetryException:

me.alexpanov.retries.FailedToComputeAValueException

Same thing asynchronously, java.util.concurrent.ExecutionException is thrown

Future<String> resultAfterRetries = new Retries<String>(retryable).stopOnMaxFailures(1).performAsync();
String result = resultAfterRetries.get();

Code above will throw an ExecutionException with a subclass of RetryException as a cause:

me.alexpanov.retries.FailedToComputeAValueException

One call, one failure, default value is returned

String resultAfterRetries = new Retries<String>(retryable).stopOnMaxFailures(1)
                                                          .orElse("default value")
                                                          .perform();
resultAfterRetries.equals("default value"); //true

Several calls, configured wait timeout

String resultAfterRetries = new Retries<String>(retryable).stopOnMaxFailures(10)
                                                          .waitAfterFailureAtLeast(10, TimeUnit.SECONDS)
                                                          .orElse("default value")
                                                          .perform();

Ignoring results

Predicate<String> startsWithLetterB = new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                return input.startsWith("B");
            }
        };
String resultAfterRetries = new Retries<String>(retryable).stopOnMaxFailures(2)
                                                          .ignoreIfResult(startsWithLetterB)
                                                          .perform();

Subscribing to failures for logging etc.

FailureSubscriber<String> logTheError = new FailureSubscriber<String>() {
            @Override
            public void onFailure(RetryFailure<String> details) {
                LOG.info("Failure");
            }
        };
String resultAfterRetries = new Retries<String>(retryable).stopOnMaxFailures(10)
                                                          .onEachFailureDo(logTheError)
                                                          .perform();

The code above will append a log message each time a call failed (exception, null or skipped result).

But what about my Callable(s)!?

I got you covered, man.

Retryable<String> retryable = new CallableToRetryable<String>(yourCallable);

Licence

The Apache Software License, Version 2.0

Issues

Please feel free to add any issues regarding new functionality, improvements etc. in the Issues section

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].