Class ConnectionChecker
- java.lang.Object
-
- nl.bebr.mapviewer.data.util.ConnectionChecker
-
public class ConnectionChecker extends Object
Checks connection availability.Check is running periodically in a {@link java.util.Timer} with period 5000 ms.
When status changes (from online to offline and vice versa) {@link java.beans.PropertyChangeListener} is fired.
- Author:
- Frantisek Post
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(PropertyChangeListener listener)Add property change listenerlonggetCheckPeriod()Return time in milliseconds between two checksStringgetHostName()Return hostname, that is used to checked online statusstatic ConnectionCheckergetInstance()Returns singleton instanceintgetPortNumber()Return checked port numberbooleanisOnline()Returns online statusbooleanisStarted()Returns checker statevoidremovePropertyChangeListener(PropertyChangeListener listener)Remove property change listenervoidrestart()Restart checker to apply new settings.voidsetCheckPeriod(long checkPeriod)Set time in milliseconds between two checksvoidsetHostName(String hostName)Set hostname to check online statusvoidsetPortNumber(int portNumber)Set port numbervoidstart()Starting checker.voidstop()Stopping checker
-
-
-
Method Detail
-
getInstance
public static ConnectionChecker getInstance()
Returns singleton instance- Returns:
-
isStarted
public boolean isStarted()
Returns checker stateChecker is started automatically when util module is loaded
- Returns:
- checker state
-
start
public void start()
Starting checker.Checking timer starts immediately, with default period 2000 ms.
-
stop
public void stop()
Stopping checker
-
isOnline
public boolean isOnline()
Returns online statusBooleantype is used to be able to return answer "I don't know" in case the checker is not runningFirst testing if there is a connection. This should be quite fast. If connection is available, then return result of test in timer.
NOTE: Displable fast check since this could be blocking in case of slow dns server method just returns online state now.- Returns:
- online status
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Add property change listenerListener is fired with property name
statusin case status changes (online->offline, offline->online)- Parameters:
listener-
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove property change listener- Parameters:
listener-
-
getCheckPeriod
public long getCheckPeriod()
Return time in milliseconds between two checks- Returns:
-
setCheckPeriod
public void setCheckPeriod(long checkPeriod)
Set time in milliseconds between two checksTo apply new settings call
restart()- Parameters:
checkPeriod-
-
getHostName
public String getHostName()
Return hostname, that is used to checked online status- Returns:
-
setHostName
public void setHostName(String hostName)
Set hostname to check online statusTo apply new settings call
restart()- Parameters:
hostName-
-
getPortNumber
public int getPortNumber()
Return checked port number- Returns:
-
setPortNumber
public void setPortNumber(int portNumber)
Set port numberTo apply new settings call
restart()- Parameters:
portNumber-
-
restart
public void restart()
-
-