Class CircuitBreaker

All Implemented Interfaces:
Runnable, MetricConstants, MoleculerLifecycle

public class CircuitBreaker extends DefaultServiceInvoker implements Runnable, MetricConstants
Special service invoker with retry logic + circuit breaker.
  • Field Details

    • maxTries

      protected int maxTries
      Number of max tries
    • maxSameNodes

      protected int maxSameNodes
      Exit from "maxTries" loop, when strategy returns number of "maxSameNodes" corresponding node IDs
    • cleanup

      protected int cleanup
      Cleanup period time, in SECONDS (0 = disable cleanup process)
    • windowLength

      protected long windowLength
      Length of time-window in MILLISECONDS
    • maxErrors

      protected int maxErrors
      Maximum number of errors in time-window
    • lockTimeout

      protected long lockTimeout
      Half-open timeout in MILLISECONDS
    • serviceRegistry

      protected ServiceRegistry serviceRegistry
    • metrics

      protected Metrics metrics
    • ignoredTypes

      protected Set<Class<? extends Throwable>> ignoredTypes
    • errorCounters

      protected HashMap<EndpointKey, ErrorCounter> errorCounters
    • readLock

      protected final ReentrantReadWriteLock.ReadLock readLock
    • writeLock

      protected final ReentrantReadWriteLock.WriteLock writeLock
    • lastCleanup

      protected long lastCleanup
    • timer

      protected volatile ScheduledFuture<?> timer
      Cancelable timer
  • Constructor Details

    • CircuitBreaker

      public CircuitBreaker()
  • Method Details

    • started

      public void started(ServiceBroker broker) throws Exception
      Specified by:
      started in interface MoleculerLifecycle
      Overrides:
      started in class DefaultServiceInvoker
      Throws:
      Exception
    • stopped

      public void stopped()
      Specified by:
      stopped in interface MoleculerLifecycle
      Overrides:
      stopped in class MoleculerComponent
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • call

      protected io.datatree.Promise call(Context ctx, String targetID, int remaining)
      Overrides:
      call in class DefaultServiceInvoker
    • getErrorCounter

      protected ErrorCounter getErrorCounter(EndpointKey endpointKey)
    • onError

      protected void onError(ErrorCounter errorCounter, EndpointKey endpointKey, Throwable cause)
    • addIgnoredType

      public void addIgnoredType(Class<? extends Throwable> type)
    • removeIgnoredType

      public void removeIgnoredType(Class<? extends Throwable> type)
    • getIgnoredTypes

      public Set<Class<? extends Throwable>> getIgnoredTypes()
    • setIgnoredTypes

      public void setIgnoredTypes(Set<Class<? extends Throwable>> ignoredTypes)
    • getMaxTries

      public int getMaxTries()
    • setMaxTries

      public void setMaxTries(int maxTries)
    • getMaxSameNodes

      public int getMaxSameNodes()
    • setMaxSameNodes

      public void setMaxSameNodes(int maxSameNodes)
    • getCleanup

      public int getCleanup()
    • setCleanup

      public void setCleanup(int cleanup)
    • getWindowLength

      public long getWindowLength()
    • setWindowLength

      public void setWindowLength(long windowLength)
    • getMaxErrors

      public int getMaxErrors()
    • setMaxErrors

      public void setMaxErrors(int maxErrors)
    • getLockTimeout

      public long getLockTimeout()
    • setLockTimeout

      public void setLockTimeout(long lockTimeout)