public void onRequestReceive()

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


    public void onRequestReceive(WilmaHttpRequest wilmaHttpRequest, ParameterList parameters) {
        //get the key
        String identifier = parameters.get("identifier");
        if (identifier != null && identifier.length() != 0) {
            //we have identifier
            synchronized (GUARD) {
                CircuitBreakerInformation circuitBreakerInformation;
                if (!CIRCUIT_BREAKER_MAP.containsKey(identifier)) {
                    //we don't have this circuit breaker in the map yet, so put it there
                    circuitBreakerInformation = new CircuitBreakerInformation(identifier, parameters);
                    CIRCUIT_BREAKER_MAP.put(identifier, circuitBreakerInformation);
                }
                //we are sure that we have the info in the map, so evaluate it
                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()
                        && wilmaHttpRequest.getRequestLine().toLowerCase().contains(circuitBreakerInformation.getPath().toLowerCase())) {
                    //it is mine
                    //handle the active circuit breaker - if necessary
                    if (circuitBreakerInformation.isActive()) {
                        //specific circuit breaker is turned ON - is the timeout passed?
                        if (circuitBreakerInformation.getTimeout() < System.currentTimeMillis()) {
                            //yes, passed, so we need to turn off the active CB, and fall back to normal operation
                            circuitBreakerInformation.turnCircuitBreakerOff();
                        } else {
                            //no, not yet timed out, so CB must be active, and Wilma sends back the response,
                            //let's notify the condition checker
                            wilmaHttpRequest.addHeaderUpdate(CIRCUIT_BREAKER_HEADER, identifier);
                        }
                    }
                }
            }
        }
    }