@Override
    public State state() {
        long failingNanos = nanoClock.getAsLong() - failingSinceNanos.get();
        if (failingNanos > graceNanos && halfOpen.compareAndSet(false, true))
            log.log(INFO, "Circuit breaker is now half-open, as no requests have succeeded for the " +
                          "last " + failingNanos / 1_000_000 + "ms. The server will be pinged to see if it recovers" +
                          (doomNanos >= 0 ? ", but this client will give up if no successes are observed within " + doomNanos / 1_000_000 + "ms" : "") +
                          ". First failure was '" + detail.get() + "'.");

        if (doomNanos >= 0 && failingNanos > doomNanos && open.compareAndSet(false, true))
            log.log(WARNING, "Circuit breaker is now open, after " + doomNanos / 1_000_000 + "ms of failing request, " +
                             "and this client will give up and abort its remaining feed operations.");

        return open.get() ? State.OPEN : halfOpen.get() ? State.HALF_OPEN : State.CLOSED;
    }
Creates a new circuit breaker with the given grace periods.
@param grace the period of consecutive failures before state changes to half-open.
@param doom the period of consecutive failures before shutting down.
vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/GracePeriodCircuitBreaker.java