Git Product home page Git Product logo

Comments (9)

JensRantil avatar JensRantil commented on September 27, 2024 1

I get an error:
for implements RetryListener {

I never compiled my code so I'm afraid you will have to take it with a grain of salt. :)

why are these atomic?

Because Java closures can't modify variables outside of its scope (since they need to be final). Using Atomic* classes circumvents that restriction.

what does this mean retry.getNumerOfAttampts() == 1 ?

What type is retry? Have you checked the JavaDoc for the method? See http://rholder.github.io/guava-retrying/javadoc/2.0.0/.

I mean, should I create new listener to each request?

I guess that really depends if you decide to keep any state in it or not. In my example above I store my state in RetryableRequest. That way, it's totally fine to create a new temporary listener for every request.

each listener have a request member and thus i don't need thread safety (atomic boolean). no?

Like I said ☝️, the Atomic* classes aren't really used for thread safety, but rather working around Java limitations.

from guava-retrying.

JensRantil avatar JensRantil commented on September 27, 2024

You might be able to keep track of that in a RetryListener which you give to the RetryerBuilder. Does that solve your issue?

from guava-retrying.

elad2109 avatar elad2109 commented on September 27, 2024

can you help with a code snipet? I'm not sure the code that calls the backoff mechanism can read the falg indicating a request was successful only after a retry?

from guava-retrying.

JensRantil avatar JensRantil commented on September 27, 2024

Let's take a step back. What is your use-case? Why do you want to flag the retry?

from guava-retrying.

elad2109 avatar elad2109 commented on September 27, 2024

I have a list of requests. I want to flag each response with "succeeded"(status 200) , "failed", "succeeded after retry"

from guava-retrying.

JensRantil avatar JensRantil commented on September 27, 2024

Something like this should probably get you started:

class RetryableRequest implements RetryListener<Boolean> {
    private final Retryer retryer;
    private final Request request;
    private final AtomicBoolean succeeded = new AtomicBoolean();
    private final AtomicBoolean retried = new AtomicBoolean();

    public RetryableRequest(Request request) {
        this.retryer = RetryerBuilder.withRetryListener(this).build();
        this.request = request;
    }

    public void execute() {
        retryer.call(new Callable<Boolean>() {
            public Boolean call() {
                request.execute();
                // Here you modify `succeeded`.
            }
        });
    }

    public void onRetry(Attempt<Boolean> retry) {
        if (!retry.hasResult())
            retried.set(true);
    }

    public boolean executionWasRetried() {
        return retried.get();
    }

    public boolean executionSucceeded() {
        return succeeded.get();
    }
}

from guava-retrying.

elad2109 avatar elad2109 commented on September 27, 2024

I get an error:
for implements RetryListener<Boolean> {

Error:(15, 48) java: type com.github.rholder.retry.RetryListener does not take parameters

from guava-retrying.

elad2109 avatar elad2109 commented on September 27, 2024

why are these atomic?

private final AtomicBoolean succeeded = new AtomicBoolean();
private final AtomicBoolean retried = new AtomicBoolean();

I mean, should I create new listener to each request?
each listener have a request member and thus i don't need thread safety (atomic boolean). no?

from guava-retrying.

elad2109 avatar elad2109 commented on September 27, 2024

what does this mean retry.getNumerOfAttampts() == 1 ?

  1. The first try ever has been done?
    e.g. http send and returned

Or
2) These has been a retry after the a failure (retry-predicate returned false)?
http send and returned failure, then we sent a retry already.

from guava-retrying.

Related Issues (20)

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.