Giter Site home page Giter Site logo

Comments (6)

jhalterman avatar jhalterman commented on August 19, 2024

withDelay should always work, even when manually operating the CircuitBreaker. State transitions occur when CircuitBreaker.allowsExecution is called. If the delay has been exceeded since the circuit breaker has been in that state, then a transition will happen. Here's a bit of code that demonstrates:

  public void test() throws Throwable {
    CircuitBreaker breaker = new CircuitBreaker().withDelay(500, TimeUnit.MILLISECONDS);

    breaker.open();
    breaker.allowsExecution();
    Thread.sleep(400);

    assertTrue(breaker.isOpen());
    Thread.sleep(150);
    breaker.allowsExecution();
    assertTrue(breaker.isHalfOpen());
  }

Are you seeing something else?

from failsafe.

Spikhalskiy avatar Spikhalskiy commented on August 19, 2024

Ups, I didn't use this method, it's pretty unobvious that this method triggers state changing and getState doesn't. Maybe additional javadocs for getState() that if you want state to be updated - you should trigger allowsExecution() before in case of standalone usage? Thanks for your help anyway.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

No problem. getState() triggering a transition check is not a bad idea. Standalone usage is a bit more of a niche use case, but I want it to make sense.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

@Spikhalskiy What would your ideal API/usage look like? The example in the docs uses allowsExecution, but maybe that doesn't make sense for all use cases...

from failsafe.

Spikhalskiy avatar Spikhalskiy commented on August 19, 2024

@jhalterman I already can't adopt canonical failsafe API to my project, because we have some different requirements like... in half_open state we don't want to allow any concurrent executions, we want to allow only one execution for health check and only after success of this one execution allow concurrency for this service. But CircuitBreaker alone is very fine for me.

Give me some time, maybe I would back with few pull requests and proposals. Thank you for response.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

@Spikhalskiy Your comments are welcome and appreciated.

I have thought about supporting limited concurrency in half-open state (see #44), but haven't heard much from users on this so it wasn't a priority. Right now max concurrency is determined by the success and failure thresholds you set:

https://github.com/jhalterman/failsafe/blob/master/src/main/java/net/jodah/failsafe/internal/HalfOpenState.java#L92-L98

So you could set .withSuccessThreshold(1) and it sounds like that should work for your use case. The problem is that right now, tracking currentExecutions isn't really supported for standalone usage. For internal usage via the Failsafe class, failsafe calls CircuitBreaker.before, so something like that would need to be exposed for standalone usage to inform the breaker that an execution is about to be performed.

from failsafe.

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.