Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.netaddr
Class NetworkConfigurationWatcher

java.lang.Object
  extended by net.java.sip.communicator.impl.netaddr.NetworkConfigurationWatcher
All Implemented Interfaces:
Runnable, EventListener, SystemActivityChangeListener, org.osgi.framework.ServiceListener

public class NetworkConfigurationWatcher
extends Object
implements SystemActivityChangeListener, org.osgi.framework.ServiceListener, Runnable

Periodically checks the current network interfaces to track changes and fire events on those changes.

Author:
Damian Minkov

Constructor Summary
NetworkConfigurationWatcher()
          Inits configuration watcher.
 
Method Summary
 void activityChanged(SystemActivityEvent event)
          This method gets called when a notification action for a particular event type has been changed.
(package private)  void addNetworkConfigurationChangeListener(NetworkConfigurationChangeListener listener)
          Adds new NetworkConfigurationChangeListener which will be informed for network configuration changes.
static boolean isInterfaceLoopback(NetworkInterface iface)
          Determines whether or not the iface interface is a loopback interface.
static boolean isInterfaceUp(NetworkInterface iface)
          Determines, if possible, whether or not the iface interface is up.
(package private)  void removeNetworkConfigurationChangeListener(NetworkConfigurationChangeListener listener)
          Remove NetworkConfigurationChangeListener.
 void run()
          Main loop of this thread.
 void serviceChanged(org.osgi.framework.ServiceEvent serviceEvent)
          When new protocol provider is registered we add needed listeners.
(package private)  void stop()
          Stop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkConfigurationWatcher

NetworkConfigurationWatcher()
Inits configuration watcher.

Method Detail

addNetworkConfigurationChangeListener

void addNetworkConfigurationChangeListener(NetworkConfigurationChangeListener listener)
Adds new NetworkConfigurationChangeListener which will be informed for network configuration changes.

Parameters:
listener - the listener.

removeNetworkConfigurationChangeListener

void removeNetworkConfigurationChangeListener(NetworkConfigurationChangeListener listener)
Remove NetworkConfigurationChangeListener.

Parameters:
listener - the listener.

serviceChanged

public void serviceChanged(org.osgi.framework.ServiceEvent serviceEvent)
When new protocol provider is registered we add needed listeners.

Specified by:
serviceChanged in interface org.osgi.framework.ServiceListener
Parameters:
serviceEvent - ServiceEvent

stop

void stop()
Stop.


isInterfaceLoopback

public static boolean isInterfaceLoopback(NetworkInterface iface)
Determines whether or not the iface interface is a loopback interface. We use this method as a replacement to the NetworkInterface.isLoopback() method that only comes with java 1.6.

Parameters:
iface - the interface that we'd like to determine as loopback or not.
Returns:
true if iface contains at least one loopback address and false otherwise.

isInterfaceUp

public static boolean isInterfaceUp(NetworkInterface iface)
Determines, if possible, whether or not the iface interface is up. We use this method so that we could use NetworkInterface's isUp() when running a JVM that supports it and return a default value otherwise.

Parameters:
iface - the interface that we'd like to determine as Up or Down.
Returns:
false if iface is known to be down and true if the iface is Up or in case we couldn't determine.

activityChanged

public void activityChanged(SystemActivityEvent event)
This method gets called when a notification action for a particular event type has been changed. We are interested in sleep and network changed events.

Specified by:
activityChanged in interface SystemActivityChangeListener
Parameters:
event - the NotificationActionTypeEvent, which is dispatched when an action has been changed.

run

public void run()
Main loop of this thread.

Specified by:
run in interface Runnable

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.