Class RecoveryConfig
This class defines thresholds and policies for when and how automatic recovery should be triggered. Recovery involves clearing the database directory and re-downloading fresh database files.
Recovery Triggers
Recovery can be triggered by various error conditions:
- Initialization failures - Service fails to start N times consecutively
- Lookup errors - Database returns errors for N consecutive lookups
- Download failures - Download fails after all retry attempts
- Database corruption - Database file is detected as corrupted
Recovery Actions
When recovery is triggered, the configured action determines behavior:
RecoveryConfig.RecoveryAction.AUTOMATIC- Immediately attempt recoveryRecoveryConfig.RecoveryAction.NOTIFY_ONLY- Fire event but don't auto-recoverRecoveryConfig.RecoveryAction.DISABLE_SERVICE- Disable service until manual intervention
Usage Example
RecoveryConfig config = RecoveryConfig.builder()
.recoveryAction(RecoveryAction.AUTOMATIC)
.initFailureThreshold(3)
.lookupErrorThreshold(20)
.recoverOnDownloadFailure(true)
.recoverOnCorruption(true)
.maxAutoRecoveryAttempts(3)
.autoRecoveryCooldownMinutes(60)
.build();
IP2LocationManager.getInstance().setRecoveryConfig(config);
Default Configuration
The default configuration uses RecoveryConfig.RecoveryAction.NOTIFY_ONLY with conservative thresholds. To enable automatic recovery, explicitly set the recovery action to RecoveryConfig.RecoveryAction.AUTOMATIC.
- Author:
- Christopher Mindus
- See Also:
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creatingRecoveryConfiginstances.static enumActions to take when recovery conditions are met.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault cooldown between automatic recovery attempts (minutes).static final intDefault threshold for consecutive initialization failures.static final intDefault threshold for consecutive lookup errors.static final intDefault maximum automatic recovery attempts.Method Summary
Modifier and TypeMethodDescriptionstatic RecoveryConfigReturns a configuration for fully automatic recovery.static RecoveryConfig.Builderbuilder()Creates a new builder for RecoveryConfig.static RecoveryConfigdefaults()Returns the default configuration (notify only, no auto-recovery).intReturns the cooldown period between recovery attempts.intReturns the threshold for consecutive initialization failures.intReturns the threshold for consecutive lookup errors.intReturns the maximum number of automatic recovery attempts.Returns the action to take when recovery is triggered.booleanReturns whether automatic recovery is enabled.booleanReturns whether to notify listeners on transient errors.booleanReturns whether to trigger recovery on database corruption.booleanReturns whether to trigger recovery after download failures.static RecoveryConfigstrict()Returns a strict configuration that disables service on errors.toString()
Field Details
DEFAULT_INIT_FAILURE_THRESHOLD
public static final int DEFAULT_INIT_FAILURE_THRESHOLDDefault threshold for consecutive initialization failures.- See Also:
DEFAULT_LOOKUP_ERROR_THRESHOLD
public static final int DEFAULT_LOOKUP_ERROR_THRESHOLDDefault threshold for consecutive lookup errors.- See Also:
DEFAULT_MAX_AUTO_RECOVERY_ATTEMPTS
public static final int DEFAULT_MAX_AUTO_RECOVERY_ATTEMPTSDefault maximum automatic recovery attempts.- See Also:
DEFAULT_AUTO_RECOVERY_COOLDOWN_MINUTES
public static final int DEFAULT_AUTO_RECOVERY_COOLDOWN_MINUTESDefault cooldown between automatic recovery attempts (minutes).- See Also:
Method Details
builder
Creates a new builder for RecoveryConfig.- Returns:
- A new builder instance
defaults
Returns the default configuration (notify only, no auto-recovery).- Returns:
- The default RecoveryConfig
automatic
Returns a configuration for fully automatic recovery.This preset enables automatic recovery with sensible defaults for production servers.
- Returns:
- A RecoveryConfig with automatic recovery enabled
strict
Returns a strict configuration that disables service on errors.This preset is for environments where geolocation failures should prevent dependent operations from continuing.
- Returns:
- A RecoveryConfig that disables service on errors
getRecoveryAction
Returns the action to take when recovery is triggered.- Returns:
- The recovery action
getInitFailureThreshold
public int getInitFailureThreshold()Returns the threshold for consecutive initialization failures.Recovery is triggered after this many consecutive failures to initialize the service.
- Returns:
- The init failure threshold
getLookupErrorThreshold
public int getLookupErrorThreshold()Returns the threshold for consecutive lookup errors.Recovery is triggered after this many consecutive lookups return
GeoLocation.Status.DB_ERROR.- Returns:
- The lookup error threshold
isRecoverOnDownloadFailure
public boolean isRecoverOnDownloadFailure()Returns whether to trigger recovery after download failures.When enabled, recovery is triggered if database download fails after all retry attempts are exhausted.
- Returns:
trueif recovery on download failure is enabled
isRecoverOnCorruption
public boolean isRecoverOnCorruption()Returns whether to trigger recovery on database corruption.When enabled, recovery is triggered immediately when database corruption is detected (invalid format, failed integrity check, etc.).
- Returns:
trueif recovery on corruption is enabled
getMaxAutoRecoveryAttempts
public int getMaxAutoRecoveryAttempts()Returns the maximum number of automatic recovery attempts.After this many failed recovery attempts, the service will stop trying and require manual intervention.
- Returns:
- Maximum auto-recovery attempts
getAutoRecoveryCooldownMinutes
public int getAutoRecoveryCooldownMinutes()Returns the cooldown period between recovery attempts.After a failed recovery attempt, the service will wait this many minutes before trying again.
- Returns:
- Cooldown period in minutes
isNotifyOnTransientErrors
public boolean isNotifyOnTransientErrors()Returns whether to notify listeners on transient errors.Transient errors (network issues, temporary server errors) may resolve on retry. When disabled, these errors are logged but don't trigger listener notifications.
- Returns:
trueif transient error notifications are enabled
isAutoRecoveryEnabled
public boolean isAutoRecoveryEnabled()Returns whether automatic recovery is enabled.- Returns:
trueif recovery action is AUTOMATIC
toString