Class DefaultRuntimeContext
- java.lang.Object
-
- org.nuxeo.runtime.model.impl.DefaultRuntimeContext
-
- All Implemented Interfaces:
RuntimeContext
- Direct Known Subclasses:
OSGiRuntimeContext
public class DefaultRuntimeContext extends Object implements RuntimeContext
New behavior @since 9.2 As the runtime lifecycle changed there make no sense to unregister components by their own.The component registry is either reset to a clean state or shutdown.
So methods like unregister by location used in tests make no sense. These methods are preserved yet for compatibility with some tests but may be removed in future.
Also when a context is destroyed we unregister all the components the context deployed.
This is also deprecated since the unregister component is deprecated too.
The code inside destroy method was removed too since the deployedFiles map was removed.
This map posed problems with the registry snapshot approaches since it was not kept in sync with the registry.
If unregistering components will be removed completely don't forget to remove
ComponentManager.unregisterByLocation(String)
and theComponentRegistry.deployedFiles
.Features like studio or IDE which needs unregistering components must use their own mechanism.
- Author:
- Bogdan Stefanescu
-
-
Field Summary
Fields Modifier and Type Field Description protected List<ComponentName>
components
The list of component names deployed by this context.protected ComponentDescriptorReader
reader
protected RuntimeService
runtime
-
Constructor Summary
Constructors Constructor Description DefaultRuntimeContext()
DefaultRuntimeContext(RuntimeService runtime)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationInfoImpl
createRegistrationInfo(InputStream in)
RegistrationInfoImpl
createRegistrationInfo(StreamRef ref)
RegistrationInfo
deploy(String location)
Deploys the component whose XML descriptor is at the given location.RegistrationInfo
deploy(URL url)
Deploys a component XML descriptor given its URL.RegistrationInfo
deploy(StreamRef ref)
Same asRuntimeContext.deploy(URL)
but using aStreamRef
as argument.void
destroy()
Destroys this context.org.osgi.framework.Bundle
getBundle()
Gets the container bundle or null if we are not running in an OSGi environment.ComponentName[]
getComponents()
Get the component names deployed by this contextURL
getLocalResource(String name)
Finds a local resource having the given name.URL
getResource(String name)
Finds a resource having the given name.RuntimeService
getRuntime()
Gets the current runtime service.boolean
isDeployed(String location)
Checks if the component at the given location is deployed.boolean
isDeployed(URL url)
Checks whether the component XML file at given URL was deployed.boolean
isDeployed(StreamRef ref)
Checks whether the component XML file given by the StreamRef argument was deployed.Class<?>
loadClass(String className)
Loads the class given its name.void
setRuntime(RuntimeService runtime)
void
undeploy(String location)
Undeploys the component at the given location if any was deployed.void
undeploy(URL url)
Undeploys a component XML descriptor given its URL.void
undeploy(StreamRef ref)
Same asRuntimeContext.undeploy(URL)
but using aStreamRef
as stream reference.
-
-
-
Field Detail
-
runtime
protected RuntimeService runtime
-
components
protected List<ComponentName> components
The list of component names deployed by this context.- Since:
- 9.2
-
reader
protected final ComponentDescriptorReader reader
-
-
Constructor Detail
-
DefaultRuntimeContext
public DefaultRuntimeContext()
-
DefaultRuntimeContext
public DefaultRuntimeContext(RuntimeService runtime)
-
-
Method Detail
-
setRuntime
public void setRuntime(RuntimeService runtime)
-
getRuntime
public RuntimeService getRuntime()
Description copied from interface:RuntimeContext
Gets the current runtime service.- Specified by:
getRuntime
in interfaceRuntimeContext
- Returns:
- the runtime service
-
getComponents
public ComponentName[] getComponents()
Description copied from interface:RuntimeContext
Get the component names deployed by this context- Specified by:
getComponents
in interfaceRuntimeContext
- Returns:
- the list of components. Return an empty array if no components where deployed.
-
getResource
public URL getResource(String name)
Description copied from interface:RuntimeContext
Finds a resource having the given name.- Specified by:
getResource
in interfaceRuntimeContext
- Parameters:
name
- the resource name- Returns:
- an URL to the resource having that name or null if not was found
- See Also:
ClassLoader.getResource(String)
-
getLocalResource
public URL getLocalResource(String name)
Description copied from interface:RuntimeContext
Finds a local resource having the given name.Only the current bundle should be searched for the resource.
- Specified by:
getLocalResource
in interfaceRuntimeContext
- Parameters:
name
- the local resource name- Returns:
- an URL to the resource having that name or null if not was found
- See Also:
ClassLoader.getResource(String)
-
loadClass
public Class<?> loadClass(String className) throws ClassNotFoundException
Description copied from interface:RuntimeContext
Loads the class given its name.- Specified by:
loadClass
in interfaceRuntimeContext
- Parameters:
className
- the class name- Returns:
- the class object
- Throws:
ClassNotFoundException
- if no such class were found- See Also:
ClassLoader.loadClass(String)
-
deploy
public RegistrationInfo deploy(URL url) throws IOException
Description copied from interface:RuntimeContext
Deploys a component XML descriptor given its URL.Do nothing if component is already deployed.
Returns the registration info of the new deployed component or null if the component was not deployed.
- Specified by:
deploy
in interfaceRuntimeContext
- Parameters:
url
- the url of the XML descriptor- Returns:
- the component registration info or null if registration failed for some reason
- Throws:
IOException
-
deploy
public RegistrationInfo deploy(StreamRef ref) throws IOException
Description copied from interface:RuntimeContext
Same asRuntimeContext.deploy(URL)
but using aStreamRef
as argument.- Specified by:
deploy
in interfaceRuntimeContext
- Throws:
IOException
-
undeploy
public void undeploy(URL url)
Description copied from interface:RuntimeContext
Undeploys a component XML descriptor given its URL.Do nothing if no component was registered for the given URL.
- Specified by:
undeploy
in interfaceRuntimeContext
- Parameters:
url
- the URL of the XML descriptor
-
undeploy
public void undeploy(StreamRef ref)
Description copied from interface:RuntimeContext
Same asRuntimeContext.undeploy(URL)
but using aStreamRef
as stream reference.- Specified by:
undeploy
in interfaceRuntimeContext
-
isDeployed
public boolean isDeployed(URL url)
Description copied from interface:RuntimeContext
Checks whether the component XML file at given URL was deployed.- Specified by:
isDeployed
in interfaceRuntimeContext
- Parameters:
url
- the URL to check- Returns:
- true it deployed, false otherwise
-
isDeployed
public boolean isDeployed(StreamRef ref)
Description copied from interface:RuntimeContext
Checks whether the component XML file given by the StreamRef argument was deployed.- Specified by:
isDeployed
in interfaceRuntimeContext
-
deploy
public RegistrationInfo deploy(String location)
Description copied from interface:RuntimeContext
Deploys the component whose XML descriptor is at the given location.If the component is already deployed do nothing.
The location is interpreted as a relative path inside the bundle (jar) containing the component - and will be loaded using
RuntimeContext.getLocalResource(String)
.Returns the registration info of the new deployed component or null if the component was not deployed.
- Specified by:
deploy
in interfaceRuntimeContext
- Parameters:
location
- the location- Returns:
- the component registration info or null if registration failed for some reason
-
undeploy
public void undeploy(String location)
Description copied from interface:RuntimeContext
Undeploys the component at the given location if any was deployed.If the component was not deployed do nothing.
- Specified by:
undeploy
in interfaceRuntimeContext
- Parameters:
location
- the location of the component to undeploy
-
isDeployed
public boolean isDeployed(String location)
Description copied from interface:RuntimeContext
Checks if the component at the given location is deployed.- Specified by:
isDeployed
in interfaceRuntimeContext
- Parameters:
location
- the component location to check- Returns:
- true if deployed, false otherwise
-
destroy
public void destroy()
Description copied from interface:RuntimeContext
Destroys this context.- Specified by:
destroy
in interfaceRuntimeContext
-
getBundle
public org.osgi.framework.Bundle getBundle()
Description copied from interface:RuntimeContext
Gets the container bundle or null if we are not running in an OSGi environment.- Specified by:
getBundle
in interfaceRuntimeContext
-
createRegistrationInfo
public RegistrationInfoImpl createRegistrationInfo(StreamRef ref) throws IOException
- Throws:
IOException
-
createRegistrationInfo
public RegistrationInfoImpl createRegistrationInfo(InputStream in) throws IOException
- Throws:
IOException
-
-