public void onResponseReceive()

in wilma-extras/circuitBreaker/src/main/java/com/epam/wilma/extras/circuitbreaker/CircuitBreakerInterceptor.java [92:121]


    public void onResponseReceive(WilmaHttpResponse wilmaHttpResponse, ParameterList parameters) {
        //get the key
        String identifier = parameters.get("identifier");
        if (identifier != null && identifier.length() != 0) {
            //we have identifier
            synchronized (GUARD) {
                if (CIRCUIT_BREAKER_MAP.containsKey(identifier)) {
                    CircuitBreakerInformation circuitBreakerInformation = CIRCUIT_BREAKER_MAP.get(identifier);
                    //detect if it belongs to my circuit breaker (= is it the right path?) and is it valid
                    if (circuitBreakerInformation.isValid()
                            && wilmaHttpResponse.getProxyRequestLine().toLowerCase().contains(circuitBreakerInformation.getPath().toLowerCase())) {
                        //it is mine, so let's evaluate the result
                        if (!circuitBreakerInformation.isActive()) {
                            //circuit breaker is not active
                            if (isStatusCodeAcceptable(wilmaHttpResponse.getStatusCode(), circuitBreakerInformation.getSuccessCodes())) {
                                //the response has acceptable status code
                                circuitBreakerInformation.resetErrorLevel();
                            } else {
                                //the response has no acceptable status code, so increase the number of problematic responses found
                                boolean isOverLimit = circuitBreakerInformation.increaseErrorLevel();
                                if (isOverLimit) { //and in case it reaches the error limit, then turn the circuit breaker ON
                                    circuitBreakerInformation.turnCircuitBreakerOn();
                                }
                            }
                        }
                    }
                }
            }
        }
    }