Package aQute.bnd.resource.repository
Class ResourceRepositoryImpl
- java.lang.Object
-
- aQute.bnd.resource.repository.ResourceRepositoryImpl
-
- All Implemented Interfaces:
ResourceRepository
public class ResourceRepositoryImpl extends java.lang.Object implements ResourceRepository
This class implements a hidden repository. This repo is kept in a text file that is under scm control. Files are fetched on demand. The idea is that bnd will bootstrap from this repo and downloads plugins. These plugins then provide faces on this hidden repository.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResourceRepositoryImpl.FileLayoutClass maintains the info stored in the text file in the cnf directory that holds our contents.-
Nested classes/interfaces inherited from interface aQute.bnd.service.repository.ResourceRepository
ResourceRepository.Listener, ResourceRepository.ResourceRepositoryEvent, ResourceRepository.TYPE
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.Filecache(package private) static JSONCodeccodecprivate URLConnectionHandlerconnectorprivate booleandirtyprotected static RepositoryPlugin.DownloadListener[]EMPTY_LISTENERprivate java.util.concurrent.Executorexecutorprivate java.util.Map<java.net.URI,java.lang.Long>failuresprivate java.io.Filehostingprivate ResourceRepositoryImpl.FileLayoutindexprivate java.io.FileindexFile(package private) java.util.concurrent.SemaphorelimitDownloadsprivate java.util.List<ResourceRepository.Listener>listenersprivate static org.slf4j.Loggerlogger(package private) MultiMap<java.io.File,RepositoryPlugin.DownloadListener>queuesprivate Reporterreporterprivate static java.util.Comparator<SearchableRepository.ResourceDescriptor>RESOURCE_DESCRIPTOR_COMPARATORprivate static longTHRESHOLD-
Fields inherited from interface aQute.bnd.service.repository.ResourceRepository
FILENAME
-
-
Constructor Summary
Constructors Constructor Description ResourceRepositoryImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.String repoId, SearchableRepository.ResourceDescriptor rd)Add a resource descriptor to the index.voidaddListener(ResourceRepository.Listener rrl)Add a new event listener(package private) voiddelete(byte[] id)Delete a resource from the text file (not from the cache)booleandelete(java.lang.String repoId, byte[] id)booleandeleteCache(byte[] id)Delete a cache entry(package private) voiddownload(SearchableRepository.ResourceDescriptor rds, java.io.File path)(package private) voiddownload0(java.net.URI url, java.io.File path, byte[] sha)private voidevent(ResourceRepository.TYPE type, SearchableRepository.ResourceDescriptor rds, java.lang.Exception exception)Dispatch the events(package private) voidfail(java.lang.Exception e, RepositoryPlugin.DownloadListener[] blockers, java.io.File file)java.util.List<ResourceDescriptorImpl>filter(java.lang.String repoId, java.lang.String filter)List the resources.java.util.SortedSet<SearchableRepository.ResourceDescriptor>find(java.lang.String repoId, java.lang.String bsn, VersionRange range)java.io.FilegetCacheDir(java.lang.String name)private ResourceRepositoryImpl.FileLayoutgetIndex()Get the index, load it if necessaryjava.io.FilegetResource(byte[] rd, RepositoryPlugin.DownloadListener... blockers)Get the file belonging to a Resource DescriptorResourceDescriptorImplgetResourceDescriptor(byte[] rd)List the resources.(package private) voidok(RepositoryPlugin.DownloadListener[] blockers, java.io.File file)Just report success to all download listenersvoidremoveListener(ResourceRepository.Listener rrl)Remove an event listenerprivate voidsave()Save the index file.voidsetCache(java.io.File cache)private voidsetDirty()Set dirty for save.voidsetExecutor(java.util.concurrent.Executor executor)voidsetIndexFile(java.io.File file)voidsetReporter(Reporter processor)voidsetURLConnector(URLConnectionHandler connector)private booleansleep(int i)Sleep function that does not throwInterruptedExceptionjava.lang.StringtoString()
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
RESOURCE_DESCRIPTOR_COMPARATOR
private static java.util.Comparator<SearchableRepository.ResourceDescriptor> RESOURCE_DESCRIPTOR_COMPARATOR
-
THRESHOLD
private static final long THRESHOLD
- See Also:
- Constant Field Values
-
EMPTY_LISTENER
protected static final RepositoryPlugin.DownloadListener[] EMPTY_LISTENER
-
codec
static JSONCodec codec
-
listeners
private final java.util.List<ResourceRepository.Listener> listeners
-
dirty
private boolean dirty
-
index
private ResourceRepositoryImpl.FileLayout index
-
failures
private java.util.Map<java.net.URI,java.lang.Long> failures
-
cache
private java.io.File cache
-
hosting
private java.io.File hosting
-
reporter
private Reporter reporter
-
executor
private java.util.concurrent.Executor executor
-
indexFile
private java.io.File indexFile
-
connector
private URLConnectionHandler connector
-
queues
final MultiMap<java.io.File,RepositoryPlugin.DownloadListener> queues
-
limitDownloads
final java.util.concurrent.Semaphore limitDownloads
-
-
Method Detail
-
filter
public java.util.List<ResourceDescriptorImpl> filter(java.lang.String repoId, java.lang.String filter) throws java.lang.Exception
List the resources. We skip the filter for now.- Specified by:
filterin interfaceResourceRepositoryfilter- An OSGi filter matched against theSearchableRepository.ResourceDescriptor- Returns:
- an immutable list of resource descriptors
- Throws:
java.lang.Exception
-
delete
void delete(byte[] id) throws java.lang.ExceptionDelete a resource from the text file (not from the cache)- Throws:
java.lang.Exception
-
delete
public boolean delete(java.lang.String repoId, byte[] id) throws java.lang.Exception- Specified by:
deletein interfaceResourceRepository- Throws:
java.lang.Exception
-
deleteCache
public boolean deleteCache(byte[] id) throws java.lang.ExceptionDelete a cache entry- Specified by:
deleteCachein interfaceResourceRepository- Throws:
java.lang.Exception
-
add
public boolean add(java.lang.String repoId, SearchableRepository.ResourceDescriptor rd) throws java.lang.ExceptionAdd a resource descriptor to the index.- Specified by:
addin interfaceResourceRepository- Throws:
java.lang.Exception
-
getResource
public java.io.File getResource(byte[] rd, RepositoryPlugin.DownloadListener... blockers) throws java.lang.ExceptionGet the file belonging to a Resource Descriptor- Specified by:
getResourcein interfaceResourceRepository- Throws:
java.lang.Exception
-
addListener
public void addListener(ResourceRepository.Listener rrl)
Add a new event listener- Specified by:
addListenerin interfaceResourceRepository
-
removeListener
public void removeListener(ResourceRepository.Listener rrl)
Remove an event listener
-
setDirty
private void setDirty()
Set dirty for save. Save is a noop if not dirty
-
getResourceDescriptor
public ResourceDescriptorImpl getResourceDescriptor(byte[] rd) throws java.lang.Exception
List the resources. We skip the filter for now.- Specified by:
getResourceDescriptorin interfaceResourceRepository- Throws:
java.lang.Exception
-
ok
void ok(RepositoryPlugin.DownloadListener[] blockers, java.io.File file)
Just report success to all download listeners- Parameters:
blockers-file-
-
fail
void fail(java.lang.Exception e, RepositoryPlugin.DownloadListener[] blockers, java.io.File file)
-
download
void download(SearchableRepository.ResourceDescriptor rds, java.io.File path) throws java.lang.Exception
- Throws:
java.lang.Exception
-
download0
void download0(java.net.URI url, java.io.File path, byte[] sha) throws java.lang.Exception- Throws:
java.lang.Exception
-
event
private void event(ResourceRepository.TYPE type, SearchableRepository.ResourceDescriptor rds, java.lang.Exception exception)
Dispatch the events- Parameters:
type-rds-exception-
-
sleep
private boolean sleep(int i)
Sleep function that does not throwInterruptedException- Parameters:
i-
-
save
private void save() throws java.lang.ExceptionSave the index file.- Throws:
java.lang.Exception
-
getIndex
private ResourceRepositoryImpl.FileLayout getIndex() throws java.lang.Exception
Get the index, load it if necessary- Throws:
java.lang.Exception
-
setReporter
public void setReporter(Reporter processor)
-
setIndexFile
public void setIndexFile(java.io.File file)
-
setCache
public void setCache(java.io.File cache)
-
setExecutor
public void setExecutor(java.util.concurrent.Executor executor) throws java.lang.Exception- Throws:
java.lang.Exception
-
setURLConnector
public void setURLConnector(URLConnectionHandler connector) throws java.lang.Exception
- Throws:
java.lang.Exception
-
find
public java.util.SortedSet<SearchableRepository.ResourceDescriptor> find(java.lang.String repoId, java.lang.String bsn, VersionRange range) throws java.lang.Exception
- Specified by:
findin interfaceResourceRepository- Throws:
java.lang.Exception
-
getCacheDir
public java.io.File getCacheDir(java.lang.String name)
- Specified by:
getCacheDirin interfaceResourceRepository
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-