Class Framework
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static BooleanWhether or not services should be exported as OSGI services.static final StringGlobal dev propertystatic final StringGlobal testing propertyprotected static SharedResourceLoaderA class loader used to share resources between all bundles. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddListener(RuntimeServiceListener listener) Registers a listener to be notified about runtime events.protected static voidstatic PathcreateTempDirectory(String prefix, FileAttribute<?>... attrs) Creates a new directory in the framework temporary-file directory (nuxeo.tmp.dirvsjava.io.tmpdir), using the given prefix to generate its name.static FilecreateTempFile(String prefix, String suffix) Creates an empty file in the framework temporary-file directory (nuxeo.tmp.dirvsjava.io.tmpdir), using the given prefix and suffix to generate its name.static PathcreateTempFilePath(String prefix, String suffix, FileAttribute<?>... attrs) Creates an empty file in the framework temporary-file directory (nuxeo.tmp.dirvsjava.io.tmpdir), using the given prefix and suffix to generate its name.static voiddoPrivileged(Runnable runnable) Runs the givenRunnablewhile logged in as a system user.static <T> TdoPrivileged(Supplier<T> supplier) Calls the givenSupplierwhile logged in as a system user and returns its result.static <E extends Throwable>
voiddoPrivilegedThrowing(ThrowableRunnable<E> runnable) Runs the givenThrowableRunnablewhile logged in as a system user.static <T,E extends Throwable>
TdoPrivilegedThrowing(ThrowableSupplier<T, E> supplier) Calls the givenThrowableSupplierwhile logged in as a system user and returns its result.static StringexpandVars(String expression) Expands any variable found in the given expression with the value of the corresponding framework property.static PropertiesGets all the framework properties.static StringgetProperty(String key) Gets the given property value if any, otherwise null.static StringgetProperty(String key, String defValue) Gets the given property value if any, otherwise returns the given default value.static SharedResourceLoaderstatic RuntimeServiceGets the runtime service instance.static <T> TgetService(Class<T> serviceClass) Gets a service given its class.static voidinitialize(RuntimeService runtimeService) static booleanisBooleanPropertyFalse(String propName) Returns true if given property is false when compared to a boolean value.static booleanisBooleanPropertyTrue(String propName) Returns true if given property is true when compared to a boolean value.static booleanReturns true if dev mode is set.static booleanTests whether or not the runtime was initialized.static booleanstatic booleanReturns true if test mode is set.static LoginContextlogin()Deprecated.static LoginContextDeprecated.since 11.1, useloginUser(java.lang.String)insteadprotected static <T,E extends Throwable>
TloginAndDo(ThrowableSupplier<NuxeoLoginContext, LoginException> authSupplier, ThrowableSupplier<T, E> supplier) Logs in the Nuxeo platform using the givenauthSupplier, then gets the givensupplierbefore logging out.static LoginContextDeprecated.since 11.1, useloginSystem(String)insteadstatic LoginContextloginAsUser(String username) Deprecated.since 11.1, useloginUser(java.lang.String)insteadstatic NuxeoLoginContextLogin as the system user (with no originating user).static NuxeoLoginContextloginSystem(String originatingUser) Login as the system user, remembering the originating user.static NuxeoLoginContextLogin as the given user.static voidstatic voidreloadResourceLoader(List<URL> urlsToAdd, List<URL> urlsToRemove) Reload the resources loader, keeping URLs already tracked, and adding possibility to add or remove some URLs.static voidremoveListener(RuntimeServiceListener listener) Removes the given listener.static voidsendEvent(RuntimeServiceEvent event) static voidshutdown()static voidtrackDirectory(File file, Object marker) Tracks the specifiedfile, using the providedmarker, deleting the file when the marker instance is garbage collected.static voidTracks the specifiedfile, using the providedmarker, deleting the file when the marker instance is garbage collected.
-
Field Details
-
NUXEO_DEV_SYSTEM_PROP
Global dev property- Since:
- 5.6
- See Also:
-
NUXEO_TESTING_SYSTEM_PROP
Global testing property- Since:
- 5.6
- See Also:
-
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
Whether or not services should be exported as OSGI services. This is controlled by the ${ecr.osgi.services} property. The default is false.
-
-
Method Details
-
initialize
-
reloadResourceLoader
public static void reloadResourceLoader() -
reloadResourceLoader
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
-
shutdown
- Throws:
InterruptedException
-
isInitialized
public static boolean isInitialized()Tests whether or not the runtime was initialized.- Returns:
- true if the runtime was initialized, false otherwise
-
getResourceLoader
-
getRuntime
Gets the runtime service instance.- Returns:
- the runtime service instance
-
getService
Gets a service given its class. -
doPrivileged
Runs the givenRunnablewhile logged in as a system user.- Parameters:
runnable- what to run- Since:
- 8.4
-
doPrivileged
Calls the givenSupplierwhile 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 <E extends Throwable> void doPrivilegedThrowing(ThrowableRunnable<E> runnable) throws E Runs the givenThrowableRunnablewhile logged in as a system user.- Parameters:
runnable- what to run- Throws:
E extends Throwable- Since:
- 11.3
-
doPrivilegedThrowing
public static <T,E extends Throwable> T doPrivilegedThrowing(ThrowableSupplier<T, E> supplier) throws ECalls the givenThrowableSupplierwhile 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
-
loginAndDo
protected static <T,E extends Throwable> T loginAndDo(ThrowableSupplier<NuxeoLoginContext, LoginException> authSupplier, ThrowableSupplier<T, throws EE> supplier) Logs in the Nuxeo platform using the givenauthSupplier, then gets the givensupplierbefore logging out.- Throws:
E extends Throwable- Since:
- 11.1
-
loginSystem
Login as the system user (with no originating user).The returned
NuxeoLoginContextMUST be closed when done.- Returns:
- the login context, to be closed when done
- Since:
- 11.1
- See Also:
-
loginSystem
Login as the system user, remembering the originating user.The returned
NuxeoLoginContextMUST be closed when done.If the originating user is
null, then this is equivalent tologinSystem().- Parameters:
originatingUser- the originating user- Returns:
- the login context, to be closed when done
- Since:
- 11.1
- See Also:
-
loginUser
Login as the given user. The returnedNuxeoLoginContextMUST be closed when done.- Parameters:
username- the username- Returns:
- the login context, to be closed when done
- Throws:
LoginException- on login failure- Since:
- 11.1
-
login
Deprecated.since 11.1, useloginSystem()insteadLogin in the system as the system user (a pseudo-user having all privileges).- Returns:
- the login session if successful. Never returns null.
- Throws:
LoginException- on login failure
-
loginAs
Deprecated.since 11.1, useloginSystem(String)insteadLogin 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
-
loginAsUser
Deprecated.since 11.1, useloginUser(java.lang.String)insteadLogin in the system as the given user without checking the password.- Parameters:
username- the user name to login as.- Returns:
- the login context
- Throws:
LoginException- if any error occurs- Since:
- 5.4.2
-
login
@Deprecated public static LoginContext login(String username, Object password) throws LoginException Deprecated.since 11.1, useloginUser(java.lang.String)insteadLogin in the system as the given user using the given password.- Parameters:
username- the username to loginpassword- the password- Returns:
- a login session if login was successful. Never returns null.
- Throws:
LoginException- if login failed
-
sendEvent
-
addListener
Registers a listener to be notified about runtime events.If the listener is already registered, do nothing.
- Parameters:
listener- the listener to register
-
removeListener
Removes the given listener.If the listener is not registered, do nothing.
- Parameters:
listener- the listener to remove
-
getProperty
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
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 keydefValue- the default value to use- Returns:
- the property value if any otherwise the default value
-
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
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
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
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
Tracks the specifiedfile, using the providedmarker, deleting the file when the marker instance is garbage collected.If the
fileis a directory, it is not deleted if not empty. To make sure a directory is deleted if not empty, usetrackDirectory(File, Object).- Parameters:
file- the file to deletemarker- the marker Object- See Also:
-
trackDirectory
Tracks the specifiedfile, using the providedmarker, deleting the file when the marker instance is garbage collected.Unlike
trackFile(File, Object), thefileis deleted even if it is a non empty directory.- Parameters:
file- the file to deletemarker- the marker Object- Since:
- 2023.5
- See Also:
-
checkRuntimeInitialized
protected static void checkRuntimeInitialized()- Since:
- 6.0
-
createTempFile
Creates an empty file in the framework temporary-file directory (nuxeo.tmp.dirvsjava.io.tmpdir), using the given prefix and suffix to generate its name.Invoking this method is equivalent to invoking
.File.createTempFile(prefix, suffix, Environment.getDefault().getTemp())The
createTempFilePath(String, String, FileAttribute...)method provides an alternative method to create an empty file in the framework temporary-file directory. Files created by that method may have more restrictive access permissions to files created by this method and so may be more suited to security-sensitive applications.- Parameters:
prefix- The prefix string to be used in generating the file's name; must be at least three characters longsuffix- The suffix string to be used in generating the file's name; may benull, in which case the suffix".tmp"will be used- Returns:
- An abstract pathname denoting a newly-created empty file
- Throws:
IllegalArgumentException- If theprefixargument contains fewer than three charactersIOException- If a file could not be createdSecurityException- If a security manager exists and itsmethod does not allow a file to be createdSecurityManager.checkWrite(java.lang.String)- Since:
- 8.1
- See Also:
-
createTempFilePath
public static Path createTempFilePath(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException Creates an empty file in the framework temporary-file directory (nuxeo.tmp.dirvsjava.io.tmpdir), using the given prefix and suffix to generate its name. The resultingPathis associated with the defaultFileSystem.Invoking this method is equivalent to invoking
Files.createTempFile(Environment.getDefault().getTemp().toPath(), prefix, suffix, attrs).- Parameters:
prefix- the prefix string to be used in generating the file's name; may benullsuffix- the suffix string to be used in generating the file's name; may benull, in which case ".tmp" is usedattrs- an optional list of file attributes to set atomically when creating the file- Returns:
- the path to the newly created file that did not exist before this method was invoked
- Throws:
IllegalArgumentException- if the prefix or suffix parameters cannot be used to generate a candidate file nameUnsupportedOperationException- if the array contains an attribute that cannot be set atomically when creating the directoryIOException- if an I/O error occurs or the temporary-file directory does not existSecurityException- In the case of the default provider, and a security manager is installed, thecheckWritemethod is invoked to check write access to the file.- Since:
- 8.1
- See Also:
-
createTempDirectory
Creates a new directory in the framework temporary-file directory (nuxeo.tmp.dirvsjava.io.tmpdir), using the given prefix to generate its name. The resultingPathis associated with the defaultFileSystem.Invoking this method is equivalent to invoking
Files.createTempDirectory(Environment.getDefault().getTemp().toPath(), prefix, suffix, attrs).- Parameters:
prefix- the prefix string to be used in generating the directory's name; may benullattrs- an optional list of file attributes to set atomically when creating the directory- Returns:
- the path to the newly created directory that did not exist before this method was invoked
- Throws:
IllegalArgumentException- if the prefix cannot be used to generate a candidate directory nameUnsupportedOperationException- if the array contains an attribute that cannot be set atomically when creating the directoryIOException- if an I/O error occurs or the temporary-file directory does not existSecurityException- In the case of the default provider, and a security manager is installed, thecheckWritemethod is invoked to check write access when creating the directory.- Since:
- 8.1
- See Also:
-
loginSystem()instead