class QueueCircuitBreakerImpl implements QueueCircuitBreaker, RuleChangesObserver, Refreshable {

    @Override
    public Future<Long> unlockSampleQueues() {
        log.info("About to unlock a sample queue for each circuit");
        Future<Long> future = Future.future();
        queueCircuitBreakerStorage.unlockSampleQueues().setHandler(event -> {
            if (event.failed()) {
                future.fail(event.cause().getMessage());
                return;
            }
            List<String> queuesToUnlock = event.result();
            if (queuesToUnlock == null || queuesToUnlock.isEmpty()) {
                future.complete(0L);
                return;
            }
            final AtomicInteger futureCounter = new AtomicInteger(queuesToUnlock.size());
            List<String> failedFutures = new ArrayList<>();
            for (String queueToUnlock : queuesToUnlock) {
                log.info("About to unlock sample queue '" + queueToUnlock + "'");
                unlockQueue(queueToUnlock).setHandler(event1 -> {
                    futureCounter.decrementAndGet();
                    if (event1.failed()) {
                        failedFutures.add(event1.cause().getMessage());
                    }
                    if (futureCounter.get() == 0) {
                        if (failedFutures.size() > 0) {
                            future.fail("The following queues could not be unlocked: " + failedFutures);
                        } else {
                            future.complete((long) queuesToUnlock.size());
                        }
                    }
                });
            }
        });
        return future;
    }

    public  QueueCircuitBreakerImpl(Vertx vertx, Lock lock, String redisquesAddress, QueueCircuitBreakerStorage queueCircuitBreakerStorage, RuleProvider ruleProvider, QueueCircuitBreakerRulePatternToCircuitMapping ruleToCircuitMapping, QueueCircuitBreakerConfigurationResourceManager configResourceManager, Handler<HttpServerRequest> queueCircuitBreakerHttpRequestHandler, int requestHandlerPort);

}