Package org.jini.rio.boot
Class BootUtil
java.lang.Object
org.jini.rio.boot.BootUtil
Provides static convenience methods for use in configuration files. This class cannot be
instantiated.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Method Summary
Modifier and TypeMethodDescriptionstatic StringConvenience method to return a String array as a CSV String.static StringarrayToDelimitedString(Object[] arr, String delim) Convenience method to return a String array as a delimited (e.g.static StringformatDuration(long duration) static StringGet an anonymous portstatic intgetAvailablePort(String hostname, String portRange) static StringgetCodebase(String[] jars, String protocol, String port) Return the codebase for the provided JAR names and port.static StringgetCodebase(String[] jars, String protocol, String address, String port) Return the codebase for the provided JAR names, port and addressstatic StringReturn the local host address usingjava.net.InetAddress.getLocalHost().getHostAddress()static NetworkInterface[]static StringgetPortInRange(int minPort, int maxPort) Get a free port in supplied port range.static URLgetResourceURL(String name, String locatorBaseDir) Loads the requested resource and returns its URL.static Stringstatic String[]Convert comma delimited and/or space String to array of Stringsstatic LookupLocator[]toLookupLocators(String lookupLocatorURLs) Parse a comma delimited LookupLocator URLs and build array ofLookupLocatorout of it.static StringtoLookupLocatorURLs(LookupLocator[] lookupLocators, boolean removeProtocolPrefix) Takes an array of LookupLocator builds a comma seperated string of urls out of it.
-
Method Details
-
getCodebase
public static String getCodebase(String[] jars, String protocol, String port) throws UnknownHostException Return the codebase for the provided JAR names and port. This method will first get the IP Address of the machine usingjava.net.InetAddress.getLocalHost().getHostAddress(), then construct the codebase using the host address and the port for each jar in the array of jars.- Parameters:
jars- The JAR names to useport- The port to use when constructing the codebase- Returns:
- The codebase as a space-delimited String for the provided JARs
- Throws:
UnknownHostException- if no IP address for the local host could be found.
-
getCodebase
Return the codebase for the provided JAR names, port and address- Parameters:
jars- Array of JAR namesaddress- The address to use when constructing the codebaseport- The port to use when constructing the codebase- Returns:
- the codebase for the JAR
-
getHostAddress
Return the local host address usingjava.net.InetAddress.getLocalHost().getHostAddress()- Returns:
- The local host address
- Throws:
UnknownHostException- if no IP address for the local host could be found.
-
getAnonymousPort
Get an anonymous port- Returns:
- An anonymous port created by instantiating a
java.net.ServerSocketwith a port of 0 - Throws:
IOException
-
getPortInRange
Get a free port in supplied port range. minPort <= freePort <=maxPort The max port should be up to 65536 value.- Parameters:
minPort- the minimum port number of the port range to scan.maxPort- the maximum port number of the port range to scan.- Returns:
- a free socket port.
- Throws:
IOException
-
getAvailablePort
- Throws:
IOException
-
toURLs
- Throws:
MalformedURLException
-
arrayToCommaDelimitedString
Convenience method to return a String array as a CSV String. E.g. useful for toString() implementations.- Parameters:
arr- array to display. Elements may be of any type (toString will be called on each element).
-
arrayToDelimitedString
Convenience method to return a String array as a delimited (e.g. CSV) String. E.g. useful for toString() implementations.- Parameters:
arr- array to display. Elements may be of any type (toString will be called on each element).delim- delimiter to use (probably a ",")
-
toArray
Convert comma delimited and/or space String to array of Strings -
toLookupLocators
Parse a comma delimited LookupLocator URLs and build array ofLookupLocatorout of it. For example: "host1:4180,host2:4180,host3:4180"- Parameters:
lookupLocatorURLs- List of LookupLocators urls, separates by ",".- Returns:
- LookupLocator[] Array of initilized
LookupLocator.
-
toLookupLocatorURLs
public static String toLookupLocatorURLs(LookupLocator[] lookupLocators, boolean removeProtocolPrefix) Takes an array of LookupLocator builds a comma seperated string of urls out of it. Return example (removeProtocolPrefix==true): "host1:4180,host2:4180,host3:4180" Return example (removeProtocolPrefix==false): "jini://host1:4180/,jini://host2:4180/,jini://host3:4180/"- Parameters:
lookupLocators- The locatorsremoveProtocolPrefix- whether the jini:// prefix should be removed- Returns:
- URL to lookup locator
-
formatDuration
-
getStackTrace
-
getNetworkInterfaces
- Returns:
- Available network interfaces
- Throws:
SocketException- Since:
- 11.0
-
getResourceURL
Loads the requested resource and returns its URL. Several attempts to search for the requested resource: 1. It calls the (current thread) contextClassLoader.getResource(config/schemas/yyy.xml). if not found --> 1.1 It calls the (current thread) contextClassLoader.getResource(yyy.xml). if not found --> 2. It calls this classLoader.getResource(config/schemas/yyy.xml) (e.g. if running in AppServer) if not found --> 2.1 It calls this classLoader.getResource(yyy.xml) (e.g. if running in AppServer) if not found AND useOnlyClasspath == false (expensive operation!) --> 2.2 if the resource was not found, instead of returning null, we attempt to load it as a File IF it was passed as file format e.g. D:/gigaspaces/GenericJDBCProperties/HSQLProperties/jdbc.properties 3. Uses the com.gigaspaces.start.Locator.locate(yyy.xml) that searches recursively under the GS, using root file system. Not the default behavior Notes: In some scenarios, the ResourceLoader does not use the right class loader and returns no resource. E.g. when running within application server the config and jar files loaded using the Thread.currentThread().getContextClassLoader().getResource() but since the lower level CL is used (of the APPServer) we should try also and use the getClass().getResource() in case the first attempt failed to find the resource. A third attempt, if the resource still was not found, it will be using the Locator facility that searches for the resource (using only the resource name) under a base directory in the file system.- Parameters:
name- name of resource to loadlocatorBaseDir- if not null we will try to search for the resource in the file system locatorBaseDir, we will try to recursively search under the locatorBaseDir as the base search path. By default, false.- Returns:
- URL containing the resource
-