Class IP2LocationAdminConfig

java.lang.Object
com.iizix.server.geo.ip2location.IP2LocationAdminConfig

public final class IP2LocationAdminConfig extends Object
The configuration of the IP2Location service as an administrator edits it: every control of the NetPhantom IP2Location page and of its Recovery Settings dialog, as one immutable value with a builder. Ported from co.mindus.ip2location.ui.IP2LocationConfig; where NetPhantom loads from and saves to server.ini, this class reads ServerSettings and writes them back (fromSettings(ServerSettings), applyTo(ServerSettings)), with the same defaults and the same ranges as ServerSettings' clamped getters.

The library types stay inside the server bundle: the database tier and the recovery action are exposed as IP2LocationAdminConfig.DatabaseInfo and IP2LocationAdminConfig.RecoveryMode, so that an application such as ServerAdmin never imports co.mindus.ip2location.

The token. getToken() is the download token in clear, as the server holds it in memory; a UI never shows it. applyTo(ServerSettings) stores a non-empty token as the PasswordProp ServerSettings.IP2LOCATION_TOKEN marked secret, so that the server's save writes it into the secrets store and never into the configuration file; without a secrets context the token is kept in memory only and the caller is told (IP2LocationAdminConfig.TokenOutcome.NOT_STORED_NO_SECRETS_CONTEXT), the rule of ServerAdmin's Mail page.

Author:
Christopher Mindus
  • Field Details

  • Method Details

    • fromSettings

      public static IP2LocationAdminConfig fromSettings(ServerSettings settings)
      Reads the configuration from the server settings, through the typed getters of ServerSettings: an unknown tier or action reads as its default, an integer outside its range as the bound, exactly as the running service sees them.
      Parameters:
      settings - The server settings.
      Returns:
      The configuration.
    • applyTo

      Writes the configuration into the server settings, every setting of the NetPhantom [IP2Location] section one to one. The caller validates first (validate()), then flushes the configuration file and reconfigures the running service (IP2LocationAdmin.apply(ServerSettings)).

      The token: a non-empty token that differs from the stored one replaces it as a PasswordProp marked secret when the settings have a secrets context (ServerSettings.getSecretsContext()); without one it is set in memory and not marked, and the outcome says so. An empty token leaves the stored token as it is.

      Parameters:
      settings - The server settings.
      Returns:
      What happened with the token.
      Throws:
      PropException - For property errors.
    • validate

      public ValidationResult validate()
      Validates the configuration as the NetPhantom page did before applying it: with the service enabled the token and the database directory are required and the tier must be known; the four recovery numbers must be inside their ranges whatever the switch. A disabled service with a bad recovery number is still refused, because the numbers are saved.
      Returns:
      The result; ValidationResult.isValid() says whether the configuration can be applied.
    • getDatabases

      public static List<IP2LocationAdminConfig.DatabaseInfo> getDatabases()
      Lists the database tiers, in the order of the library's Database enum: the lines of the Database combo box.
      Returns:
      The tiers, never empty.
    • findDatabase

      public static IP2LocationAdminConfig.DatabaseInfo findDatabase(String name)
      Finds a database tier by name.
      Parameters:
      name - The tier name, or null.
      Returns:
      The tier, or null for an unknown or null name.
    • isEnabled

      public boolean isEnabled()
      Checks if the service is enabled.
      Returns:
      The switch.
    • getToken

      public String getToken()
      Gets the download token.
      Returns:
      The token trimmed, empty for none; never shown to a user.
    • getDatabasePath

      public String getDatabasePath()
      Gets the database directory.
      Returns:
      The directory, relative the server's current directory or absolute, trimmed.
    • getDatabase

      public String getDatabase()
      Gets the database tier name.
      Returns:
      The name, e.g. "DB11_LITE".
    • getIPMode

      public IPMode getIPMode()
      Gets the IP mode.
      Returns:
      The mode.
    • isMemoryMapped

      public boolean isMemoryMapped()
      Checks if memory-mapped file access is used.
      Returns:
      The flag.
    • getRecoveryMode

      public IP2LocationAdminConfig.RecoveryMode getRecoveryMode()
      Gets the recovery mode.
      Returns:
      The mode.
    • getInitFailureThreshold

      public int getInitFailureThreshold()
      Gets the consecutive initialization failures before the recovery action.
      Returns:
      The threshold.
    • getLookupErrorThreshold

      public int getLookupErrorThreshold()
      Gets the consecutive lookup errors before the recovery action.
      Returns:
      The threshold.
    • getMaxAutoRecoveryAttempts

      public int getMaxAutoRecoveryAttempts()
      Gets the maximum automatic recovery attempts.
      Returns:
      The count.
    • getRecoveryCooldownMinutes

      public int getRecoveryCooldownMinutes()
      Gets the cooldown between automatic recovery attempts.
      Returns:
      The minutes.
    • isRecoverOnDownloadFailure

      public boolean isRecoverOnDownloadFailure()
      Checks if a download failure triggers the recovery.
      Returns:
      The flag.
    • isRecoverOnCorruption

      public boolean isRecoverOnCorruption()
      Checks if a database corruption triggers the recovery.
      Returns:
      The flag.
    • isNotifyOnTransientErrors

      public boolean isNotifyOnTransientErrors()
      Checks if transient errors are notified.
      Returns:
      The flag.
    • equals

      public boolean equals(Object o)
      --- Object ---
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      The configuration without the token.
      Overrides:
      toString in class Object
    • builder

      public static IP2LocationAdminConfig.Builder builder()
      Creates a builder with the defaults of every setting.
      Returns:
      The builder.
    • toBuilder

      public IP2LocationAdminConfig.Builder toBuilder()
      Creates a builder with this configuration's values.
      Returns:
      The builder.