Package gov.usgs.earthquake.geoserve
Class ANSSRegionsFactory
- java.lang.Object
-
- gov.usgs.earthquake.geoserve.ANSSRegionsFactory
-
public class ANSSRegionsFactory extends java.lang.Object
Class to manage ANSS Authoritative Region updates. Simplest usage: ANSSRegionsFactory.getFactory().getRegions() Regions are not fetched untilstartup()
(orfetchRegions()
) is called.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_REGIONS_JSON
path to write regions.jsonstatic java.util.logging.Logger
LOGGER
logging objectstatic long
MILLISECONDS_PER_DAY
milliseconds per day
-
Constructor Summary
Constructors Constructor Description ANSSRegionsFactory()
Use default GeoserveLayersService.ANSSRegionsFactory(GeoserveLayersService geoserveLayersService)
Use custom GeoserveLayersService.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fetchRegions()
Download regions from geoserve.static ANSSRegionsFactory
getFactory()
Get the global ANSSRegionsFactory, creating and starting if needed.static ANSSRegionsFactory
getFactory(boolean startup)
GeoserveLayersService
getGeoserveLayersService()
Get the service.java.io.File
getLocalRegions()
Get the local regions file.Regions
getRegions()
Get the most recently fetched Regions.protected Regions
loadFromFile()
Read regions from local regions file.protected Regions
loadFromGeoserve()
Read regions from geoserve service.protected void
saveToFile(java.io.File regionsFile, javax.json.JsonObject json)
Store json to local regions file.static void
setFactory(ANSSRegionsFactory factory)
Set the global ANSSRegionsFactory, shutting down any existing factory if needed.void
setGeoserveLayersService(GeoserveLayersService service)
Set the service.void
setLocalRegions(java.io.File localRegions)
Set the local regions file.void
shutdown()
Stop updating regions.void
startup()
Start updating regions.
-
-
-
Field Detail
-
LOGGER
public static final java.util.logging.Logger LOGGER
logging object
-
MILLISECONDS_PER_DAY
public static final long MILLISECONDS_PER_DAY
milliseconds per day- See Also:
- Constant Field Values
-
DEFAULT_REGIONS_JSON
public static final java.lang.String DEFAULT_REGIONS_JSON
path to write regions.json- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ANSSRegionsFactory
public ANSSRegionsFactory()
Use default GeoserveLayersService.
-
ANSSRegionsFactory
public ANSSRegionsFactory(GeoserveLayersService geoserveLayersService)
Use custom GeoserveLayersService.- Parameters:
geoserveLayersService
- to use
-
-
Method Detail
-
getFactory
public static ANSSRegionsFactory getFactory()
Get the global ANSSRegionsFactory, creating and starting if needed.- Returns:
- ANSSRegionsFactory
-
getFactory
public static ANSSRegionsFactory getFactory(boolean startup)
- Parameters:
startup
- if Factory should be created and started, if needed- Returns:
- ANSSRegionsFactory
-
setFactory
public static void setFactory(ANSSRegionsFactory factory)
Set the global ANSSRegionsFactory, shutting down any existing factory if needed.- Parameters:
factory
- to set
-
fetchRegions
public void fetchRegions()
Download regions from geoserve. Writes out to "regions.json" in current working directory and, if unable to update, reads in local copy.
-
loadFromFile
protected Regions loadFromFile() throws java.io.IOException
Read regions from local regions file.- Returns:
- Regions
- Throws:
java.io.IOException
- if error occurs
-
loadFromGeoserve
protected Regions loadFromGeoserve() throws java.io.IOException
Read regions from geoserve service.- Returns:
- Regions
- Throws:
java.io.IOException
- if error occurs
-
saveToFile
protected void saveToFile(java.io.File regionsFile, javax.json.JsonObject json) throws java.io.IOException
Store json to local regions file.- Parameters:
regionsFile
- to store tojson
- json response to store locally.- Throws:
java.io.IOException
- if IO error occurs
-
startup
public void startup()
Start updating regions.
-
shutdown
public void shutdown()
Stop updating regions.
-
getGeoserveLayersService
public GeoserveLayersService getGeoserveLayersService()
Get the service.- Returns:
- geoserveLayersService
-
setGeoserveLayersService
public void setGeoserveLayersService(GeoserveLayersService service)
Set the service.- Parameters:
service
- GeoserveLayersService to set
-
getLocalRegions
public java.io.File getLocalRegions()
Get the local regions file.- Returns:
- localRegions
-
setLocalRegions
public void setLocalRegions(java.io.File localRegions)
Set the local regions file.- Parameters:
localRegions
- file to set
-
getRegions
public Regions getRegions()
Get the most recently fetched Regions.- Returns:
- regions
-
-