Class CircuitBreakerManager

  • All Implemented Interfaces:
    PluginInfoInitialized

    public class CircuitBreakerManager
    extends Object
    implements PluginInfoInitialized
    Manages all registered circuit breaker instances. Responsible for a holistic view of whether a circuit breaker has tripped or not.

    There are two typical ways of using this class's instance: 1. Check if any circuit breaker has triggered -- and know which circuit breaker has triggered. 2. Get an instance of a specific circuit breaker and perform checks.

    It is a good practice to register new circuit breakers here if you want them checked for every request.

    NOTE: The current way of registering new default circuit breakers is minimal and not a long term solution. There will be a follow up with a SIP for a schema API design.

    • Constructor Detail

      • CircuitBreakerManager

        public CircuitBreakerManager​(boolean enableCircuitBreakerManager)
    • Method Detail

      • deregisterAll

        public void deregisterAll()
      • checkTripped

        public List<CircuitBreaker> checkTripped()
        Check and return circuit breakers that have triggered
        Returns:
        CircuitBreakers which have triggered, null otherwise.
      • checkAnyTripped

        public boolean checkAnyTripped()
        Returns true if *any* circuit breaker has triggered, false if none have triggered.

        NOTE: This method short circuits the checking of circuit breakers -- the method will return as soon as it finds a circuit breaker that is enabled and has triggered.

      • toErrorMessage

        public static String toErrorMessage​(List<CircuitBreaker> circuitBreakerList)
        Construct the final error message to be printed when circuit breakers trip.
        Parameters:
        circuitBreakerList - Input list for circuit breakers.
        Returns:
        Constructed error message.
      • build

        public static CircuitBreakerManager build​(PluginInfo pluginInfo)
        Register default circuit breakers and return a constructed CircuitBreakerManager instance which serves the given circuit breakers.

        Any default circuit breakers should be registered here.

      • isEnabled

        public boolean isEnabled()
      • getRegisteredCircuitBreakers

        public List<CircuitBreaker> getRegisteredCircuitBreakers()