Package gov.nasa.worldwind.util
Class BasicNetworkStatus
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.util.BasicNetworkStatus
-
- All Implemented Interfaces:
AVList,NetworkStatus
public class BasicNetworkStatus extends AVListImpl implements NetworkStatus
Basic implementation of NetworkStatus.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBasicNetworkStatus.HostInfo
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_ATTEMPT_LIMITprotected static java.lang.String[]DEFAULT_NETWORK_TEST_SITESprotected static longDEFAULT_TRY_AGAIN_INTERVALprotected java.util.concurrent.ConcurrentHashMap<java.lang.String,BasicNetworkStatus.HostInfo>hostMapprotected java.util.concurrent.atomic.AtomicLonglastAvailableLogTimeprotected java.util.concurrent.atomic.AtomicLonglastNetworkCheckTimeprotected java.util.concurrent.atomic.AtomicLonglastNetworkStatusReportTimeprotected java.util.concurrent.atomic.AtomicBooleanlastNetworkUnavailableResultprotected java.util.concurrent.atomic.AtomicLonglastUnavailableLogTimeprotected static longNETWORK_STATUS_REPORT_INTERVAL-
Fields inherited from interface gov.nasa.worldwind.util.NetworkStatus
HOST_AVAILABLE, HOST_UNAVAILABLE
-
-
Constructor Summary
Constructors Constructor Description BasicNetworkStatus()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidestablishNetworkTestSites()Determines and stores the network sites to test for public network connectivity.intgetAttemptLimit()Returns the number of times a host must be logged as unavailable before it is marked unavailable in this class.java.util.List<java.lang.String>getNetworkTestSites()Returns the server domain names of the sites used to test public network availability.longgetTryAgainInterval()Returns the length of time to wait until a host is marked as not unreachable subsequent to its being marked unreachable.protected static booleanisHostReachable(java.lang.String hostName)Determine if a host is reachable by attempting to resolve the host name, and then attempting to open a connection using either https or http.booleanisHostUnavailable(java.net.URL url)Indicates whether the host has been marked as unavailable.booleanisNetworkUnavailable()Indicates whether a public network can be reached or has been reached in the previous five seconds.booleanisNetworkUnavailable(long checkInterval)Indicates whether a public network can be reached or has been reached in a specified previous amount of time.booleanisOfflineMode()Indicates whether WorldWind will attempt to connect to the network to retrieve data or for other reasons.booleanisWorldWindServerUnavailable()Indicates whether the NASA WorldWind servers can be reached.voidlogAvailableHost(java.net.URL url)Log a host as available.voidlogUnavailableHost(java.net.URL url)Log a host as unavailable.voidsetAttemptLimit(int limit)Sets the number of times a host must be logged as unavailable before it is marked unavailable in this class.voidsetNetworkTestSites(java.util.List<java.lang.String> networkTestSites)Sets the domain names, e.g., worldwind.arc.nasa.gov, of sites used to determine public network availability.voidsetOfflineMode(boolean offlineMode)Indicates whether WorldWind should attempt to connect to the network to retrieve data or for other reasons.voidsetTryAgainInterval(long interval)Sets the length of time to wait until a host is marked as not unreachable subsequent to its being marked unreachable.-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
-
-
-
Field Detail
-
DEFAULT_TRY_AGAIN_INTERVAL
protected static final long DEFAULT_TRY_AGAIN_INTERVAL
- See Also:
- Constant Field Values
-
DEFAULT_ATTEMPT_LIMIT
protected static final int DEFAULT_ATTEMPT_LIMIT
- See Also:
- Constant Field Values
-
NETWORK_STATUS_REPORT_INTERVAL
protected static final long NETWORK_STATUS_REPORT_INTERVAL
- See Also:
- Constant Field Values
-
DEFAULT_NETWORK_TEST_SITES
protected static final java.lang.String[] DEFAULT_NETWORK_TEST_SITES
-
hostMap
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,BasicNetworkStatus.HostInfo> hostMap
-
lastUnavailableLogTime
protected java.util.concurrent.atomic.AtomicLong lastUnavailableLogTime
-
lastAvailableLogTime
protected java.util.concurrent.atomic.AtomicLong lastAvailableLogTime
-
lastNetworkCheckTime
protected java.util.concurrent.atomic.AtomicLong lastNetworkCheckTime
-
lastNetworkStatusReportTime
protected java.util.concurrent.atomic.AtomicLong lastNetworkStatusReportTime
-
lastNetworkUnavailableResult
protected java.util.concurrent.atomic.AtomicBoolean lastNetworkUnavailableResult
-
-
Method Detail
-
establishNetworkTestSites
protected void establishNetworkTestSites()
Determines and stores the network sites to test for public network connectivity. The sites are drawn from the JVM's gov.nasa.worldwind.avkey.NetworkStatusTestSites property (AVKey.NETWORK_STATUS_TEST_SITES). If that property is not defined, the sites are drawn from the same property in the WorldWind or application configuration file. If the sites are not specified there, the set of sites specified inDEFAULT_NETWORK_TEST_SITESare used. To indicate an empty list in the JVM property or configuration file property, specify an empty site list, "".
-
isOfflineMode
public boolean isOfflineMode()
Indicates whether WorldWind will attempt to connect to the network to retrieve data or for other reasons.- Specified by:
isOfflineModein interfaceNetworkStatus- Returns:
trueif WorldWind is in off-line mode,falseif not.
-
setOfflineMode
public void setOfflineMode(boolean offlineMode)
Indicates whether WorldWind should attempt to connect to the network to retrieve data or for other reasons. The default value for this attribute isfalse, indicating that the network should be used.- Specified by:
setOfflineModein interfaceNetworkStatus- Parameters:
offlineMode-trueif WorldWind should use the network,falseotherwise
-
setAttemptLimit
public void setAttemptLimit(int limit)
Sets the number of times a host must be logged as unavailable before it is marked unavailable in this class.- Specified by:
setAttemptLimitin interfaceNetworkStatus- Parameters:
limit- the number of log-unavailability invocations necessary to consider the host unreachable.
-
setTryAgainInterval
public void setTryAgainInterval(long interval)
Sets the length of time to wait until a host is marked as not unreachable subsequent to its being marked unreachable.- Specified by:
setTryAgainIntervalin interfaceNetworkStatus- Parameters:
interval- The length of time, in milliseconds, to wait to unmark a host as unreachable.
-
getAttemptLimit
public int getAttemptLimit()
Returns the number of times a host must be logged as unavailable before it is marked unavailable in this class.- Specified by:
getAttemptLimitin interfaceNetworkStatus- Returns:
- the limit.
-
getTryAgainInterval
public long getTryAgainInterval()
Returns the length of time to wait until a host is marked as not unreachable subsequent to its being marked unreachable.- Specified by:
getTryAgainIntervalin interfaceNetworkStatus- Returns:
- the interval, in milliseconds.
-
getNetworkTestSites
public java.util.List<java.lang.String> getNetworkTestSites()
Returns the server domain names of the sites used to test public network availability.- Specified by:
getNetworkTestSitesin interfaceNetworkStatus- Returns:
- the list of sites used to check network status. The list is a copy of the internal list, so changes to it do not affect instances of this class.
-
setNetworkTestSites
public void setNetworkTestSites(java.util.List<java.lang.String> networkTestSites)
Sets the domain names, e.g., worldwind.arc.nasa.gov, of sites used to determine public network availability.- Specified by:
setNetworkTestSitesin interfaceNetworkStatus- Parameters:
networkTestSites- the list of desired test sites. The list is copied internally, so changes made to the submitted list do not affect instances of this class. May be null, in which case no sites are consulted.
-
logUnavailableHost
public void logUnavailableHost(java.net.URL url)
Log a host as unavailable. Each invocation increments the host's attempt count. When the count equals or exceeds the attempt limit, the host is marked as unavailable.- Specified by:
logUnavailableHostin interfaceNetworkStatus- Parameters:
url- a url containing the host to mark as unavailable.
-
logAvailableHost
public void logAvailableHost(java.net.URL url)
Log a host as available. Each invocation causes the host to no longer be marked as unavailable. Its unavailability count is effectively set to 0.- Specified by:
logAvailableHostin interfaceNetworkStatus- Parameters:
url- a url containing the host to mark as available.
-
isHostUnavailable
public boolean isHostUnavailable(java.net.URL url)
Indicates whether the host has been marked as unavailable. To be marked unavailable a host's attempt count must exceed the specified attempt limit.- Specified by:
isHostUnavailablein interfaceNetworkStatus- Parameters:
url- a url containing the host to check for availability.- Returns:
- true if the host is marked as unavailable, otherwise false.
-
isNetworkUnavailable
public boolean isNetworkUnavailable()
Indicates whether a public network can be reached or has been reached in the previous five seconds.- Specified by:
isNetworkUnavailablein interfaceNetworkStatus- Returns:
- false if the network can be reached or has been reached in the previous five seconds, otherwise true.
-
isNetworkUnavailable
public boolean isNetworkUnavailable(long checkInterval)
Indicates whether a public network can be reached or has been reached in a specified previous amount of time.- Specified by:
isNetworkUnavailablein interfaceNetworkStatus- Parameters:
checkInterval- the number of milliseconds in the past used to determine whether the server was avaialble recently.- Returns:
- false if the network can be reached or has been reached in a specified time, otherwise true.
-
isWorldWindServerUnavailable
public boolean isWorldWindServerUnavailable()
Indicates whether the NASA WorldWind servers can be reached.- Specified by:
isWorldWindServerUnavailablein interfaceNetworkStatus- Returns:
- false if the servers can be reached, otherwise true.
-
isHostReachable
protected static boolean isHostReachable(java.lang.String hostName)
Determine if a host is reachable by attempting to resolve the host name, and then attempting to open a connection using either https or http.- Parameters:
hostName- Name of the host to connect to.- Returns:
trueif a the host is reachable,falseif the host name cannot be resolved, or if opening a connection to the host fails.
-
-