Class IP2LocationModule
- All Implemented Interfaces:
IServerModule<Object>
co.mindus.ip2location library. Added by ServerShell.onWorkerStarted right after the Push Notification module, which reaches initialize(IServer) through ServerShell.addModule.What the switches do.
ServerSettings.IP2LOCATION_ENABLED(default off):initialize(IServer)configures theIP2LocationManagerasynchronously from the settings - the database directory, the LITE database tier, IPv4 or IPv4+IPv6, memory mapping, the recovery configuration, the download token - so the server starts without waiting for a download.onServerReady(IServer)then registers the region location providers with IP2Location first, which makes it the default provider ofRegionLocationService; lookups stay on the server. Without the switch nothing of this happens, exactly as before this module existed: no provider is registered in production.ServerSettings.GEO_WEB_PROVIDERS(default off): the web providers GeoPlugin, IPStack and IPWhoIs are registered too (after IP2Location when that is enabled); a lookup through one of them sends the client's IP address to that web service.ServerSettings.GEO_SESSION_LOG(default off):SessionGeoLoggerwrites the geolocation of every client session at connect, reconnect and disconnect, using whichever provider is the default. It is read at every event, not here.
The module exposes no WebSocket end point. dispose() shuts the manager down; the providers are disposed of by ServerShell.dispose through RegionLocationService.shutdown(), which only that class may call.
Live reconfiguration. ServerAdmin's IP2Location dialog writes the settings and calls
invalid reference
#reconfigure(ServerSettings)IP2LocationAdmin), which hands the manager a new builder as NetPhantom's bootstrap does on a server reload: the manager hot-swaps the service, or configures it for the first time when the server started with the switch off. The two event logs of the library - the text log of EventLogManager and the JSON-lines history of IP2LocationEventLog - live beside the databases under their own names.Cluster index. IIZI has no per-instance identity for clustered servers (nothing in com.iizix.server.loadbalancer numbers the members), so the index is always 0 and the database directory is the configured path as is.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe cluster index of this server instance: IIZI has none, so 0 (unclustered).Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoiddispose()Disposes of this server module: shuts the IP2Location manager down when it was started.Gets the server's current directory.static IP2LocationModuleGets the module of the running server.Gets the description.Gets the name of the module.Gets the server's settings.initialize(IServer server) Initializes the module: whenServerSettings.IP2LOCATION_ENABLEDis on, configures theIP2LocationManagerasynchronously from the settings.voidonServerReady(IServer server) Called when the server is ready: registers the region location providers when the local service or the web providers are enabled.booleanreconfigure(ServerSettings settings, File currentDirectory) Reconfigures the running service from the settings, as NetPhantom's bootstrap does when the server reloads its configuration: the manager hot-swaps the service (lookups keep being answered meanwhile), or configures it for the first time when the server started with the switch off.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IServerModule
processServerArg
Field Details
CLUSTER_INDEX
public static final int CLUSTER_INDEXThe cluster index of this server instance: IIZI has none, so 0 (unclustered).- See Also:
Constructor Details
IP2LocationModule
public IP2LocationModule()
Method Details
getInstance
Gets the module of the running server.- Returns:
- The module, or null when no server has initialized one (a test JVM, a server started without the module).
getModuleName
Gets the name of the module.- Specified by:
getModuleNamein interfaceIServerModule<Object>- Returns:
- "IP Geolocation".
getModuleDescripion
Gets the description.- Specified by:
getModuleDescripionin interfaceIServerModule<Object>- Returns:
- A descriptive text of the module.
initialize
Initializes the module: whenServerSettings.IP2LOCATION_ENABLEDis on, configures theIP2LocationManagerasynchronously from the settings.- Specified by:
initializein interfaceIServerModule<Object>- Parameters:
server- The server instance.- Returns:
- The end point constructor (handles nothing).
reconfigure
Reconfigures the running service from the settings, as NetPhantom's bootstrap does when the server reloads its configuration: the manager hot-swaps the service (lookups keep being answered meanwhile), or configures it for the first time when the server started with the switch off. With the switch off the manager is given a disabled service, which answers no lookup and holds no file, so that a later switch-on reconfigures it again; a manager thatdispose()has shut down is left alone (logged).The caller has written the settings (
IP2LocationAdminConfig.applyTo(ServerSettings)) and validated them: an enabled service without a token is not refused here but getsIP2LocationSettings.NO_TOKEN, whose download fails with a token error the status shows.- Parameters:
settings- The server settings.currentDirectory- The server's current directory, the base of a relative database directory.- Returns:
- false when the manager is shut down and nothing was done, true otherwise.
getServerSettings
Gets the server's settings.- Returns:
- The settings of the server that initialized this module.
getCurrentDirectory
Gets the server's current directory.- Returns:
- The directory a relative database directory is resolved against.
onServerReady
Called when the server is ready: registers the region location providers when the local service or the web providers are enabled. Without either, nothing is registered, which is the state production has always been in.A local service that is still initializing - the first start downloads the database - is not configured yet, and
ServerShell.registerRegionLocationServiceProviderswould skip it (and make a web provider the default, when those are on). The registration then waits for the manager's callback,registerProvidersWhenReady(); the providers are registered exactly once either way.- Specified by:
onServerReadyin interfaceIServerModule<Object>- Parameters:
server- The server instance.
dispose
public void dispose()Disposes of this server module: shuts the IP2Location manager down when it was started.- Specified by:
disposein interfaceIServerModule<Object>