Class RedisQueueCircuitBreakerStorage
- java.lang.Object
-
- org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.RedisQueueCircuitBreakerStorage
-
- All Implemented Interfaces:
QueueCircuitBreakerStorage
public class RedisQueueCircuitBreakerStorage extends Object implements QueueCircuitBreakerStorage
Redis based implementation of theQueueCircuitBreakerStorageinterface.- Author:
- https://github.com/mcweba [Marc-Andre Weber]
-
-
Field Summary
Fields Modifier and Type Field Description static StringFIELD_CIRCUITstatic StringFIELD_FAILRATIOstatic StringFIELD_STATEstatic StringSTORAGE_ALL_CIRCUITSstatic StringSTORAGE_HALFOPEN_CIRCUITSstatic StringSTORAGE_INFOS_SUFFIXstatic StringSTORAGE_OPEN_CIRCUITSstatic StringSTORAGE_PREFIXstatic StringSTORAGE_QUEUES_SUFFIXstatic StringSTORAGE_QUEUES_TO_UNLOCK
-
Constructor Summary
Constructors Constructor Description RedisQueueCircuitBreakerStorage(io.vertx.redis.client.RedisAPI redisAPI)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.vertx.core.Future<Void>closeAllCircuits()Closes all non-closed circuits.io.vertx.core.Future<Void>closeAndRemoveCircuit(PatternAndCircuitHash patternAndCircuitHash)Closes the circuit and removes all circuit information from storage.io.vertx.core.Future<Void>closeCircuit(PatternAndCircuitHash patternAndCircuitHash)Closes the circuit.io.vertx.core.Future<io.vertx.core.json.JsonObject>getAllCircuits()Get the information (status, failRatio and circuit) of all circuits.io.vertx.core.Future<io.vertx.core.json.JsonObject>getQueueCircuitInformation(String circuitHash)Get the information (status, failRatio and circuit) of the circuit represented by the provided circuitHash.io.vertx.core.Future<QueueCircuitState>getQueueCircuitState(String circuitHash)Get the actualQueueCircuitStateof the provided circuitHash.io.vertx.core.Future<QueueCircuitState>getQueueCircuitState(PatternAndCircuitHash patternAndCircuitHash)Get the actualQueueCircuitStateof the provided patternAndCircuitHash object.io.vertx.core.Future<Void>lockQueue(String queueName, PatternAndCircuitHash patternAndCircuitHash)Mark the queueName as a locked queue of the circuit representing the provided patternAndCircuitHash.io.vertx.core.Future<String>popQueueToUnlock()Get the next queue to unlock.io.vertx.core.Future<Void>reOpenCircuit(PatternAndCircuitHash patternAndCircuitHash)Re-Opens the (half-open) circuit again.io.vertx.core.Future<Long>setOpenCircuitsToHalfOpen()Changes the status of all circuits having a status equalsQueueCircuitState.OPENtoQueueCircuitState.HALF_OPEN.io.vertx.core.Future<io.vertx.redis.client.Response>unlockSampleQueues()Get a list of sample queues of all circuits having a status equalsQueueCircuitState.HALF_OPEN.io.vertx.core.Future<UpdateStatisticsResult>updateStatistics(PatternAndCircuitHash patternAndCircuitHash, String uniqueRequestID, long timestamp, int errorThresholdPercentage, long entriesMaxAgeMS, long minQueueSampleCount, long maxQueueSampleCount, QueueResponseType queueResponseType)Updates the statistics of the corresponding circuit based on the provided patternAndCircuitHash.
-
-
-
Field Detail
-
STORAGE_PREFIX
public static final String STORAGE_PREFIX
- See Also:
- Constant Field Values
-
STORAGE_INFOS_SUFFIX
public static final String STORAGE_INFOS_SUFFIX
- See Also:
- Constant Field Values
-
STORAGE_QUEUES_SUFFIX
public static final String STORAGE_QUEUES_SUFFIX
- See Also:
- Constant Field Values
-
STORAGE_ALL_CIRCUITS
public static final String STORAGE_ALL_CIRCUITS
- See Also:
- Constant Field Values
-
STORAGE_HALFOPEN_CIRCUITS
public static final String STORAGE_HALFOPEN_CIRCUITS
- See Also:
- Constant Field Values
-
STORAGE_OPEN_CIRCUITS
public static final String STORAGE_OPEN_CIRCUITS
- See Also:
- Constant Field Values
-
STORAGE_QUEUES_TO_UNLOCK
public static final String STORAGE_QUEUES_TO_UNLOCK
- See Also:
- Constant Field Values
-
FIELD_STATE
public static final String FIELD_STATE
- See Also:
- Constant Field Values
-
FIELD_FAILRATIO
public static final String FIELD_FAILRATIO
- See Also:
- Constant Field Values
-
FIELD_CIRCUIT
public static final String FIELD_CIRCUIT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getQueueCircuitState
public io.vertx.core.Future<QueueCircuitState> getQueueCircuitState(PatternAndCircuitHash patternAndCircuitHash)
Description copied from interface:QueueCircuitBreakerStorageGet the actualQueueCircuitStateof the provided patternAndCircuitHash object. When no circuit could be found in the storage,QueueCircuitState.CLOSEDis returned.- Specified by:
getQueueCircuitStatein interfaceQueueCircuitBreakerStorage- Parameters:
patternAndCircuitHash- circuit information- Returns:
- returns the actual
QueueCircuitStateorQueueCircuitState.CLOSEDwhen no circuit was found
-
getQueueCircuitState
public io.vertx.core.Future<QueueCircuitState> getQueueCircuitState(String circuitHash)
Description copied from interface:QueueCircuitBreakerStorageGet the actualQueueCircuitStateof the provided circuitHash. When no circuit could be found in the storage,QueueCircuitState.CLOSEDis returned.- Specified by:
getQueueCircuitStatein interfaceQueueCircuitBreakerStorage- Parameters:
circuitHash- the hash representing the circuit- Returns:
- returns the actual
QueueCircuitStateorQueueCircuitState.CLOSEDwhen no circuit was found
-
getQueueCircuitInformation
public io.vertx.core.Future<io.vertx.core.json.JsonObject> getQueueCircuitInformation(String circuitHash)
Description copied from interface:QueueCircuitBreakerStorageGet the information (status, failRatio and circuit) of the circuit represented by the provided circuitHash.- Specified by:
getQueueCircuitInformationin interfaceQueueCircuitBreakerStorage- Parameters:
circuitHash- the hash representing the circuit to get the informations from- Returns:
- returns a
JsonObjectcontaining the information of the circuit
-
getAllCircuits
public io.vertx.core.Future<io.vertx.core.json.JsonObject> getAllCircuits()
Description copied from interface:QueueCircuitBreakerStorageGet the information (status, failRatio and circuit) of all circuits.- Specified by:
getAllCircuitsin interfaceQueueCircuitBreakerStorage- Returns:
- returns a
JsonObjectcontaining the information of all circuits
-
updateStatistics
public io.vertx.core.Future<UpdateStatisticsResult> updateStatistics(PatternAndCircuitHash patternAndCircuitHash, String uniqueRequestID, long timestamp, int errorThresholdPercentage, long entriesMaxAgeMS, long minQueueSampleCount, long maxQueueSampleCount, QueueResponseType queueResponseType)
Description copied from interface:QueueCircuitBreakerStorageUpdates the statistics of the corresponding circuit based on the provided patternAndCircuitHash.
Updating the statistics includes the following steps:
- Record uniqueRequestID as failed when queueResponseType equals
QueueResponseType.FAILURE - Record uniqueRequestID as success when queueResponseType equals
QueueResponseType.SUCCESS - Calculate failRatio based on fail/success records not older than entriesMaxAgeMS
- Change status of corresponding circuit to 'OPEN' when minQueueSampleCount and errorThresholdPercentage is reached
- Remove oldest fail/success records when maxQueueSampleCount is reached
- Specified by:
updateStatisticsin interfaceQueueCircuitBreakerStorage- Parameters:
patternAndCircuitHash- the information of the circuituniqueRequestID- the unique identifier of the queued requesttimestamp- the current timestamperrorThresholdPercentage- the threshold to change status to 'OPEN' when reachedentriesMaxAgeMS- the maximum age of fail/success records to respect to calculate the failRatiominQueueSampleCount- the minimum amount of records (unique uniqueRequestIDs) to reach before status can be changedmaxQueueSampleCount- the maximum amount of fail/success records to keepqueueResponseType- theQueueResponseTyperepresenting the execution result of the queuedRequest- Returns:
- returns an
UpdateStatisticsResultobject representing the result of the statistics update
- Record uniqueRequestID as failed when queueResponseType equals
-
lockQueue
public io.vertx.core.Future<Void> lockQueue(String queueName, PatternAndCircuitHash patternAndCircuitHash)
Description copied from interface:QueueCircuitBreakerStorageMark the queueName as a locked queue of the circuit representing the provided patternAndCircuitHash.- Specified by:
lockQueuein interfaceQueueCircuitBreakerStorage- Parameters:
queueName- the name of the queuepatternAndCircuitHash- the information of the circuit- Returns:
- returns a void Future when the queue could be successfully marked as locked
-
popQueueToUnlock
public io.vertx.core.Future<String> popQueueToUnlock()
Description copied from interface:QueueCircuitBreakerStorageGet the next queue to unlock. When successful, the queue is removed from the storage.- Specified by:
popQueueToUnlockin interfaceQueueCircuitBreakerStorage- Returns:
- returns a Future holding the name of the next queue or
nullwhen no queue was found
-
closeCircuit
public io.vertx.core.Future<Void> closeCircuit(PatternAndCircuitHash patternAndCircuitHash)
Description copied from interface:QueueCircuitBreakerStorageCloses the circuit.
Closing the circuit includes the following steps:
- Clear statistics of this circuit
- Reset failRatio of this circuit to zero
- Set status of this circuit to 'CLOSED'
- Unlock all queues related to this circuit
- Specified by:
closeCircuitin interfaceQueueCircuitBreakerStorage- Parameters:
patternAndCircuitHash- the information of the circuit- Returns:
- returns a void Future when circuit could be closed successfully.
-
closeAndRemoveCircuit
public io.vertx.core.Future<Void> closeAndRemoveCircuit(PatternAndCircuitHash patternAndCircuitHash)
Description copied from interface:QueueCircuitBreakerStorageCloses the circuit and removes all circuit information from storage.- Specified by:
closeAndRemoveCircuitin interfaceQueueCircuitBreakerStorage- Parameters:
patternAndCircuitHash- the information of the circuit- Returns:
- returns a void Future when circuit could be closed and removed successfully.
-
closeAllCircuits
public io.vertx.core.Future<Void> closeAllCircuits()
Description copied from interface:QueueCircuitBreakerStorageCloses all non-closed circuits.
Closing all non-closed circuits includes the following steps:
- Clear statistics of all non-closed circuits
- Reset failRatio of all non-closed circuits to zero
- Set status of all non-closed circuits to 'CLOSED'
- Unlock all queues related to all non-closed circuits
- Specified by:
closeAllCircuitsin interfaceQueueCircuitBreakerStorage- Returns:
- returns a void Future when all non-closed circuits could be closed successfully.
-
reOpenCircuit
public io.vertx.core.Future<Void> reOpenCircuit(PatternAndCircuitHash patternAndCircuitHash)
Description copied from interface:QueueCircuitBreakerStorageRe-Opens the (half-open) circuit again. Circuits should be re-opened after a sample queue request was not successful.- Specified by:
reOpenCircuitin interfaceQueueCircuitBreakerStorage- Parameters:
patternAndCircuitHash- the information of the circuit- Returns:
- returns a void Future when the circuit could be re-opened successfully
-
setOpenCircuitsToHalfOpen
public io.vertx.core.Future<Long> setOpenCircuitsToHalfOpen()
Description copied from interface:QueueCircuitBreakerStorageChanges the status of all circuits having a status equalsQueueCircuitState.OPENtoQueueCircuitState.HALF_OPEN.- Specified by:
setOpenCircuitsToHalfOpenin interfaceQueueCircuitBreakerStorage- Returns:
- returns a Future holding the amount of circuits updated
-
unlockSampleQueues
public io.vertx.core.Future<io.vertx.redis.client.Response> unlockSampleQueues()
Description copied from interface:QueueCircuitBreakerStorageGet a list of sample queues of all circuits having a status equalsQueueCircuitState.HALF_OPEN. The sample queues are always the queues which have not been unlocked the longest. Each sample queue of each circuit is then updated to be the 'most recently' unlocked queue.- Specified by:
unlockSampleQueuesin interfaceQueueCircuitBreakerStorage- Returns:
- returns a Future holding a list of sample queues to unlock
-
-