Package ej.ecom.network
Class NetworkInterfaceManager
- java.lang.Object
-
- ej.ecom.network.NetworkInterfaceManager
-
public class NetworkInterfaceManager extends Object
A manager for the network interfaces. It allows to get the current IP configuration of a network interface and to reconfigure it.
It allows to enable/disable and start/stop an interface.
- Enable/disable is simply a logical state of the interface managed by software.
- Start/stop is more hardware-related. It may physically turn on/off the hardware module and it is intended to manage power consumption.
Scenario example: a system uses Ethernet as its main interface and 3G as its backup interface. In normal mode, Ethernet is started and enabled while 3G is stopped (and hence disabled) and communications all go through the Ethernet interface. When Ethernet loses Internet connection, it is disabled and 3G is started. Communications will then go through the 3G interface. When Ethernet gets Internet connection back, it is re-enabled, 3G is stopped and the system goes back to normal mode.
-
-
Constructor Summary
Constructors Constructor Description NetworkInterfaceManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidconfigure(NetworkInterface netif, IPConfiguration conf)Sets the IP configuration of a network interface.static voiddisable(NetworkInterface netif)Disables a network interface (software side).static voidenable(NetworkInterface netif)Enables a network interface (software side).static IPConfigurationgetIPConfiguration(NetworkInterface netif)Gets the current IP configuration of a network interface.static booleanisEnabled(NetworkInterface netif)Tells whether a network interface is enabled or not.static booleanisStarted(NetworkInterface netif)Tells whether a network interface is started or not.static voidsetDefault(NetworkInterface netif)Set a network interface as default.static voidstart(NetworkInterface netif)Starts a network interface (hardware side).static voidstop(NetworkInterface netif)Stops a network interface (hardware side).
-
-
-
Method Detail
-
configure
public static void configure(NetworkInterface netif, IPConfiguration conf) throws IOException
Sets the IP configuration of a network interface. The configuration may be sparse. Only not-nulland relevant fields are applied. For instance, static IP address is ignored if DHCP is to be used. When the configuration is applied, be aware that:- current communications may be interrupted, raising
IOException, - the hardware module associated to the network interface may reboot, making the interface not usable for a few seconds,
- it may take time to acquire an IP address if the configuration requires the use of DHCP, making the interface not usable for a few seconds.
- Parameters:
netif- the network interface.conf- the network interface IP configuration.- Throws:
IOException- if it is not possible to reconfigure the interface.IllegalArgumentException- if netif or conf isnull.
- current communications may be interrupted, raising
-
disable
public static void disable(NetworkInterface netif) throws IllegalStateException, IOException
Disables a network interface (software side). A disabled network interface is no longer available for communications. Current communications may be interrupted, raisingIOException.- Parameters:
netif- the network interface to disable.- Throws:
IllegalStateException- if the network interface is currently stopped.IOException- if an I/O error occurs.IllegalArgumentException- if netif isnull.
-
enable
public static void enable(NetworkInterface netif) throws IllegalStateException, IOException
Enables a network interface (software side). An enabled network interface is available for communications, assuming thatstart(NetworkInterface)has been called beforehand.- Parameters:
netif- the network interface to enable.- Throws:
IllegalStateException- if the interface is currently stopped.IOException- if an I/O error occurs.IllegalArgumentException- if netif isnull.
-
getIPConfiguration
public static IPConfiguration getIPConfiguration(NetworkInterface netif) throws IOException
Gets the current IP configuration of a network interface.- Parameters:
netif- the network interface.- Returns:
- the current IP configuration of the network interface.
- Throws:
IOException- if an I/O error occurs.IllegalArgumentException- if netif isnull.
-
isEnabled
public static boolean isEnabled(NetworkInterface netif)
Tells whether a network interface is enabled or not.- Parameters:
netif- the network interface.- Returns:
trueif enabled,falseotherwise- Throws:
IllegalArgumentException- if netif isnull.
-
isStarted
public static boolean isStarted(NetworkInterface netif)
Tells whether a network interface is started or not.- Parameters:
netif- the network interface.- Returns:
trueif started,falseotherwise.- Throws:
IllegalArgumentException- if netif isnull.
-
start
public static void start(NetworkInterface netif) throws IOException
Starts a network interface (hardware side). Switch on the network interface. The network interface is not enabled,enable(NetworkInterface)has to be called after this method.- Parameters:
netif- the network interface to start.- Throws:
IOException- if an I/O error occurs.IllegalArgumentException- if netif isnull.
-
stop
public static void stop(NetworkInterface netif) throws IOException
Stops a network interface (hardware side). Stopping a network interface will also disable it. Current communications may be interrupted, raising IOExceptions.- Parameters:
netif- the interface to stop.- Throws:
IOException- if an I/O error occurs.IllegalArgumentException- if netif isnull.
-
setDefault
public static void setDefault(NetworkInterface netif) throws IOException
Set a network interface as default. This default network interface will be used for all communications which do not specified a targeted network interface.- Parameters:
netif- the network interface to use as the default one.- Throws:
IOException- if an I/O error occurs.IllegalArgumentException- if netif isnull.
-
-