Class IP2LocationAdminConfig
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
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe builder of a configuration; starts with the defaults of every setting, which are the defaults ofServerSettingsand of NetPhantom's[IP2Location]section.static final recordOne database tier of IP2Location LITE as the Database combo box lists it.static enumThe recovery action when the error thresholds are exceeded, the three radio buttons of the Recovery Settings dialog; one to one withRecoveryConfig.RecoveryAction.static enumWhatapplyTo(ServerSettings)did with the token.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the database tier used when the configured one is unknown:"DB11_LITE".static final StringThe default database directory,ServerSettings.DEFAULT_IP2LOCATION_DB_PATH.static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final StringThe field names of the validation messages, seeValidationResult.Message.field().static final intThe range of the initialization failure threshold: 1..100 (the clamp ofServerSettings.getIP2LocationInitFailureThreshold()).static final intThe range of the lookup error threshold: 1..1000.static final intThe range of the maximum automatic recovery attempts: 1..10.static final intThe range of the recovery cooldown in minutes: 5..1440 (a day).static final intThe range of the initialization failure threshold: 1..100 (the clamp ofServerSettings.getIP2LocationInitFailureThreshold()).static final intThe range of the lookup error threshold: 1..1000.static final intThe range of the maximum automatic recovery attempts: 1..10.static final intThe range of the recovery cooldown in minutes: 5..1440 (a day).Method Summary
Modifier and TypeMethodDescriptionapplyTo(ServerSettings settings) Writes the configuration into the server settings, every setting of the NetPhantom[IP2Location]section one to one.builder()Creates a builder with the defaults of every setting.boolean--- Object ---findDatabase(String name) Finds a database tier by name.static IP2LocationAdminConfigfromSettings(ServerSettings settings) Reads the configuration from the server settings, through the typed getters ofServerSettings: an unknown tier or action reads as its default, an integer outside its range as the bound, exactly as the running service sees them.Gets the database tier name.Gets the database directory.Lists the database tiers, in the order of the library'sDatabaseenum: the lines of the Database combo box.intGets the consecutive initialization failures before the recovery action.Gets the IP mode.intGets the consecutive lookup errors before the recovery action.intGets the maximum automatic recovery attempts.intGets the cooldown between automatic recovery attempts.Gets the recovery mode.getToken()Gets the download token.inthashCode()booleanChecks if the service is enabled.booleanChecks if memory-mapped file access is used.booleanChecks if transient errors are notified.booleanChecks if a database corruption triggers the recovery.booleanChecks if a download failure triggers the recovery.Creates a builder with this configuration's values.toString()The configuration without the token.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.
Field Details
DEFAULT_DATABASE
The name of the database tier used when the configured one is unknown:"DB11_LITE".DEFAULT_DATABASE_PATH
The default database directory,ServerSettings.DEFAULT_IP2LOCATION_DB_PATH.- See Also:
MIN_INIT_FAILURE_THRESHOLD
public static final int MIN_INIT_FAILURE_THRESHOLDThe range of the initialization failure threshold: 1..100 (the clamp ofServerSettings.getIP2LocationInitFailureThreshold()).- See Also:
MAX_INIT_FAILURE_THRESHOLD
public static final int MAX_INIT_FAILURE_THRESHOLDThe range of the initialization failure threshold: 1..100 (the clamp ofServerSettings.getIP2LocationInitFailureThreshold()).- See Also:
MIN_LOOKUP_ERROR_THRESHOLD
public static final int MIN_LOOKUP_ERROR_THRESHOLDThe range of the lookup error threshold: 1..1000.- See Also:
MAX_LOOKUP_ERROR_THRESHOLD
public static final int MAX_LOOKUP_ERROR_THRESHOLDThe range of the lookup error threshold: 1..1000.- See Also:
MIN_MAX_AUTO_RECOVERY_ATTEMPTS
public static final int MIN_MAX_AUTO_RECOVERY_ATTEMPTSThe range of the maximum automatic recovery attempts: 1..10.- See Also:
MAX_MAX_AUTO_RECOVERY_ATTEMPTS
public static final int MAX_MAX_AUTO_RECOVERY_ATTEMPTSThe range of the maximum automatic recovery attempts: 1..10.- See Also:
MIN_RECOVERY_COOLDOWN_MINUTES
public static final int MIN_RECOVERY_COOLDOWN_MINUTESThe range of the recovery cooldown in minutes: 5..1440 (a day).- See Also:
MAX_RECOVERY_COOLDOWN_MINUTES
public static final int MAX_RECOVERY_COOLDOWN_MINUTESThe range of the recovery cooldown in minutes: 5..1440 (a day).- See Also:
FIELD_TOKEN
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
FIELD_DATABASE_PATH
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
FIELD_DATABASE
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
FIELD_INIT_FAILURE_THRESHOLD
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
FIELD_LOOKUP_ERROR_THRESHOLD
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
FIELD_MAX_AUTO_RECOVERY_ATTEMPTS
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
FIELD_RECOVERY_COOLDOWN_MINUTES
The field names of the validation messages, seeValidationResult.Message.field().- See Also:
Method Details
fromSettings
Reads the configuration from the server settings, through the typed getters ofServerSettings: 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
PasswordPropmarked 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
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
Lists the database tiers, in the order of the library'sDatabaseenum: the lines of the Database combo box.- Returns:
- The tiers, never empty.
findDatabase
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
Gets the download token.- Returns:
- The token trimmed, empty for none; never shown to a user.
getDatabasePath
Gets the database directory.- Returns:
- The directory, relative the server's current directory or absolute, trimmed.
getDatabase
getIPMode
isMemoryMapped
public boolean isMemoryMapped()Checks if memory-mapped file access is used.- Returns:
- The flag.
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
hashCode
toString
builder
Creates a builder with the defaults of every setting.- Returns:
- The builder.
toBuilder
Creates a builder with this configuration's values.- Returns:
- The builder.