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>>addedlinksThe added links.protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>addtodoThe delayed add links (could not directly be added because the parent was not there).protected ChangeableURLClassLoaderbaseloaderThe base classloader.protected java.util.Map<IResourceIdentifier,DelegationURLClassLoader>classloadersThe map of managed resources 2xrid (local, remote) -> delegate loader).protected java.util.Map<IResourceIdentifier,Future<DelegationURLClassLoader>>clfutsThe class loader futures for currently loading class loaders.protected IInternalAccesscomponentThe component.protected java.util.List<java.lang.String[]>componentmodelsCached list of component models.protected java.lang.Object[]initurlsThe init urls.static java.lang.StringLIBRARY_SERVICEThe (standard) Library service name.protected java.util.Set<ILibraryServiceListener>listenersLibraryService listeners.protected java.util.Set<java.net.URI>nonmanagedThe non-managed urls (cached for speed).protected java.util.Set<Tuple2<IResourceIdentifier,IResourceIdentifier>>removedlinksThe remove links.protected Tuple2<IResourceIdentifier,java.util.Map<IResourceIdentifier,java.util.List<IResourceIdentifier>>>ridsThe dependencies.protected DelegationURLClassLoaderrootloaderThe delegation root loader.protected IResourceIdentifierrootridprotected IFuture<java.util.Collection<java.lang.String[]>>searchstatic IResourceIdentifierSYSTEMCPRIDThe 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 voidaddLink(IResourceIdentifier parid, IResourceIdentifier rid)Add a link.IFuture<IResourceIdentifier>addResourceIdentifier(IResourceIdentifier parid, IResourceIdentifier orid, boolean workspace)Add a new resource identifier.protected voidaddSupport(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 voidcheckLocalRid(IResourceIdentifier rid)Check if rid has local part and if it is null.protected java.net.URLcheckUri(java.net.URI uri)Check if a local url is backed by a file.protected java.net.URLcheckUrl(java.net.URL url)Check if a local url is backed by a file.protected voidcollectClasspathURLs(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 voidcollectManifestURLs(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 DelegationURLClassLoadercreateNewDelegationClassLoader(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.FilegetHashRidFile(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.StringgetJarName(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.URLgetRidUrl(IResourceIdentifier rid)Get the local file url for a rid.IResourceIdentifiergetRootResourceIdentifier()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 booleanisAvailable(IResourceIdentifier rid)Test, if a resource is available locally.protected voidnotifyAdditionListeners(IResourceIdentifier parid, IResourceIdentifier rid)Notify listeners about addition.protected voidnotifyRemovalListeners(IResourceIdentifier parid, IResourceIdentifier rid)Notify listeners about removal.IFuture<java.lang.Void>removeLibraryServiceListener(ILibraryServiceListener listener)Remove an Library Service listener.protected voidremoveLink(IResourceIdentifier parid, IResourceIdentifier rid)Remove a link.IFuture<java.lang.Void>removeResourceIdentifier(IResourceIdentifier parid, IResourceIdentifier rid)Remove a resource identifier.protected voidremoveSupport(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:
addResourceIdentifierin 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:
removeResourceIdentifierin interfaceILibraryService- Parameters:
uri- The resource identifier.
-
getRootResourceIdentifier
public IResourceIdentifier getRootResourceIdentifier()
Get the root resource identifier.- Specified by:
getRootResourceIdentifierin 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:
getAllResourceIdentifiersin 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:
getResourceIdentifiersin 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:
addURLin 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:
removeURLin 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:
addTopLevelURLin 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:
removeTopLevelURLin 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:
getNonManagedURLsin 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:
getAllURLsin interfaceILibraryService- Returns:
- The list of urls.
-
getClassLoader
public IFuture<java.lang.ClassLoader> getClassLoader(IResourceIdentifier rid)
Returns the current ClassLoader.- Specified by:
getClassLoaderin 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:
getClassLoaderin 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:
getResourceIdentifierin 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:
addLibraryServiceListenerin interfaceILibraryService- Parameters:
listener- The listener to be added.
-
removeLibraryServiceListener
public IFuture<java.lang.Void> removeLibraryServiceListener(ILibraryServiceListener listener)
Remove an Library Service listener.- Specified by:
removeLibraryServiceListenerin 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:
DelegationURLClassLoaderor 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:
getResourceAsStreamin 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:
getRemovableLinksin interfaceILibraryService
-
setProperties
public IFuture<java.lang.Void> setProperties(Properties props)
Update from given properties.- Specified by:
setPropertiesin interfaceIPropertiesProvider
-
getProperties
public IFuture<Properties> getProperties()
Write current state into properties.- Specified by:
getPropertiesin 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:
getComponentModelsin interfaceILibraryService- Returns:
- The file names of the component models.
-
-