Class Bootstrap

  • Direct Known Subclasses:
    InstallerBootstrap

    public abstract class Bootstrap
    extends java.lang.Object
    Bootstrap application for starting OpenNMS.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bootstrap()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void executeClass​(java.lang.String classToExec, java.lang.String classToExecMethod, java.lang.String[] classToExecArgs, boolean appendClasspath)  
      protected static void executeClass​(java.lang.String classToExec, java.lang.String classToExecMethod, java.lang.String[] classToExecArgs, boolean appendClasspath, boolean recurse)  
      protected static java.io.File findOpenNMSHome()
      Find the OpenNMS home directory.
      static java.io.File findOpenNMSHomeUsingJarPath()
      Determine the OpenNMS home directory based on the location of the JAR file containing this code.
      protected static java.util.List<java.io.File> getPropertiesFiles​(java.io.File opennmsHome)
      Retrieves the list of configuration files containing system properties to be set.
      protected static boolean isValidOpenNMSHome​(java.io.File opennmsHome)
      Validates the OpenNMS home directory by checking for known mandatory files.
      static java.lang.ClassLoader loadClasses​(java.io.File dir, boolean recursive)
      Create a ClassLoader with the JARs found in dir.
      static void loadClasses​(java.io.File dir, boolean recursive, java.util.List<java.net.URL> urls)
      Add JARs found in dir to the LinkedList urls.
      static java.lang.ClassLoader loadClasses​(java.lang.String dirStr, boolean recursive, boolean append)
      Create a ClassLoader with the JARs found in dirStr.
      protected static void loadSystemProperties​(java.io.File opennmsHome)
      Load default properties from the specified OpenNMS home into the system properties.
      static void main​(java.lang.String[] args)
      Bootloader main method.
      static java.lang.ClassLoader newClassLoader​(java.util.List<java.net.URL> urls)
      Create a ClassLoader with the list of URLs found in urls.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • VERSION_PROPERTIES

        protected static final java.nio.file.Path VERSION_PROPERTIES
      • BOOT_PROPERTIES_NAME

        protected static final java.lang.String BOOT_PROPERTIES_NAME
        See Also:
        Constant Field Values
      • RRD_PROPERTIES_NAME

        protected static final java.lang.String RRD_PROPERTIES_NAME
        See Also:
        Constant Field Values
      • LIBRARY_PROPERTIES_NAME

        protected static final java.lang.String LIBRARY_PROPERTIES_NAME
        See Also:
        Constant Field Values
      • OPENNMS_PROPERTIES_NAME

        protected static final java.lang.String OPENNMS_PROPERTIES_NAME
        See Also:
        Constant Field Values
      • OPENNMS_PROPERTIES_D_NAME

        protected static final java.lang.String OPENNMS_PROPERTIES_D_NAME
        See Also:
        Constant Field Values
      • OPENNMS_HOME_PROPERTY

        protected static final java.lang.String OPENNMS_HOME_PROPERTY
        See Also:
        Constant Field Values
    • Constructor Detail

      • Bootstrap

        public Bootstrap()
    • Method Detail

      • loadClasses

        public static java.lang.ClassLoader loadClasses​(java.lang.String dirStr,
                                                        boolean recursive,
                                                        boolean append)
                                                 throws java.net.MalformedURLException
        Create a ClassLoader with the JARs found in dirStr.
        Parameters:
        dirStr - List of directories to search for JARs, separated by File.pathSeparator.
        recursive - Whether to recurse into subdirectories of the directories in dirStr.
        append - Append the URLs of the current {@link java.lang.Thread#getContextClassLoader()) to this classloader.
        Returns:
        a ClassLoader object.
        Throws:
        java.net.MalformedURLException - if any.
      • loadClasses

        public static java.lang.ClassLoader loadClasses​(java.io.File dir,
                                                        boolean recursive)
                                                 throws java.net.MalformedURLException
        Create a ClassLoader with the JARs found in dir.
        Parameters:
        dir - Directory to search for JARs
        recursive - Whether to recurse into subdirectories of dir
        Returns:
        a ClassLoader object.
        Throws:
        java.net.MalformedURLException - if any.
      • newClassLoader

        public static java.lang.ClassLoader newClassLoader​(java.util.List<java.net.URL> urls)
        Create a ClassLoader with the list of URLs found in urls.
        Parameters:
        urls - List of URLs to add to the ClassLoader's search list.
        Returns:
        a ClassLoader object.
      • loadClasses

        public static void loadClasses​(java.io.File dir,
                                       boolean recursive,
                                       java.util.List<java.net.URL> urls)
                                throws java.net.MalformedURLException
        Add JARs found in dir to the LinkedList urls.
        Parameters:
        dir - Directory to search for JARs
        recursive - Whether to recurse into subdirectories of the directory in dir
        urls - LinkedList to append found JARs onto
        Throws:
        java.net.MalformedURLException - if any.
      • getPropertiesFiles

        protected static java.util.List<java.io.File> getPropertiesFiles​(java.io.File opennmsHome)
        Retrieves the list of configuration files containing system properties to be set. The system properties must be set in the same order as they are returned here.
        Parameters:
        opennmsHome - the OpenNMS home directory
        Returns:
        a list of property files
      • loadSystemProperties

        protected static void loadSystemProperties​(java.io.File opennmsHome)
                                            throws java.io.IOException
        Load default properties from the specified OpenNMS home into the system properties.
        Parameters:
        opennmsHome - the OpenNMS home directory
        Throws:
        java.io.IOException
      • isValidOpenNMSHome

        protected static boolean isValidOpenNMSHome​(java.io.File opennmsHome)
        Validates the OpenNMS home directory by checking for known mandatory files.
        Parameters:
        opennmsHome - the OpenNMS home directory
        Returns:
        true is the opennmsHome folder is a valid OpenNMS home directory
      • findOpenNMSHome

        protected static java.io.File findOpenNMSHome()
                                               throws java.lang.Exception
        Find the OpenNMS home directory.
        Throws:
        java.lang.Exception
      • findOpenNMSHomeUsingJarPath

        public static java.io.File findOpenNMSHomeUsingJarPath()
        Determine the OpenNMS home directory based on the location of the JAR file containing this code. Finds the JAR file containing this code, and if it is found, the file name of the JAR (e.g.: opennms_bootstrap.jar) and its parent directory (e.g.: the lib directory) are removed from the path and the resulting path (e.g.: /opt/OpenNMS) is returned.
        Returns:
        Home directory or null if it couldn't be found
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Bootloader main method. Takes the following steps to initialize a ClassLoader, set properties, and start OpenNMS:
        • Checks for existence of opennms.home system property, and loads properties file located at ${opennms.home}/etc/bootstrap.properties if it exists.
        • Calls findOpenNMSHome to determine the OpenNMS home directory if the bootstrap.properties file has not yet been loaded. Sets the opennms.home system property to the path returned from findOpenNMSHome.
        • Calls loadClasses to create a new ClassLoader. ${opennms.home}/etc and ${opennms.home}/lib are passed to loadClasses.
        • Determines the proper default value for configuration options when overriding system properties have not been set. Below are the default values.
          • opennms.library.jicmp: ClassLoader.getResource(System.mapLibraryName("jicmp"))
          • opennms.library.jrrd: ClassLoader.getResource(System.mapLibraryName("jrrd"))
          • log4j.configuration: "log4j.properties"
          • jcifs.properties: ClassLoader.getResource("jcifs.properties")
        • Finally, the main method of org.opennms.netmgt.vmmgr.Controller is invoked with the parameters passed in argv.
        Parameters:
        args - Command line arguments
        Throws:
        java.lang.Exception - if any.
      • executeClass

        protected static void executeClass​(java.lang.String classToExec,
                                           java.lang.String classToExecMethod,
                                           java.lang.String[] classToExecArgs,
                                           boolean appendClasspath)
                                    throws java.lang.ClassNotFoundException,
                                           java.lang.NoSuchMethodException,
                                           java.io.IOException
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.io.IOException
      • executeClass

        protected static void executeClass​(java.lang.String classToExec,
                                           java.lang.String classToExecMethod,
                                           java.lang.String[] classToExecArgs,
                                           boolean appendClasspath,
                                           boolean recurse)
                                    throws java.lang.ClassNotFoundException,
                                           java.lang.NoSuchMethodException,
                                           java.io.IOException
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.io.IOException