Class BootUtil

java.lang.Object
org.jini.rio.boot.BootUtil

public class BootUtil extends Object
Provides static convenience methods for use in configuration files. This class cannot be instantiated.
  • 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 using java.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 use
      port - 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

      public static String getCodebase(String[] jars, String protocol, String address, String port)
      Return the codebase for the provided JAR names, port and address
      Parameters:
      jars - Array of JAR names
      address - The address to use when constructing the codebase
      port - The port to use when constructing the codebase
      Returns:
      the codebase for the JAR
    • getHostAddress

      public static String getHostAddress() throws UnknownHostException
      Return the local host address using java.net.InetAddress.getLocalHost().getHostAddress()
      Returns:
      The local host address
      Throws:
      UnknownHostException - if no IP address for the local host could be found.
    • getAnonymousPort

      public static String getAnonymousPort() throws IOException
      Get an anonymous port
      Returns:
      An anonymous port created by instantiating a java.net.ServerSocket with a port of 0
      Throws:
      IOException
    • getPortInRange

      public static String getPortInRange(int minPort, int maxPort) throws IOException
      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

      public static int getAvailablePort(String hostname, String portRange) throws IOException
      Throws:
      IOException
    • toURLs

      public static List<URL> toURLs(String element) throws MalformedURLException
      Throws:
      MalformedURLException
    • arrayToCommaDelimitedString

      public static String arrayToCommaDelimitedString(Object[] arr)
      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

      public static String arrayToDelimitedString(Object[] arr, String delim)
      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

      public static String[] toArray(String arg)
      Convert comma delimited and/or space String to array of Strings
    • toLookupLocators

      public static LookupLocator[] toLookupLocators(String lookupLocatorURLs)
      Parse a comma delimited LookupLocator URLs and build array of LookupLocator out 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 locators
      removeProtocolPrefix - whether the jini:// prefix should be removed
      Returns:
      URL to lookup locator
    • formatDuration

      public static String formatDuration(long duration)
    • getStackTrace

      public static String getStackTrace(Throwable t)
    • getNetworkInterfaces

      public static NetworkInterface[] getNetworkInterfaces() throws SocketException
      Returns:
      Available network interfaces
      Throws:
      SocketException
      Since:
      11.0
    • getResourceURL

      public static URL getResourceURL(String name, String locatorBaseDir)
      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 load
      locatorBaseDir - 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