Class CircuitBreaker
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.ServiceInvoker
services.moleculer.service.DefaultServiceInvoker
services.moleculer.breaker.CircuitBreaker
- All Implemented Interfaces:
Runnable, MetricConstants, MoleculerLifecycle
Special service invoker with retry logic + circuit breaker.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intCleanup period time, in SECONDS (0 = disable cleanup process)protected HashMap<EndpointKey, ErrorCounter> protected longprotected longHalf-open timeout in MILLISECONDSprotected intMaximum number of errors in time-windowprotected intExit from "maxTries" loop, when strategy returns number of "maxSameNodes" corresponding node IDsprotected intNumber of max triesprotected Metricsprotected final ReentrantReadWriteLock.ReadLockprotected ServiceRegistryprotected ScheduledFuture<?> Cancelable timerprotected longLength of time-window in MILLISECONDSprotected final ReentrantReadWriteLock.WriteLockFields inherited from class DefaultServiceInvoker
eventbus, maxCallLevel, retryLogic, uidGenerator, writeErrorsToLogFields inherited from class MoleculerComponent
broker, logger, nameFields inherited from interface MetricConstants
MOLECULER_CACHER_CLEAN_TIME, MOLECULER_CACHER_CLEAN_TIME_DESC, MOLECULER_CACHER_CLEAN_TOTAL, MOLECULER_CACHER_CLEAN_TOTAL_DESC, MOLECULER_CACHER_DEL_TIME, MOLECULER_CACHER_DEL_TIME_DESC, MOLECULER_CACHER_DEL_TOTAL, MOLECULER_CACHER_DEL_TOTAL_DESC, MOLECULER_CACHER_EXPIRED_TOTAL, MOLECULER_CACHER_EXPIRED_TOTAL_DESC, MOLECULER_CACHER_FOUND_TOTAL, MOLECULER_CACHER_FOUND_TOTAL_DESC, MOLECULER_CACHER_GET_TIME, MOLECULER_CACHER_GET_TIME_DESC, MOLECULER_CACHER_GET_TOTAL, MOLECULER_CACHER_GET_TOTAL_DESC, MOLECULER_CACHER_SET_TIME, MOLECULER_CACHER_SET_TIME_DESC, MOLECULER_CACHER_SET_TOTAL, MOLECULER_CACHER_SET_TOTAL_DESC, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL_DESC, MOLECULER_EVENT_BROADCAST_TOTAL, MOLECULER_EVENT_BROADCAST_TOTAL_DESC, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL_DESC, MOLECULER_EVENT_EMIT_TOTAL, MOLECULER_EVENT_EMIT_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_ACTIVE, MOLECULER_EVENT_RECEIVED_ACTIVE_DESC, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_TIME, MOLECULER_EVENT_RECEIVED_TIME_DESC, MOLECULER_EVENT_RECEIVED_TOTAL, MOLECULER_EVENT_RECEIVED_TOTAL_DESC, MOLECULER_EXECUTOR, MOLECULER_REQUEST_ACTIVE, MOLECULER_REQUEST_ACTIVE_DESC, MOLECULER_REQUEST_ERROR_TOTAL, MOLECULER_REQUEST_ERROR_TOTAL_DESC, MOLECULER_REQUEST_LEVELS, MOLECULER_REQUEST_LEVELS_DESC, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL_DESC, MOLECULER_REQUEST_TIME, MOLECULER_REQUEST_TIME_DESC, MOLECULER_REQUEST_TIMEOUT_TOTAL, MOLECULER_REQUEST_TIMEOUT_TOTAL_DESC, MOLECULER_REQUEST_TOTAL, MOLECULER_REQUEST_TOTAL_DESC, MOLECULER_SCHEDULER, MOLECULER_TRANSIT_CONNECTED, MOLECULER_TRANSIT_CONNECTED_DESC, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL_DESC, MOLECULER_TRANSIT_REQUESTS_ACTIVE, MOLECULER_TRANSIT_REQUESTS_ACTIVE_DESC, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL_DESC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIgnoredType(Class<? extends Throwable> type) protected io.datatree.Promiseintprotected ErrorCountergetErrorCounter(EndpointKey endpointKey) longintintintlongprotected voidonError(ErrorCounter errorCounter, EndpointKey endpointKey, Throwable cause) voidremoveIgnoredType(Class<? extends Throwable> type) voidrun()voidsetCleanup(int cleanup) voidsetIgnoredTypes(Set<Class<? extends Throwable>> ignoredTypes) voidsetLockTimeout(long lockTimeout) voidsetMaxErrors(int maxErrors) voidsetMaxSameNodes(int maxSameNodes) voidsetMaxTries(int maxTries) voidsetWindowLength(long windowLength) voidstarted(ServiceBroker broker) voidstopped()Methods inherited from class DefaultServiceInvoker
call, getMaxCallLevel, getRetryLogic, isWriteErrorsToLog, retry, setMaxCallLevel, setRetryLogic, setWriteErrorsToLogMethods inherited from class MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
maxTries
protected int maxTriesNumber of max tries -
maxSameNodes
protected int maxSameNodesExit from "maxTries" loop, when strategy returns number of "maxSameNodes" corresponding node IDs -
cleanup
protected int cleanupCleanup period time, in SECONDS (0 = disable cleanup process) -
windowLength
protected long windowLengthLength of time-window in MILLISECONDS -
maxErrors
protected int maxErrorsMaximum number of errors in time-window -
lockTimeout
protected long lockTimeoutHalf-open timeout in MILLISECONDS -
serviceRegistry
-
metrics
-
ignoredTypes
-
errorCounters
-
readLock
-
writeLock
-
lastCleanup
protected long lastCleanup -
timer
Cancelable timer
-
-
Constructor Details
-
CircuitBreaker
public CircuitBreaker()
-
-
Method Details
-
started
- Specified by:
startedin interfaceMoleculerLifecycle- Overrides:
startedin classDefaultServiceInvoker- Throws:
Exception
-
stopped
public void stopped()- Specified by:
stoppedin interfaceMoleculerLifecycle- Overrides:
stoppedin classMoleculerComponent
-
run
-
call
- Overrides:
callin classDefaultServiceInvoker
-
getErrorCounter
-
onError
-
addIgnoredType
-
removeIgnoredType
-
getIgnoredTypes
-
setIgnoredTypes
-
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)
-