Class Framework


  • public final class Framework
    extends Object
    This class is the main entry point to a Nuxeo runtime application.

    It offers an easy way to create new sessions, to access system services and other resources.

    There are two type of services:

    • Global Services - these services are uniquely defined by a service class, and there is an unique instance of the service in the system per class.
    • Local Services - these services are defined by a class and an URI. This type of service allows multiple service instances for the same class of services. Each instance is uniquely defined in the system by an URI.
    Author:
    Bogdan Stefanescu
    • Field Detail

      • NUXEO_STRICT_RUNTIME_SYSTEM_PROP

        @Deprecated(since="9.1")
        public static final String NUXEO_STRICT_RUNTIME_SYSTEM_PROP
        Deprecated.
        since 9.1 This property is not documented and doesn't work.
        Property to control strict runtime mode
        Since:
        5.6
        See Also:
        Constant Field Values
      • resourceLoader

        protected static SharedResourceLoader resourceLoader
        A class loader used to share resources between all bundles.

        This is useful to put resources outside any bundle (in a directory on the file system) and then refer them from XML contributions.

        The resource directory used by this loader is ${nuxeo_data_dir}/resources whee ${nuxeo_data_dir} is usually ${nuxeo_home}/data

      • isOSGiServiceSupported

        protected static Boolean isOSGiServiceSupported
        Whether or not services should be exported as OSGI services. This is controlled by the ${ecr.osgi.services} property. The default is false.
    • Method Detail

      • initialize

        public static void initialize​(RuntimeService runtimeService)
      • reloadResourceLoader

        public static void reloadResourceLoader()
      • reloadResourceLoader

        public static void reloadResourceLoader​(List<URL> urlsToAdd,
                                                List<URL> urlsToRemove)
        Reload the resources loader, keeping URLs already tracked, and adding possibility to add or remove some URLs.

        Useful for hot reload of jars.

        Since:
        5.6
      • isInitialized

        public static boolean isInitialized()
        Tests whether or not the runtime was initialized.
        Returns:
        true if the runtime was initialized, false otherwise
      • getRuntime

        public static RuntimeService getRuntime()
        Gets the runtime service instance.
        Returns:
        the runtime service instance
      • getService

        public static <T> T getService​(Class<T> serviceClass)
        Gets a service given its class.
      • doPrivileged

        public static void doPrivileged​(Runnable runnable)
        Runs the given Runnable while logged in as a system user.
        Parameters:
        runnable - what to run
        Since:
        8.4
      • doPrivileged

        public static <T> T doPrivileged​(Supplier<T> supplier)
        Calls the given Supplier while logged in as a system user and returns its result.
        Parameters:
        supplier - what to call
        Returns:
        the supplier's result
        Since:
        8.4
      • doPrivilegedThrowing

        public static <T,​E extends Throwable> T doPrivilegedThrowing​(ThrowableSupplier<T,​E> supplier)
                                                                    throws E extends Throwable
        Calls the given ThrowableSupplier while logged in as a system user and returns its result.
        Parameters:
        supplier - what to call
        Returns:
        the supplier's result
        Throws:
        E extends Throwable
        Since:
        11.3
      • loginSystem

        public static NuxeoLoginContext loginSystem​(String originatingUser)
        Login as the system user, remembering the originating user.

        The returned NuxeoLoginContext MUST be closed when done.

        If the originating user is null, then this is equivalent to loginSystem().

        Parameters:
        originatingUser - the originating user
        Returns:
        the login context, to be closed when done
        Since:
        11.1
        See Also:
        loginSystem()
      • loginAs

        @Deprecated
        public static LoginContext loginAs​(String originatingUser)
                                    throws LoginException
        Deprecated.
        since 11.1, use loginSystem(String) instead
        Login in the system as the system user (a pseudo-user having all privileges). The given username will be used to identify the user id that called this method.
        Parameters:
        originatingUser - the originating user id
        Returns:
        the login session if successful. Never returns null.
        Throws:
        LoginException - on login failure
      • addListener

        public static void addListener​(RuntimeServiceListener listener)
        Registers a listener to be notified about runtime events.

        If the listener is already registered, do nothing.

        Parameters:
        listener - the listener to register
      • removeListener

        public static void removeListener​(RuntimeServiceListener listener)
        Removes the given listener.

        If the listener is not registered, do nothing.

        Parameters:
        listener - the listener to remove
      • getProperty

        public static String getProperty​(String key)
        Gets the given property value if any, otherwise null.

        The framework properties will be searched first then if any matching property is found the system properties are searched too.

        Parameters:
        key - the property key
        Returns:
        the property value if any or null otherwise
      • getProperty

        public static String getProperty​(String key,
                                         String defValue)
        Gets the given property value if any, otherwise returns the given default value.

        The framework properties will be searched first then if any matching property is found the system properties are searched too.

        Parameters:
        key - the property key
        defValue - the default value to use
        Returns:
        the property value if any otherwise the default value
      • getProperties

        public static Properties getProperties()
        Gets all the framework properties. The system properties are not included in the returned map.
        Returns:
        the framework properties map. Never returns null.
      • expandVars

        public static String expandVars​(String expression)
        Expands any variable found in the given expression with the value of the corresponding framework property.

        The variable format is ${property_key}.

        System properties are also expanded.

      • isOSGiServiceSupported

        public static boolean isOSGiServiceSupported()
      • isDevModeSet

        public static boolean isDevModeSet()
        Returns true if dev mode is set.

        Activating this mode, some of the code may not behave as it would in production, to ease up debugging and working on developing the application.

        For instance, it'll enable hot-reload if some packages are installed while the framework is running. It will also reset some caches when that happens.

      • isTestModeSet

        public static boolean isTestModeSet()
        Returns true if test mode is set.

        Activating this mode, some of the code may not behave as it would in production, to ease up testing.

      • isBooleanPropertyFalse

        public static boolean isBooleanPropertyFalse​(String propName)
        Returns true if given property is false when compared to a boolean value. Returns false if given property in unset.

        Checks for the system properties if property is not found in the runtime properties.

        Since:
        5.8
      • isBooleanPropertyTrue

        public static boolean isBooleanPropertyTrue​(String propName)
        Returns true if given property is true when compared to a boolean value.

        Checks for the system properties if property is not found in the runtime properties.

        Since:
        5.6
      • trackFile

        public static void trackFile​(File file,
                                     Object marker)
        Tracks the specified file, using the provided marker, deleting the file when the marker instance is garbage collected.

        If the file is a directory, it is not deleted if not empty. To make sure a directory is deleted if not empty, use trackDirectory(File, Object).

        Parameters:
        file - the file to delete
        marker - the marker Object
        See Also:
        FileEventTracker
      • trackDirectory

        public static void trackDirectory​(File file,
                                          Object marker)
        Tracks the specified file, using the provided marker, deleting the file when the marker instance is garbage collected.

        Unlike trackFile(File, Object), the file is deleted even if it is a non empty directory.

        Parameters:
        file - the file to delete
        marker - the marker Object
        Since:
        2023.5
        See Also:
        trackFile(File, Object)
      • checkRuntimeInitialized

        protected static void checkRuntimeInitialized()
        Since:
        6.0