Package com.sun.enterprise.util.net
Class NetUtils
java.lang.Object
com.sun.enterprise.util.net.NetUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic NetUtils.PortAvailabilitycheckPort(int portNumber) There are 4 possibilities when you want to setup a server socket on a port: The port is not in valid range.static StringThis method returns the fully qualified name of the host.static intGets a free port at the time of call to this method.static InetAddress[]static String[]static Stringstatic booleanstatic booleanisPortFree(int portNumber) static booleanisPortFree(String hostName, int portNumber) static booleanisPortStringValid(String portNumber) static booleanisPortValid(int portNumber) static booleanstatic booleanCallsisRunning(String, int, int)with 3000 ms timeout.static booleanThere is sometimes a need for subclasses to know if alocal domainis running.static booleanisSameHost(String host1, String host2) Resolves both hosts and then compares their internet addresses.static booleanisThisHostLocal(String hostname) Return true if hostname represents the current machine.
-
Field Details
-
MAX_PORT
public static final int MAX_PORT- See Also:
-
-
Method Details
-
getFreePort
Gets a free port at the time of call to this method. The logic leverages the built in java.net.ServerSocket implementation which binds a server socket to a free port when instantiated with a port0.Note that this method guarantees the availability of the port only at the time of call. The method does not bind to this port.
Checking for free port can fail for several reasons which may indicate potential problems with the system.
If any exceptional condition is experienced,
0is returned, indicating that the method failed for some reasons and the callers should take the corrective action.Method is synchronized on this class.
- Returns:
- integer depicting the free port number available at this time
- Throws:
IllegalStateException- if it was not possible to open and close the server socket.
-
checkPort
There are 4 possibilities when you want to setup a server socket on a port:- The port is not in valid range.
- The user does not have permission to open up shop on that port An example of (2) is a non-root user on UNIX trying to use port 80
- The port is already in use
- OK -- you can use it!
- Parameters:
portNumber-- Returns:
- one of the 4 possibilities for this port
-
isPortStringValid
-
isPortValid
public static boolean isPortValid(int portNumber) -
isPortFree
public static boolean isPortFree(int portNumber) -
isPortFree
-
isRunning
CallsisRunning(String, int, int)with 3000 ms timeout.- Parameters:
host-port- port to check.- Returns:
- true if there's something listening on the port.
-
isRunning
There is sometimes a need for subclasses to know if alocal domainis running. An example of such a command is change-master-password command. The stop-domain command also needs to know if a domain is running without having to provide user name and password on command line (this is the case when I own a domain that has non-default admin user and password) and want to stop it without providing it.In such cases, we need to know if the domain is running and this method provides a way to do that.
- Parameters:
timeoutMilliseconds- timeout in milliseconds- Returns:
- true if there's something listening on th port.
-
isRemote
-
isLocal
-
isThisHostLocal
Return true if hostname represents the current machine. A null or empty hostname is considered local, as is the name "localhost". Otherwise, all the IP addresses corresponding to hostname are compared with all the IP addresses corresponding to "localhost", as well as all the IP addresses for all the network interfaces on this machine. Note that hostname can also be an IP address in string form.- Returns:
- true if hostname is the local host
-
isSameHost
Resolves both hosts and then compares their internet addresses. If they match at least once, those hosts are considered as same. If there is no such address, returns false.- Parameters:
host1-host2-- Returns:
- true if parameters resolved to same internet address(es)
-
getHostIPs
-
getHostAddresses
-
getHostName
-
getCanonicalHostName
This method returns the fully qualified name of the host. If the name can't be resolved (on Windows if there isn't a domain specified), just host name is returned- Returns:
- fully qualified name of the local host.
- Throws:
UnknownHostException- so it can be handled on a case by case basis
-