Class IP2LocationRegionService

java.lang.Object
com.iizix.geo.RegionLocationService
com.iizix.server.geo.ip2location.IP2LocationRegionService

public class IP2LocationRegionService extends RegionLocationService
The IP2Location region location provider: answers RegionLocationService requests from the local IP2Location LITE database through IP2LocationManager. No client IP address leaves the server, which is what sets it apart from the web providers GeoPlugin, IPStack and IPWhoIs of com.iizix.server.region; it is registered first by ServerShell.registerRegionLocationServiceProviders when the service is enabled and is therefore the default provider.

The provider is available while the manager is configured (the service may still be initializing: a lookup then answers with an error location saying so, and the base class caches only valid answers over erroneous ones).

The mapping from the library's GeoLocation to RegionLocation is toRegionLocation(GeoLocation): country code and name, region, city, ZIP code and time zone as the database tier provides them, the coordinates when the tier has them (the library reports 0.0/0.0 when it has none, which is not a location), and no accuracy radius, because IP2Location publishes none.

Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • IP2LocationRegionService

      public IP2LocationRegionService()
      Constructs the provider. The default timeout is the minimum the base class allows (5 seconds); a local lookup takes microseconds, the timeout only bounds a caller that waits synchronously while the database is being loaded.
  • Method Details

    • isManagerConfigured

      public static boolean isManagerConfigured()
      Returns if the manager has a configured service, i.e. if a provider instance would be available; ServerShell.registerRegionLocationServiceProviders asks this before constructing one.
      Returns:
      true when configured, false otherwise.
    • isAvailable

      protected boolean isAvailable()
      Returns if the provider can be used: the manager has a configured service.
      Overrides:
      isAvailable in class RegionLocationService
      Returns:
      true when configured, false otherwise.
    • request

      protected RegionLocation request(String ipAddress)
      Requests region location information from the local database.
      Specified by:
      request in class RegionLocationService
      Parameters:
      ipAddress - The IP address (IPv4 or IPv6) to look up.
      Returns:
      The region location, always non-null: an error location when the lookup did not succeed, with the library's status code as the error text.
    • toRegionLocation

      public static RegionLocation toRegionLocation(GeoLocation loc)
      Maps a lookup result of the library to a region location.
      Parameters:
      loc - The lookup result.
      Returns:
      The region location; an error location carrying "IP2Location: " and the status code when the lookup was not OK.