Package ej.net
Class PollerConnectivityManager
- java.lang.Object
-
- android.net.ConnectivityManager
-
- ej.net.PollerConnectivityManager
-
- Direct Known Subclasses:
HttpPollerConnectivityManager
public class PollerConnectivityManager extends ConnectivityManager
Basic full java implementation. Consider the network is connected when there is at least oneNetworkInterfacewhich address is not0.0.0.0.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class android.net.ConnectivityManager
ConnectivityManager.NetworkCallback
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringBASE_PROPERTYBase property name.protected static NetworkCapabilitiesINTERNET_CONNECTEDCapability with internet access.protected static NetworkCapabilitiesINTERNET_UNCONNECTEDCapability with internet access.
-
Constructor Summary
Constructors Constructor Description PollerConnectivityManager()Instantiates aPollerConnectivityManagerwith default periods and delay and a new timer.PollerConnectivityManager(Timer timer)Instantiates aPollerConnectivityManagerwith default value.PollerConnectivityManager(Timer timer, long delay, long period)Instantiates aPollerConnectivityManagerwith the same period when up or not.PollerConnectivityManager(Timer timer, long delay, long periodWhenAvailable, long periodWhenLost)Instantiates aPollerConnectivityManagerwith the different periods when available or not.PollerConnectivityManager(Timer timer, long delay, long periodWhenAvaialble, long periodWhenLost, long periodWhenInternet)Instantiates aPollerConnectivityManagerwith the same period when connected or not.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels the associated timer.protected NetworkCapabilitiesgetCapabilities(InetAddress connectedAddress)Gets the capabilities of a network.protected NetworkInterfacegetNetworkInterface(String name)Isolate for testing.protected Enumeration<NetworkInterface>getNetworkInterfaces()Isolate for testing.protected voidlog(int msg)Logs a message.protected voidlog(int msg, Throwable t)Logs a message and a throwable.voidstartPolling(long delay)Starts the polling function.voidstopPolling()Stops the polling function.-
Methods inherited from class android.net.ConnectivityManager
doNotifyAvailabilityChange, doNotifyCapabilitiesChange, getActiveNetwork, getActiveNetworkInfo, getAllNetworks, getNetworkCapabilities, getNetworkInfo, notifyNetworkCallbacks, notifyNetworkCallbacks, registerDefaultNetworkCallback, registerNetworkCallback, setActiveNetwork, setAvailable, unregisterNetworkCallback
-
-
-
-
Field Detail
-
INTERNET_CONNECTED
protected static final NetworkCapabilities INTERNET_CONNECTED
Capability with internet access.
-
INTERNET_UNCONNECTED
protected static final NetworkCapabilities INTERNET_UNCONNECTED
Capability with internet access.
-
BASE_PROPERTY
protected static final String BASE_PROPERTY
Base property name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PollerConnectivityManager
public PollerConnectivityManager()
Instantiates aPollerConnectivityManagerwith default periods and delay and a new timer.
-
PollerConnectivityManager
public PollerConnectivityManager(Timer timer)
Instantiates aPollerConnectivityManagerwith default value.- Parameters:
timer- the timer to use, cannot benull.
-
PollerConnectivityManager
public PollerConnectivityManager(Timer timer, long delay, long period)
Instantiates aPollerConnectivityManagerwith the same period when up or not.- Parameters:
timer- the timer to use, cannot benull.delay- the delay before the start.period- the period for the polling.
-
PollerConnectivityManager
public PollerConnectivityManager(Timer timer, long delay, long periodWhenAvailable, long periodWhenLost)
Instantiates aPollerConnectivityManagerwith the different periods when available or not. The same period is used wth or without internet access when availble.- Parameters:
timer- the timer to use, cannot benull.delay- the delay before the start.periodWhenAvailable- the period for the polling when at least one interface is available.periodWhenLost- the period for the polling when all the interface are down.
-
PollerConnectivityManager
public PollerConnectivityManager(Timer timer, long delay, long periodWhenAvaialble, long periodWhenLost, long periodWhenInternet)
Instantiates aPollerConnectivityManagerwith the same period when connected or not.- Parameters:
timer- the timer to use, cannot benull.delay- the delay before the start.periodWhenAvaialble- the period for the polling when at least one interface is available.periodWhenLost- the period for the polling when all the interface are down.periodWhenInternet- the period for the polling when there is internet access.
-
-
Method Detail
-
startPolling
public void startPolling(long delay)
Starts the polling function.- Parameters:
delay- the delay before starting.
-
stopPolling
public void stopPolling()
Stops the polling function.
-
cancel
public void cancel()
Cancels the associated timer.
-
log
protected void log(int msg)
Logs a message.- Parameters:
msg- the message to log.
-
log
protected void log(int msg, Throwable t)Logs a message and a throwable.- Parameters:
msg- the message to log.t- a throwable to print, cannot benull.
-
getCapabilities
protected NetworkCapabilities getCapabilities(InetAddress connectedAddress)
Gets the capabilities of a network.- Parameters:
connectedAddress- the address to get the capabilities from, cannot benull.- Returns:
- the capabilities of the address.
-
getNetworkInterfaces
@Nullable protected Enumeration<NetworkInterface> getNetworkInterfaces() throws SocketException
Isolate for testing.- Returns:
- all the interface available.
- Throws:
SocketException- if an I/O exception occurs.
-
getNetworkInterface
@Nullable protected NetworkInterface getNetworkInterface(String name) throws SocketException
Isolate for testing.- Parameters:
name- the name of the interface, cannot benull.- Returns:
- the interface with a name.
- Throws:
SocketException- if an I/O exception occurs.
-
-