[jitsi-dev] [jitsi-commits] master: Remove use of reflection for isUp and isLoopback (578fde2)


#1

Hey Ingo,

I wanted to try our new "Reply-To: dev@jitsi.org" header on the commits list :slight_smile: so a quick comment here:

The point of wrapping isUp() and isLoopback() was to be able to transparently switch between implementations. Possibly even with use of properties. I agree that we no longer need reflection given that we've dropped J1.5 compatibility, but seeing some of the issues we have with the loopback methods on windows, I think we may still end up using an alternative implementation.

WDYT?

Emil

路路路

On 01.06.13, 00:39, gitdub@jitsi.org wrote:

Repository : ssh://lists.jitsi.org/jitsi

On branch : master
Link : https://github.com/jitsi/jitsi/compare/9d3bdfbafeac7b55fa2140bb4457f1c8653be9e4...90f9d1e6af3b0faf1c808eb304c129572bdafd09

---------------------------------------------------------------

commit 578fde27e7f9f62921438dfab4253a5b85dcda74
Author: Ingo Bauersachs <ingo@jitsi.org>
Date: Fri May 31 19:21:15 2013 +0200

聽聽聽聽聽Remove use of reflection for isUp and isLoopback

---------------------------------------------------------------

578fde27e7f9f62921438dfab4253a5b85dcda74
聽聽.../impl/netaddr/NetworkConfigurationWatcher.java | 69 ++------------------
聽聽1 file changed, 4 insertions(+), 65 deletions(-)

diff --git a/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java b/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java
index d356cb2..ecf4033 100644
--- a/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java
+++ b/src/net/java/sip/communicator/impl/netaddr/NetworkConfigurationWatcher.java
@@ -6,7 +6,6 @@
聽聽聽*/
聽聽package net.java.sip.communicator.impl.netaddr;

-import java.lang.reflect.*;
聽聽import java.net.*;
聽聽import java.util.*;

@@ -117,12 +116,12 @@ public class NetworkConfigurationWatcher
聽聽聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽NetworkInterface networkInterface = e.nextElement();

- if(isInterfaceLoopback(networkInterface))
+ if(networkInterface.isLoopback())
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽continue;

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽// if interface is up and has some valid(non-local) address
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽// add it to currently active
- if(isInterfaceUp(networkInterface))
+ if(networkInterface.isUp())
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Enumeration<InetAddress> as =
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽networkInterface.getInetAddresses();
@@ -262,66 +261,6 @@ public class NetworkConfigurationWatcher
聽聽聽聽聽聽}

聽聽聽聽聽聽/**
- * Determines whether or not the <tt>iface</tt> interface is a loopback
- * interface. We use this method as a replacement to the
- * <tt>NetworkInterface.isLoopback()</tt> method that only comes with
- * java 1.6.
- *
- * @param iface the interface that we'd like to determine as loopback or not.
- *
- * @return true if <tt>iface</tt> contains at least one loopback address
- * and <tt>false</tt> otherwise.
- */
- public static boolean isInterfaceLoopback(NetworkInterface iface)
- {
- try
- {
- Method method = iface.getClass().getMethod("isLoopback");
-
- return ((Boolean)method.invoke(iface, new Object[]{}))
- .booleanValue();
- }
- catch(Throwable t)
- {
- //apparently we are not running in a JVM that supports the
- //is Loopback method. we'll try another approach.
- }
- Enumeration<InetAddress> addresses = iface.getInetAddresses();
-
- return addresses.hasMoreElements()
- && addresses.nextElement().isLoopbackAddress();
- }
-
- /**
- * Determines, if possible, whether or not the <tt>iface</tt> interface is
- * up. We use this method so that we could use {@link
- * java.net.NetworkInterface}'s <tt>isUp()</tt> when running a JVM that
- * supports it and return a default value otherwise.
- *
- * @param iface the interface that we'd like to determine as Up or Down.
- *
- * @return <tt>false</tt> if <tt>iface</tt> is known to be down and
- * <tt>true</tt> if the <tt>iface</tt> is Up or in case we couldn't
- * determine.
- */
- public static boolean isInterfaceUp(NetworkInterface iface)
- {
- try
- {
- Method method = iface.getClass().getMethod("isUp");
-
- return ((Boolean)method.invoke(iface)).booleanValue();
- }
- catch(Throwable t)
- {
- //apparently we are not running in a JVM that supports the
- //isUp method. returning default value.
- }
-
- return true;
- }
-
- /**
聽聽聽聽聽聽聽* 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.
@@ -405,12 +344,12 @@ public class NetworkConfigurationWatcher
聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽NetworkInterface networkInterface = e.nextElement();

- if(isInterfaceLoopback(networkInterface))
+ if(networkInterface.isLoopback())
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽continue;

聽聽聽聽聽聽聽聽聽聽聽聽聽聽// if interface is up and has some valid(non-local) address
聽聽聽聽聽聽聽聽聽聽聽聽聽聽// add it to currently active
- if(isInterfaceUp(networkInterface))
+ if(networkInterface.isUp())
聽聽聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽List<InetAddress> addresses =
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽new ArrayList<InetAddress>();

_______________________________________________
commits mailing list
commits@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/commits

--
https://jitsi.org


#2

I wanted to try our new "Reply-To: dev@jitsi.org" header on the commits
list :slight_smile: so a quick comment here:

Seems to work :slight_smile:

The point of wrapping isUp() and isLoopback() was to be able to
transparently switch between implementations. Possibly even with use of
properties. I agree that we no longer need reflection given that we've
dropped J1.5 compatibility, but seeing some of the issues we have with
the loopback methods on windows, I think we may still end up using an
alternative implementation.

I don't mind having a different implementation, but before this commit it
always went to isUp and isLoopback anyway and hence just wasting
performance. Not that the Windows-IPv6-disabled bug affects all methods that
deal with NetworkInterface, not just isUp and isLoopback.

WDYT?
Emil

Ingo


#3

I wanted to try our new "Reply-To: dev@jitsi.org" header on the commits
list :slight_smile: so a quick comment here:

Seems to work :slight_smile:

Swell, right? :slight_smile:

The point of wrapping isUp() and isLoopback() was to be able to
transparently switch between implementations. Possibly even with use of
properties. I agree that we no longer need reflection given that we've
dropped J1.5 compatibility, but seeing some of the issues we have with
the loopback methods on windows, I think we may still end up using an
alternative implementation.

I don't mind having a different implementation, but before this commit it
always went to isUp and isLoopback anyway and hence just wasting
performance.

Well we could get rid of the refactoring and just keep the wrapper method. It's not such a big deal but I think that we might be needing it soon.

Not that the Windows-IPv6-disabled bug affects all methods that
deal with NetworkInterface, not just isUp and isLoopback.

Right, so in other words: there will be more wrappers, right? :slight_smile:

Emil

路路路

On 01.06.13, 14:04, Ingo Bauersachs wrote:

WDYT?
Emil

Ingo

_______________________________________________
dev mailing list
dev@jitsi.org
Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev

--
https://jitsi.org