Class IP2LocationModule

java.lang.Object
com.iizix.server.geo.ip2location.IP2LocationModule
All Implemented Interfaces:
IServerModule<Object>

public class IP2LocationModule extends Object implements IServerModule<Object>
The IP geolocation server module: the IIZI bootstrap of the 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 the IP2LocationManager asynchronously 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 of RegionLocationService; 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): SessionGeoLogger writes 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)
(through 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 Details

    • CLUSTER_INDEX

      public static final int CLUSTER_INDEX
      The cluster index of this server instance: IIZI has none, so 0 (unclustered).
      See Also:
  • Constructor Details

    • IP2LocationModule

      public IP2LocationModule()
  • Method Details

    • getInstance

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

      public String getModuleName()
      Gets the name of the module.
      Specified by:
      getModuleName in interface IServerModule<Object>
      Returns:
      "IP Geolocation".
    • getModuleDescripion

      public String getModuleDescripion()
      Gets the description.
      Specified by:
      getModuleDescripion in interface IServerModule<Object>
      Returns:
      A descriptive text of the module.
    • initialize

      public IEndPointConstructor<Object> initialize(IServer server)
      Initializes the module: when ServerSettings.IP2LOCATION_ENABLED is on, configures the IP2LocationManager asynchronously from the settings.
      Specified by:
      initialize in interface IServerModule<Object>
      Parameters:
      server - The server instance.
      Returns:
      The end point constructor (handles nothing).
    • reconfigure

      public boolean reconfigure(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. 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 that dispose() 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 gets IP2LocationSettings.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

      public ServerSettings getServerSettings()
      Gets the server's settings.
      Returns:
      The settings of the server that initialized this module.
    • getCurrentDirectory

      public File getCurrentDirectory()
      Gets the server's current directory.
      Returns:
      The directory a relative database directory is resolved against.
    • onServerReady

      public void onServerReady(IServer server)
      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.registerRegionLocationServiceProviders would 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:
      onServerReady in interface IServerModule<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:
      dispose in interface IServerModule<Object>