Class RecoveryConfig

java.lang.Object
co.mindus.ip2location.RecoveryConfig

public final class RecoveryConfig extends Object
Configuration for automatic recovery behavior in IP2Location services.

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:

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:
  • Field Details

    • DEFAULT_INIT_FAILURE_THRESHOLD

      public static final int DEFAULT_INIT_FAILURE_THRESHOLD
      Default threshold for consecutive initialization failures.
      See Also:
    • DEFAULT_LOOKUP_ERROR_THRESHOLD

      public static final int DEFAULT_LOOKUP_ERROR_THRESHOLD
      Default threshold for consecutive lookup errors.
      See Also:
    • DEFAULT_MAX_AUTO_RECOVERY_ATTEMPTS

      public static final int DEFAULT_MAX_AUTO_RECOVERY_ATTEMPTS
      Default maximum automatic recovery attempts.
      See Also:
    • DEFAULT_AUTO_RECOVERY_COOLDOWN_MINUTES

      public static final int DEFAULT_AUTO_RECOVERY_COOLDOWN_MINUTES
      Default cooldown between automatic recovery attempts (minutes).
      See Also:
  • Method Details

    • builder

      public static RecoveryConfig.Builder builder()
      Creates a new builder for RecoveryConfig.
      Returns:
      A new builder instance
    • defaults

      public static RecoveryConfig defaults()
      Returns the default configuration (notify only, no auto-recovery).
      Returns:
      The default RecoveryConfig
    • automatic

      public static 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

      public static RecoveryConfig 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

      public RecoveryConfig.RecoveryAction 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:
      true if 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:
      true if 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:
      true if transient error notifications are enabled
    • isAutoRecoveryEnabled

      public boolean isAutoRecoveryEnabled()
      Returns whether automatic recovery is enabled.
      Returns:
      true if recovery action is AUTOMATIC
    • toString

      public String toString()
      Overrides:
      toString in class Object