public interface IServiceStatusListener
IP2LocationService
and IP2LocationManager.
Implement this interface to receive notifications about service lifecycle events, database updates, configuration changes, and error conditions.
IServiceStatusListener listener = new IServiceStatusListener() {
@Override
public void onDatabaseUpdated(boolean ipv4, boolean ipv6) {
System.out.println("Database updated: IPv4=" + ipv4 + ", IPv6=" + ipv6);
}
@Override
public void onDownloadStarted() {
System.out.println("Download started...");
}
@Override
public void onDownloadCompleted(boolean success) {
System.out.println("Download " + (success ? "succeeded" : "failed"));
}
@Override
public void onStatusChanged(String newStatus) {
SwingUtilities.invokeLater(() -> statusLabel.setText(newStatus));
}
@Override
public void onRecoveryRecommended(String reason, boolean autoRecoveryTriggered) {
if (!autoRecoveryTriggered) {
// Show dialog to user
SwingUtilities.invokeLater(() -> showRecoveryDialog(reason));
}
}
@Override
public void onError(ErrorType type, String message, Throwable error) {
logger.error("IP2Location error [" + type + "]: " + message, error);
}
};
IP2LocationManager manager = IP2LocationManager.getInstance();
manager.addStatusListener(listener);
Listener methods are called from background threads. Implementations must
be thread-safe if they access shared state. For UI updates, use appropriate
mechanisms like SwingUtilities.invokeLater() or Platform.runLater().
Avoid performing long-running operations in listener callbacks as they may
block the update scheduler.
All methods have empty default implementations, so you only need to override the events you're interested in.
| Modifier and Type | Interface and Description |
|---|---|
static class |
IServiceStatusListener.ErrorType
Categories of errors that can occur in the IP2Location service.
|
| Modifier and Type | Method and Description |
|---|---|
default void |
onDatabaseLoaded(LocalDate date,
boolean isIPv6)
Called when a database file has been loaded into memory.
|
default void |
onDatabaseUpdated(boolean ipv4Updated,
boolean ipv6Updated)
Called when databases are reloaded into memory.
|
default void |
onDownloadCompleted(boolean success)
Called when a database download completes.
|
default void |
onDownloadStarted()
Called when a database download is about to start.
|
default void |
onError(IServiceStatusListener.ErrorType type,
String message,
Throwable error)
Called when an error occurs in the service.
|
default void |
onInitialized(boolean success,
Throwable error)
Called when service initialization completes.
|
default void |
onReconfigurationCompleted(boolean success,
Throwable error)
Called when the manager completes reconfiguration.
|
default void |
onReconfigurationStarted()
Called when the manager starts reconfiguration.
|
default void |
onRecoveryCompleted(boolean success,
Throwable error)
Called when automatic recovery completes.
|
default void |
onRecoveryRecommended(String reason,
boolean autoRecoveryTriggered)
Called when recovery is recommended or automatic recovery is triggered.
|
default void |
onServiceDisposed()
Called when the service is disposed.
|
default void |
onStatusChanged(String newStatus)
Called when the status description changes.
|
default void |
onUpdateCheckPerformed(boolean downloadNeeded)
Called periodically during scheduled update checks.
|
default void onInitialized(boolean success,
Throwable error)
This is called once when the service finishes its initial startup, whether successful or not.
success - true if initialization succeeded, false if it failederror - The error that occurred, or null if successfuldefault void onServiceDisposed()
This is called when IP2LocationService.dispose() is invoked,
either directly or through the manager during reconfiguration.
default void onDownloadStarted()
This is called before each download attempt, including automatic scheduled updates and forced updates.
default void onDownloadCompleted(boolean success)
This is called after each download attempt finishes, whether successful or not.
success - true if at least one database was downloadeddefault void onDatabaseUpdated(boolean ipv4Updated,
boolean ipv6Updated)
This is called after new database files are loaded, either from a fresh download or when the service starts with existing files.
ipv4Updated - true if the IPv4 database was reloadedipv6Updated - true if the IPv6 database was reloadeddefault void onDatabaseLoaded(LocalDate date, boolean isIPv6)
This is called after each individual database file is successfully opened, during initial load, reconfiguration, download, or recovery. It provides the publication date embedded in the database file.
date - The publication date of the loaded database, or null
if the date could not be determinedisIPv6 - true if the IPv6 database was loaded,
false for IPv4default void onUpdateCheckPerformed(boolean downloadNeeded)
This is called each time the scheduler runs its update check, regardless of whether a download is actually performed.
downloadNeeded - true if a download was determined to be neededdefault void onReconfigurationStarted()
This is called at the beginning of a reconfiguration operation, before the new service is created.
default void onReconfigurationCompleted(boolean success,
Throwable error)
This is called after reconfiguration finishes, whether successful or not. The old service has been disposed at this point.
success - true if the new service initialized successfullyerror - The error that occurred, or null if successfulIP2LocationManager.reconfigure(IP2LocationService.Builder)default void onStatusChanged(String newStatus)
This is called whenever any component of the status changes, such as: initialization completing, downloads starting/stopping, databases loading, reconfiguration events, etc.
The status string is the same format returned by
IP2LocationManager.getStatusDescription() or
IP2LocationService.getStatusDescription().
@Override
public void onStatusChanged(String newStatus) {
SwingUtilities.invokeLater(() -> statusLabel.setText(newStatus));
}
newStatus - The new status description stringIP2LocationManager.getStatusDescription(),
IP2LocationService.getStatusDescription()default void onError(IServiceStatusListener.ErrorType type, String message, Throwable error)
This provides detailed error information for logging, monitoring, or automated handling. The error type can be used to determine appropriate responses:
IServiceStatusListener.ErrorType.isRecoverable() - Recovery might helpIServiceStatusListener.ErrorType.requiresUserAction() - User intervention neededIServiceStatusListener.ErrorType.isTransient() - May resolve on retry
@Override
public void onError(ErrorType type, String message, Throwable error) {
// Log the error
logger.error("IP2Location [" + type + "]: " + message, error);
// Alert administrator for critical errors
if (type.requiresUserAction()) {
alertAdmin("IP2Location requires attention: " + message);
}
}
type - The category of errormessage - A human-readable error messageerror - The underlying exception, or null if not applicableIServiceStatusListener.ErrorTypedefault void onRecoveryRecommended(String reason, boolean autoRecoveryTriggered)
This event is fired when error thresholds are exceeded and recovery action should be considered. The event indicates whether automatic recovery has been triggered (if enabled) or if manual intervention is needed.
@Override
public void onRecoveryRecommended(String reason, boolean autoRecoveryTriggered) {
if (autoRecoveryTriggered) {
logger.info("Automatic recovery initiated: " + reason);
} else {
// Prompt user for action
SwingUtilities.invokeLater(() -> {
boolean confirmed = showConfirmDialog(
"Recovery Recommended",
reason + "\n\nAttempt recovery now?");
if (confirmed) {
manager.triggerRecovery();
}
});
}
}
reason - Human-readable explanation of why recovery is recommendedautoRecoveryTriggered - true if automatic recovery has been initiated,
false if manual action is neededIP2LocationManager.isRecoveryRecommended(),
IP2LocationManager.triggerRecovery()default void onRecoveryCompleted(boolean success,
Throwable error)
This is only called when automatic recovery is enabled and was triggered. It indicates whether the recovery attempt succeeded.
success - true if recovery succeeded and service is operationalerror - The error that occurred during recovery, or null if successfulPhantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.