NASA World Wind

gov.nasa.worldwind.util
Class BasicNetworkStatus

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.util.BasicNetworkStatus
All Implemented Interfaces:
AVList, NetworkStatus, PropertyChangeListener, EventListener

public class BasicNetworkStatus
extends AVListImpl
implements NetworkStatus

Provides tracking of per-host network availability. Host computers that fail network requests can be logged to this class' tracking list. When a host has been logged a specified number of times, it is marked as unreachable. Users can query instances of this class to determine whether a host has been marked as unreachable.

Users are expected to invoke this class' logUnavailableHost(java.net.URL) method when an attempt to contact a host fails. Each invocation increments the failure count by one. When the count exceeds the attempt limit, the host is marked as unreachable. When attempts to contact the host are successful, users should invoke this class' logAvailableHost(java.net.URL) method to clear its status.

A host may become reachable at a time subsequent to its being logged. To detect this, this class will mark a host as not unreachable after a specifiable interval of time. If the host is once more logged as unavailable, its entry will return to the unavailable state. This cycle continues indefinitely.

Methods are also provided to determine whether the public network can be reached and whether the NASA World Wind servers cab be reached.


Field Summary
 
Fields inherited from class gov.nasa.worldwind.avlist.AVListImpl
changeSupport
 
Constructor Summary
BasicNetworkStatus()
           
 
Method Summary
 int getAttemptLimit()
          Returns the number of times a host must be logged as unavailable before it is marked unavailable in this class.
 long getTryAgainInterval()
          Returns the length of time to wait until a host is marked as not unreachable subsequent to its being marked unreachable.
 boolean isHostUnavailable(URL url)
          Indicates whether the host has been marked as unavailable.
 boolean isNetworkUnavailable()
          Indicates whether a public network can be reached or has been reached in the previous five seconds.
 boolean isNetworkUnavailable(long checkInterval)
          Indicates whether a public network can be reached or has been reached in a specified previous amount of time.
 boolean isOfflineMode()
          Indicates whether World Wind will attempt to connect to the network to retrieve data or for other reasons.
 boolean isWorlWindServerUnavailable()
          Indicates whether the NASA World Wind servers can be reached.
 void logAvailableHost(URL url)
          Log a host as available.
 void logUnavailableHost(URL url)
          Log a host as unavailable.
 void setAttemptLimit(int limit)
          Set the number of times a host must be logged as unavailable before it is marked unavailable in this class.
 void setOfflineMode(boolean offlineMode)
          Indicate whether World Wind should attempt to connect to the network to retrieve data or for other reasons.
 void setTryAgainInterval(long interval)
          Set 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, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, propertyChange, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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
 

Constructor Detail

BasicNetworkStatus

public BasicNetworkStatus()
Method Detail

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:
getAttemptLimit in interface NetworkStatus
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:
getTryAgainInterval in interface NetworkStatus
Returns:
the interval, in milliseconds.

isHostUnavailable

public boolean isHostUnavailable(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:
isHostUnavailable in interface NetworkStatus
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:
isNetworkUnavailable in interface NetworkStatus
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.

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.

isOfflineMode

public boolean isOfflineMode()
Indicates whether World Wind will attempt to connect to the network to retrieve data or for other reasons.

Specified by:
isOfflineMode in interface NetworkStatus
Returns:
true if World Wind is in off-line mode, false if not.

isWorlWindServerUnavailable

public boolean isWorlWindServerUnavailable()
Indicates whether the NASA World Wind servers can be reached.

Specified by:
isWorlWindServerUnavailable in interface NetworkStatus
Returns:
false if the servers can be reached, otherwise true.

logAvailableHost

public void logAvailableHost(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:
logAvailableHost in interface NetworkStatus
Parameters:
url - a url containing the host to mark as available.

logUnavailableHost

public void logUnavailableHost(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:
logUnavailableHost in interface NetworkStatus
Parameters:
url - a url containing the host to mark as unavailable.

setAttemptLimit

public void setAttemptLimit(int limit)
Set the number of times a host must be logged as unavailable before it is marked unavailable in this class.

Specified by:
setAttemptLimit in interface NetworkStatus
Parameters:
limit - the number of log-unavailability invocations necessary to consider the host unreachable.
Throws:
IllegalArgumentException - if the limit is less than 1.

setOfflineMode

public void setOfflineMode(boolean offlineMode)
Indicate whether World Wind should attempt to connect to the network to retrieve data or for other reasons. The default value for this attribute is false, indicating that the network should be used.

Specified by:
setOfflineMode in interface NetworkStatus
Parameters:
offlineMode - true if World Wind should use the network, false otherwise

setTryAgainInterval

public void setTryAgainInterval(long interval)
Set the length of time to wait until a host is marked as not unreachable subsequent to its being marked unreachable.

Specified by:
setTryAgainInterval in interface NetworkStatus
Parameters:
interval - The length of time, in milliseconds, to wait to unmark a host as unreachable.
Throws:
IllegalArgumentException - if the interval is less than 0.

NASA World Wind