Package jadex.platform.service.library
Class LibraryService
- java.lang.Object
-
- jadex.platform.service.library.LibraryService
-
- All Implemented Interfaces:
ILibraryService
,IPropertiesProvider
public class LibraryService extends java.lang.Object implements ILibraryService, IPropertiesProvider
Library service for loading classpath elements.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>
addedlinks
The added links.protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>
addtodo
The delayed add links (could not directly be added because the parent was not there).protected ChangeableURLClassLoader
baseloader
The base classloader.protected java.util.Map<IResourceIdentifier,DelegationURLClassLoader>
classloaders
The map of managed resources 2xrid (local, remote) -> delegate loader).protected java.util.Map<IResourceIdentifier,Future<DelegationURLClassLoader>>
clfuts
The class loader futures for currently loading class loaders.protected IInternalAccess
component
The component.protected java.util.List<java.lang.String[]>
componentmodels
Cached list of component models.protected java.lang.Object[]
initurls
The init urls.static java.lang.String
LIBRARY_SERVICE
The (standard) Library service name.protected java.util.Set<ILibraryServiceListener>
listeners
LibraryService listeners.protected java.util.Set<java.net.URI>
nonmanaged
The non-managed urls (cached for speed).protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>
removedlinks
The remove links.protected Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>
rids
The dependencies.protected DelegationURLClassLoader
rootloader
The delegation root loader.protected IResourceIdentifier
rootrid
protected IFuture<java.util.Collection<java.lang.String[]>>
search
static IResourceIdentifier
SYSTEMCPRID
The pseudo system classpath rid.
-
Constructor Summary
Constructors Constructor Description LibraryService()
Creates a new LibraryService.LibraryService(java.lang.ClassLoader baseloader)
Creates a new LibraryService.LibraryService(java.lang.Object[] urls)
Creates a new LibraryService.LibraryService(java.lang.Object[] urls, java.lang.ClassLoader baseloader)
Creates a new LibraryService.LibraryService(java.lang.Object[] urls, java.lang.ClassLoader baseloader, java.util.Map<java.lang.String,java.lang.Object> properties)
Creates a new LibraryService.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IFuture<java.lang.Void>
addLibraryServiceListener(ILibraryServiceListener listener)
Add an Library Service listener.protected void
addLink(IResourceIdentifier parid, IResourceIdentifier rid)
Add a link.IFuture<IResourceIdentifier>
addResourceIdentifier(IResourceIdentifier parid, IResourceIdentifier orid, boolean workspace)
Add a new resource identifier.protected void
addSupport(IResourceIdentifier rid, IResourceIdentifier parid)
Add support for a rid.IFuture<java.lang.Void>
addTopLevelURL(java.net.URL purl)
Add a top level url.IFuture<IResourceIdentifier>
addURL(IResourceIdentifier parid, java.net.URL purl)
Add a new url.protected void
checkLocalRid(IResourceIdentifier rid)
Check if rid has local part and if it is null.protected java.net.URL
checkUri(java.net.URI uri)
Check if a local url is backed by a file.protected java.net.URL
checkUrl(java.net.URL url)
Check if a local url is backed by a file.protected void
collectClasspathURLs(java.lang.ClassLoader classloader, java.util.Set<java.net.URI> set, java.util.Set<java.lang.String> jarnames)
Collect all URLs belonging to a class loader.protected void
collectManifestURLs(java.net.URI url, java.util.Set<java.net.URI> set, java.util.Set<java.lang.String> jarnames)
Collect all URLs as specified in a manifest.protected IFuture<DelegationURLClassLoader>
createClassLoader(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> alldeps, IResourceIdentifier support, boolean workspace)
Create a new classloader.protected DelegationURLClassLoader
createNewDelegationClassLoader(IResourceIdentifier rid, java.lang.ClassLoader baseloader, DelegationURLClassLoader[] delegates)
Handle instantiation here, so the DelegationURLClassLoader can be another implementation.protected IFuture<java.lang.Void>
downloadResource(IResourceIdentifier rid)
Download a resource from another platform.IFuture<java.util.List<IResourceIdentifier>>
getAllResourceIdentifiers()
Get all resource identifiers (does not include urls of parent loader).IFuture<java.util.List<java.net.URL>>
getAllURLs()
Get all urls (managed, indirect and non-managed from parent loader).IFuture<java.lang.ClassLoader>
getClassLoader(IResourceIdentifier rid)
Returns the current ClassLoader.IFuture<java.lang.ClassLoader>
getClassLoader(IResourceIdentifier rid, boolean workspace)
Returns the current ClassLoader.protected IFuture<DelegationURLClassLoader>
getClassLoader(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> alldeps, IResourceIdentifier support, boolean workspace)
Get or create a classloader for a rid.IFuture<java.util.Collection<java.lang.String[]>>
getComponentModels()
todo: support all component models Get all startable component models (currently only Java classes with @Agent).protected IFuture<Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>>
getDependencies(IResourceIdentifier rid, boolean workspace)
Get the dependent urls.protected java.io.File
getHashRidFile(IResourceIdentifier rid)
Get the file for a hash rid.protected java.util.Set<java.net.URI>
getInternalNonManagedURLs()
Get other contained (but not directly managed) urls from parent classloaders.protected static java.lang.String
getJarName(java.lang.String filename)
Get the name of a jar file without extension and version info.IFuture<java.util.List<java.net.URL>>
getNonManagedURLs()
Get other contained (but not directly managed) urls from parent classloaders.IFuture<Properties>
getProperties()
Write current state into properties.IFuture<java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>>
getRemovableLinks()
Get the removable links.IFuture<IInputConnection>
getResourceAsStream(IResourceIdentifier rid)
Get a resource as stream (jar).IFuture<IResourceIdentifier>
getResourceIdentifier(java.net.URL url)
Get the resource identifier for an url.IFuture<Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>>
getResourceIdentifiers()
Get the rids.protected java.net.URL
getRidUrl(IResourceIdentifier rid)
Get the local file url for a rid.IResourceIdentifier
getRootResourceIdentifier()
Get the root resource identifier.java.util.Set<IResourceIdentifier>
internalgetAllResourceIdentifiers()
Get all managed resource identifiers inlcuding all subdependencies.protected IFuture<IResourceIdentifier>
internalGetResourceIdentifier(java.net.URL url)
Get the resource identifier for an url.Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>
internalGetResourceIdentifiers()
protected boolean
isAvailable(IResourceIdentifier rid)
Test, if a resource is available locally.protected void
notifyAdditionListeners(IResourceIdentifier parid, IResourceIdentifier rid)
Notify listeners about addition.protected void
notifyRemovalListeners(IResourceIdentifier parid, IResourceIdentifier rid)
Notify listeners about removal.IFuture<java.lang.Void>
removeLibraryServiceListener(ILibraryServiceListener listener)
Remove an Library Service listener.protected void
removeLink(IResourceIdentifier parid, IResourceIdentifier rid)
Remove a link.IFuture<java.lang.Void>
removeResourceIdentifier(IResourceIdentifier parid, IResourceIdentifier rid)
Remove a resource identifier.protected void
removeSupport(IResourceIdentifier rid, IResourceIdentifier parid)
Remove support for a rid.IFuture<java.lang.Void>
removeTopLevelURL(java.net.URL url)
Remove a top level url.IFuture<java.lang.Void>
removeURL(IResourceIdentifier parid, java.net.URL url)
Remove a new url.IFuture<java.lang.Void>
setProperties(Properties props)
Update from given properties.IFuture<java.lang.Void>
shutdownService()
Shutdown the service.IFuture<java.lang.Void>
startService()
Start the service.
-
-
-
Field Detail
-
LIBRARY_SERVICE
public static final java.lang.String LIBRARY_SERVICE
The (standard) Library service name.- See Also:
- Constant Field Values
-
SYSTEMCPRID
public static final IResourceIdentifier SYSTEMCPRID
The pseudo system classpath rid.
-
component
protected IInternalAccess component
The component.
-
listeners
protected java.util.Set<ILibraryServiceListener> listeners
LibraryService listeners.
-
initurls
protected java.lang.Object[] initurls
The init urls.
-
clfuts
protected java.util.Map<IResourceIdentifier,Future<DelegationURLClassLoader>> clfuts
The class loader futures for currently loading class loaders.
-
classloaders
protected java.util.Map<IResourceIdentifier,DelegationURLClassLoader> classloaders
The map of managed resources 2xrid (local, remote) -> delegate loader).
-
baseloader
protected ChangeableURLClassLoader baseloader
The base classloader.
-
rootloader
protected DelegationURLClassLoader rootloader
The delegation root loader.
-
rootrid
protected IResourceIdentifier rootrid
-
addedlinks
protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>> addedlinks
The added links.
-
removedlinks
protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>> removedlinks
The remove links.
-
addtodo
protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>> addtodo
The delayed add links (could not directly be added because the parent was not there).
-
rids
protected Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>> rids
The dependencies.
-
nonmanaged
protected java.util.Set<java.net.URI> nonmanaged
The non-managed urls (cached for speed).
-
componentmodels
protected java.util.List<java.lang.String[]> componentmodels
Cached list of component models.
-
search
protected IFuture<java.util.Collection<java.lang.String[]>> search
-
-
Constructor Detail
-
LibraryService
public LibraryService()
Creates a new LibraryService.
-
LibraryService
public LibraryService(java.lang.Object[] urls)
Creates a new LibraryService.- Parameters:
urls
- Urls may be specified as java.net.URLs, java.io.Files or java.lang.Strings. Strings are interpreted as relative files (relative to current directory), absolute files or URLs (whatever can be found).
-
LibraryService
public LibraryService(java.lang.ClassLoader baseloader)
Creates a new LibraryService.- Parameters:
baseloader
- The base classloader that is parent of all subloaders.
-
LibraryService
public LibraryService(java.lang.Object[] urls, java.lang.ClassLoader baseloader)
Creates a new LibraryService.- Parameters:
urls
- Urls may be specified as java.net.URLs, java.io.Files or java.lang.Strings. Strings are interpreted as relative files (relative to current directory), absolute files or URLs (whatever can be found).
-
LibraryService
public LibraryService(java.lang.Object[] urls, java.lang.ClassLoader baseloader, java.util.Map<java.lang.String,java.lang.Object> properties)
Creates a new LibraryService.- Parameters:
urls
- Urls may be specified as java.net.URLs, java.io.Files or java.lang.Strings. Strings are interpreted as relative files (relative to current directory), absolute files or URLs (whatever can be found).
-
-
Method Detail
-
checkLocalRid
protected void checkLocalRid(IResourceIdentifier rid)
Check if rid has local part and if it is null.
-
addResourceIdentifier
public IFuture<IResourceIdentifier> addResourceIdentifier(IResourceIdentifier parid, IResourceIdentifier orid, boolean workspace)
Add a new resource identifier.- Specified by:
addResourceIdentifier
in interfaceILibraryService
- Parameters:
parid
- The optional parent rid.orid
- The resource identifier.
-
removeResourceIdentifier
public IFuture<java.lang.Void> removeResourceIdentifier(IResourceIdentifier parid, IResourceIdentifier rid)
Remove a resource identifier.- Specified by:
removeResourceIdentifier
in interfaceILibraryService
- Parameters:
uri
- The resource identifier.
-
getRootResourceIdentifier
public IResourceIdentifier getRootResourceIdentifier()
Get the root resource identifier.- Specified by:
getRootResourceIdentifier
in interfaceILibraryService
- Parameters:
uri
- The url.- Returns:
- The corresponding resource identifier.
-
getAllResourceIdentifiers
public IFuture<java.util.List<IResourceIdentifier>> getAllResourceIdentifiers()
Get all resource identifiers (does not include urls of parent loader).- Specified by:
getAllResourceIdentifiers
in interfaceILibraryService
- Returns:
- The list of resource identifiers.
-
getResourceIdentifiers
public IFuture<Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>> getResourceIdentifiers()
Get the rids.- Specified by:
getResourceIdentifiers
in interfaceILibraryService
-
internalGetResourceIdentifiers
public Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>> internalGetResourceIdentifiers()
-
addURL
public IFuture<IResourceIdentifier> addURL(IResourceIdentifier parid, java.net.URL purl)
Add a new url.- Specified by:
addURL
in interfaceILibraryService
- Parameters:
uri
- The resource identifier.
-
removeURL
public IFuture<java.lang.Void> removeURL(IResourceIdentifier parid, java.net.URL url)
Remove a new url.- Specified by:
removeURL
in interfaceILibraryService
- Parameters:
url
- The resource identifier.parid
- The resource identifier (null for root entry).
-
addTopLevelURL
public IFuture<java.lang.Void> addTopLevelURL(java.net.URL purl)
Add a top level url. A top level url will be available for all subordinated resources.- Specified by:
addTopLevelURL
in interfaceILibraryService
- Parameters:
uri
- The url.
-
removeTopLevelURL
public IFuture<java.lang.Void> removeTopLevelURL(java.net.URL url)
Remove a top level url. A top level url will be available for all subordinated resources.- Specified by:
removeTopLevelURL
in interfaceILibraryService
- Parameters:
url
- The url. note: top level url removal will only take effect after restart of the platform.
-
getNonManagedURLs
public IFuture<java.util.List<java.net.URL>> getNonManagedURLs()
Get other contained (but not directly managed) urls from parent classloaders.- Specified by:
getNonManagedURLs
in interfaceILibraryService
- Returns:
- The list of urls.
-
getInternalNonManagedURLs
protected java.util.Set<java.net.URI> getInternalNonManagedURLs()
Get other contained (but not directly managed) urls from parent classloaders.- Returns:
- The set of urls.
-
getAllURLs
public IFuture<java.util.List<java.net.URL>> getAllURLs()
Get all urls (managed, indirect and non-managed from parent loader).- Specified by:
getAllURLs
in interfaceILibraryService
- Returns:
- The list of urls.
-
getClassLoader
public IFuture<java.lang.ClassLoader> getClassLoader(IResourceIdentifier rid)
Returns the current ClassLoader.- Specified by:
getClassLoader
in interfaceILibraryService
- Parameters:
rid
- The resource identifier.- Returns:
- the current ClassLoader
-
getClassLoader
public IFuture<java.lang.ClassLoader> getClassLoader(IResourceIdentifier rid, boolean workspace)
Returns the current ClassLoader.- Specified by:
getClassLoader
in interfaceILibraryService
- Parameters:
rid
- The resource identifier (null for current global loader).workspace
- True if workspace resolution is ok.- Returns:
- the current ClassLoader
-
getResourceIdentifier
public IFuture<IResourceIdentifier> getResourceIdentifier(java.net.URL url)
Get the resource identifier for an url.- Specified by:
getResourceIdentifier
in interfaceILibraryService
- Parameters:
url
- The url.- Returns:
- The resource identifier.
-
addLibraryServiceListener
public IFuture<java.lang.Void> addLibraryServiceListener(ILibraryServiceListener listener)
Add an Library Service listener. The listener is registered for changes in the loaded library states.- Specified by:
addLibraryServiceListener
in interfaceILibraryService
- Parameters:
listener
- The listener to be added.
-
removeLibraryServiceListener
public IFuture<java.lang.Void> removeLibraryServiceListener(ILibraryServiceListener listener)
Remove an Library Service listener.- Specified by:
removeLibraryServiceListener
in interfaceILibraryService
- Parameters:
listener
- The listener to be removed.
-
getClassLoader
protected IFuture<DelegationURLClassLoader> getClassLoader(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> alldeps, IResourceIdentifier support, boolean workspace)
Get or create a classloader for a rid.
-
createClassLoader
protected IFuture<DelegationURLClassLoader> createClassLoader(IResourceIdentifier rid, java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>> alldeps, IResourceIdentifier support, boolean workspace)
Create a new classloader.
-
createNewDelegationClassLoader
protected DelegationURLClassLoader createNewDelegationClassLoader(IResourceIdentifier rid, java.lang.ClassLoader baseloader, DelegationURLClassLoader[] delegates)
Handle instantiation here, so the DelegationURLClassLoader can be another implementation.- Parameters:
rid
-baseloader
-delegates
-- Returns:
DelegationURLClassLoader
or subclass.
-
getRidUrl
protected java.net.URL getRidUrl(IResourceIdentifier rid)
Get the local file url for a rid.
-
isAvailable
protected boolean isAvailable(IResourceIdentifier rid)
Test, if a resource is available locally.
-
getHashRidFile
protected java.io.File getHashRidFile(IResourceIdentifier rid)
Get the file for a hash rid.
-
downloadResource
protected IFuture<java.lang.Void> downloadResource(IResourceIdentifier rid)
Download a resource from another platform.
-
getResourceAsStream
public IFuture<IInputConnection> getResourceAsStream(IResourceIdentifier rid)
Get a resource as stream (jar).- Specified by:
getResourceAsStream
in interfaceILibraryService
-
getDependencies
protected IFuture<Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>> getDependencies(IResourceIdentifier rid, boolean workspace)
Get the dependent urls.
-
addSupport
protected void addSupport(IResourceIdentifier rid, IResourceIdentifier parid)
Add support for a rid.
-
removeSupport
protected void removeSupport(IResourceIdentifier rid, IResourceIdentifier parid)
Remove support for a rid.
-
notifyAdditionListeners
protected void notifyAdditionListeners(IResourceIdentifier parid, IResourceIdentifier rid)
Notify listeners about addition.
-
notifyRemovalListeners
protected void notifyRemovalListeners(IResourceIdentifier parid, IResourceIdentifier rid)
Notify listeners about removal.
-
internalGetResourceIdentifier
protected IFuture<IResourceIdentifier> internalGetResourceIdentifier(java.net.URL url)
Get the resource identifier for an url.
-
startService
public IFuture<java.lang.Void> startService()
Start the service.
-
shutdownService
public IFuture<java.lang.Void> shutdownService()
Shutdown the service. Releases all cached resources and shuts down the library service.- Parameters:
listener
- The listener.
-
collectClasspathURLs
protected void collectClasspathURLs(java.lang.ClassLoader classloader, java.util.Set<java.net.URI> set, java.util.Set<java.lang.String> jarnames)
Collect all URLs belonging to a class loader.
-
getJarName
protected static java.lang.String getJarName(java.lang.String filename)
Get the name of a jar file without extension and version info.
-
collectManifestURLs
protected void collectManifestURLs(java.net.URI url, java.util.Set<java.net.URI> set, java.util.Set<java.lang.String> jarnames)
Collect all URLs as specified in a manifest.
-
addLink
protected void addLink(IResourceIdentifier parid, IResourceIdentifier rid)
Add a link.
-
removeLink
protected void removeLink(IResourceIdentifier parid, IResourceIdentifier rid)
Remove a link.
-
getRemovableLinks
public IFuture<java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>> getRemovableLinks()
Get the removable links.- Specified by:
getRemovableLinks
in interfaceILibraryService
-
setProperties
public IFuture<java.lang.Void> setProperties(Properties props)
Update from given properties.- Specified by:
setProperties
in interfaceIPropertiesProvider
-
getProperties
public IFuture<Properties> getProperties()
Write current state into properties.- Specified by:
getProperties
in interfaceIPropertiesProvider
-
checkUri
protected java.net.URL checkUri(java.net.URI uri)
Check if a local url is backed by a file.
-
checkUrl
protected java.net.URL checkUrl(java.net.URL url)
Check if a local url is backed by a file.
-
internalgetAllResourceIdentifiers
public java.util.Set<IResourceIdentifier> internalgetAllResourceIdentifiers()
Get all managed resource identifiers inlcuding all subdependencies.- Returns:
- The resource identifiers.
-
getComponentModels
public IFuture<java.util.Collection<java.lang.String[]>> getComponentModels()
todo: support all component models Get all startable component models (currently only Java classes with @Agent).- Specified by:
getComponentModels
in interfaceILibraryService
- Returns:
- The file names of the component models.
-
-