Package ej.net

Class PollerConnectivityManager

  • Direct Known Subclasses:
    HttpPollerConnectivityManager

    public class PollerConnectivityManager
    extends android.net.ConnectivityManager
    Basic full java implementation. Consider the network is connected when there is at least one NetworkInterface which address is not 0.0.0.0.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class android.net.ConnectivityManager

        android.net.ConnectivityManager.NetworkCallback
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Cancels the associated timer.
      protected android.net.NetworkCapabilities getCapabilities​(java.net.InetAddress connectedAddress)
      Gets the capabilities of a network.
      protected ej.net.NetworkInterfaceFacade getNetworkInterface​(java.lang.String name)
      Isolate for testing.
      protected java.util.Enumeration<ej.net.NetworkInterfaceFacade> getNetworkInterfaces()
      Isolate for testing.
      protected void log​(int msg)
      Logs a message.
      protected void log​(int msg, java.lang.Throwable t)
      Logs a message and a throwable.
      void startPolling​(long delay)
      Starts the polling function.
      void stopPolling()
      Stops the polling function.
      • Methods inherited from class android.net.ConnectivityManager

        addNetwork, doNotifyAvailabilityChange, doNotifyCapabilitiesChange, getActiveNetwork, getActiveNetworkInfo, getAllNetworks, getNetworkCapabilities, getNetworkInfo, notifyNetworkCallbacks, notifyNetworkCallbacks, notifyNetworkCallbacks, registerDefaultNetworkCallback, registerNetworkCallback, setActiveNetwork, setAvailable, unregisterNetworkCallback
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INTERNET_CONNECTED

        protected static final android.net.NetworkCapabilities INTERNET_CONNECTED
        Capability with internet access.
      • INTERNET_UNCONNECTED

        protected static final android.net.NetworkCapabilities INTERNET_UNCONNECTED
        Capability with internet access.
      • BASE_PROPERTY

        protected static final java.lang.String BASE_PROPERTY
        Base property name.
        See Also:
        Constant Field Values
      • periodWhenLost

        protected final long periodWhenLost
      • periodWhenAvailable

        protected final long periodWhenAvailable
      • periodWhenInternet

        protected final long periodWhenInternet
    • Constructor Detail

      • PollerConnectivityManager

        public PollerConnectivityManager()
        Instantiates a PollerConnectivityManager with default periods and delay and a new timer.
      • PollerConnectivityManager

        public PollerConnectivityManager​(ej.bon.Timer timer)
        Instantiates a PollerConnectivityManager with default value.
        Parameters:
        timer - the timer to use, cannot be null.
      • PollerConnectivityManager

        public PollerConnectivityManager​(ej.bon.Timer timer,
                                         long delay,
                                         long period)
        Instantiates a PollerConnectivityManager with the same period when up or not.
        Parameters:
        timer - the timer to use, cannot be null.
        delay - the delay before the start.
        period - the period for the polling.
      • PollerConnectivityManager

        public PollerConnectivityManager​(ej.bon.Timer timer,
                                         long delay,
                                         long periodWhenAvailable,
                                         long periodWhenLost)
        Instantiates a PollerConnectivityManager with 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 be null.
        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​(ej.bon.Timer timer,
                                         long delay,
                                         long periodWhenAvaialble,
                                         long periodWhenLost,
                                         long periodWhenInternet)
        Instantiates a PollerConnectivityManager with the same period when connected or not.
        Parameters:
        timer - the timer to use, cannot be null.
        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,
                           java.lang.Throwable t)
        Logs a message and a throwable.
        Parameters:
        msg - the message to log.
        t - a throwable to print, cannot be null.
      • getCapabilities

        protected android.net.NetworkCapabilities getCapabilities​(java.net.InetAddress connectedAddress)
        Gets the capabilities of a network. Isolate for testing.
        Parameters:
        connectedAddress - the address to get the capabilities from, cannot be null.
        Returns:
        the capabilities of the address.
      • getNetworkInterfaces

        @Nullable
        protected java.util.Enumeration<ej.net.NetworkInterfaceFacade> getNetworkInterfaces()
                                                                                     throws java.net.SocketException
        Isolate for testing.
        Returns:
        all the interface available.
        Throws:
        java.net.SocketException - if an I/O exception occurs.
      • getNetworkInterface

        @Nullable
        protected ej.net.NetworkInterfaceFacade getNetworkInterface​(java.lang.String name)
                                                             throws java.net.SocketException
        Isolate for testing.
        Parameters:
        name - the name of the interface, cannot be null.
        Returns:
        the interface with a name.
        Throws:
        java.net.SocketException - if an I/O exception occurs.