org.elasticsearch.common.network
Class NetworkUtils

java.lang.Object
  extended by org.elasticsearch.common.network.NetworkUtils

public abstract class NetworkUtils
extends Object


Nested Class Summary
static class NetworkUtils.StackType
           
 
Field Summary
static String IPv4_SETTING
           
static String IPv6_SETTING
           
static String NON_LOOPBACK_ADDRESS
           
 
Method Summary
static boolean canBindToMcastAddress()
           
static Boolean defaultReuseAddress()
           
static Collection<InetAddress> getAllAvailableAddresses()
           
static List<NetworkInterface> getAllAvailableInterfaces()
          Returns all the available interfaces, including first level sub interfaces.
static InetAddress getFirstNonLoopbackAddress(NetworkInterface intf, NetworkUtils.StackType ipVersion)
          Returns the first non-loopback address on the given interface on the current host.
static InetAddress getFirstNonLoopbackAddress(NetworkUtils.StackType ip_version)
          Returns the first non-loopback address on any interface on the current host.
static NetworkUtils.StackType getIpStackType()
          Tries to determine the type of IP stack from the available interfaces and their addresses and from the system properties (java.net.preferIPv4Stack and java.net.preferIPv6Addresses)
static InetAddress getIPv4Localhost()
           
static InetAddress getIPv6Localhost()
           
static InetAddress getLocalAddress()
           
static InetAddress getLocalhost(NetworkUtils.StackType ip_version)
           
static boolean interfaceHasIPAddresses(NetworkInterface intf, NetworkUtils.StackType ipVersion)
          A function to check if an interface supports an IP version (i.e has addresses defined for that IP version).
static boolean isIPv4()
           
static boolean isStackAvailable(boolean ipv4)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IPv4_SETTING

public static final String IPv4_SETTING
See Also:
Constant Field Values

IPv6_SETTING

public static final String IPv6_SETTING
See Also:
Constant Field Values

NON_LOOPBACK_ADDRESS

public static final String NON_LOOPBACK_ADDRESS
See Also:
Constant Field Values
Method Detail

defaultReuseAddress

public static Boolean defaultReuseAddress()

isIPv4

public static boolean isIPv4()

getIPv4Localhost

public static InetAddress getIPv4Localhost()
                                    throws UnknownHostException
Throws:
UnknownHostException

getIPv6Localhost

public static InetAddress getIPv6Localhost()
                                    throws UnknownHostException
Throws:
UnknownHostException

getLocalAddress

public static InetAddress getLocalAddress()

getLocalhost

public static InetAddress getLocalhost(NetworkUtils.StackType ip_version)
                                throws UnknownHostException
Throws:
UnknownHostException

canBindToMcastAddress

public static boolean canBindToMcastAddress()

getFirstNonLoopbackAddress

public static InetAddress getFirstNonLoopbackAddress(NetworkUtils.StackType ip_version)
                                              throws SocketException
Returns the first non-loopback address on any interface on the current host.

Parameters:
ip_version - Constraint on IP version of address to be returned, 4 or 6
Throws:
SocketException

getFirstNonLoopbackAddress

public static InetAddress getFirstNonLoopbackAddress(NetworkInterface intf,
                                                     NetworkUtils.StackType ipVersion)
                                              throws SocketException
Returns the first non-loopback address on the given interface on the current host.

Parameters:
intf - the interface to be checked
ipVersion - Constraint on IP version of address to be returned, 4 or 6
Throws:
SocketException

interfaceHasIPAddresses

public static boolean interfaceHasIPAddresses(NetworkInterface intf,
                                              NetworkUtils.StackType ipVersion)
                                       throws SocketException,
                                              UnknownHostException
A function to check if an interface supports an IP version (i.e has addresses defined for that IP version).

Parameters:
intf -
Returns:
Throws:
SocketException
UnknownHostException

getIpStackType

public static NetworkUtils.StackType getIpStackType()
Tries to determine the type of IP stack from the available interfaces and their addresses and from the system properties (java.net.preferIPv4Stack and java.net.preferIPv6Addresses)

Returns:
StackType.IPv4 for an IPv4 only stack, StackYTypeIPv6 for an IPv6 only stack, and StackType.Unknown if the type cannot be detected

isStackAvailable

public static boolean isStackAvailable(boolean ipv4)

getAllAvailableInterfaces

public static List<NetworkInterface> getAllAvailableInterfaces()
                                                        throws SocketException
Returns all the available interfaces, including first level sub interfaces.

Throws:
SocketException

getAllAvailableAddresses

public static Collection<InetAddress> getAllAvailableAddresses()


Copyright © 2009-2012. All Rights Reserved.