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 class
ResourceRepositoryImpl.FileLayout
Class 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.File
cache
(package private) static JSONCodec
codec
private URLConnectionHandler
connector
private boolean
dirty
protected static RepositoryPlugin.DownloadListener[]
EMPTY_LISTENER
private java.util.concurrent.Executor
executor
private java.util.Map<java.net.URI,java.lang.Long>
failures
private java.io.File
hosting
private ResourceRepositoryImpl.FileLayout
index
private java.io.File
indexFile
(package private) java.util.concurrent.Semaphore
limitDownloads
private java.util.List<ResourceRepository.Listener>
listeners
private static org.slf4j.Logger
logger
(package private) MultiMap<java.io.File,RepositoryPlugin.DownloadListener>
queues
private Reporter
reporter
private static java.util.Comparator<SearchableRepository.ResourceDescriptor>
RESOURCE_DESCRIPTOR_COMPARATOR
private static long
THRESHOLD
-
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 boolean
add(java.lang.String repoId, SearchableRepository.ResourceDescriptor rd)
Add a resource descriptor to the index.void
addListener(ResourceRepository.Listener rrl)
Add a new event listener(package private) void
delete(byte[] id)
Delete a resource from the text file (not from the cache)boolean
delete(java.lang.String repoId, byte[] id)
boolean
deleteCache(byte[] id)
Delete a cache entry(package private) void
download(SearchableRepository.ResourceDescriptor rds, java.io.File path)
(package private) void
download0(java.net.URI url, java.io.File path, byte[] sha)
private void
event(ResourceRepository.TYPE type, SearchableRepository.ResourceDescriptor rds, java.lang.Exception exception)
Dispatch the events(package private) void
fail(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.File
getCacheDir(java.lang.String name)
private ResourceRepositoryImpl.FileLayout
getIndex()
Get the index, load it if necessaryjava.io.File
getResource(byte[] rd, RepositoryPlugin.DownloadListener... blockers)
Get the file belonging to a Resource DescriptorResourceDescriptorImpl
getResourceDescriptor(byte[] rd)
List the resources.(package private) void
ok(RepositoryPlugin.DownloadListener[] blockers, java.io.File file)
Just report success to all download listenersvoid
removeListener(ResourceRepository.Listener rrl)
Remove an event listenerprivate void
save()
Save the index file.void
setCache(java.io.File cache)
private void
setDirty()
Set dirty for save.void
setExecutor(java.util.concurrent.Executor executor)
void
setIndexFile(java.io.File file)
void
setReporter(Reporter processor)
void
setURLConnector(URLConnectionHandler connector)
private boolean
sleep(int i)
Sleep function that does not throwInterruptedException
java.lang.String
toString()
-
-
-
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:
filter
in interfaceResourceRepository
filter
- 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.Exception
Delete 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:
delete
in interfaceResourceRepository
- Throws:
java.lang.Exception
-
deleteCache
public boolean deleteCache(byte[] id) throws java.lang.Exception
Delete a cache entry- Specified by:
deleteCache
in interfaceResourceRepository
- Throws:
java.lang.Exception
-
add
public boolean add(java.lang.String repoId, SearchableRepository.ResourceDescriptor rd) throws java.lang.Exception
Add a resource descriptor to the index.- Specified by:
add
in interfaceResourceRepository
- Throws:
java.lang.Exception
-
getResource
public java.io.File getResource(byte[] rd, RepositoryPlugin.DownloadListener... blockers) throws java.lang.Exception
Get the file belonging to a Resource Descriptor- Specified by:
getResource
in interfaceResourceRepository
- Throws:
java.lang.Exception
-
addListener
public void addListener(ResourceRepository.Listener rrl)
Add a new event listener- Specified by:
addListener
in 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:
getResourceDescriptor
in 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.Exception
Save 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:
find
in interfaceResourceRepository
- Throws:
java.lang.Exception
-
getCacheDir
public java.io.File getCacheDir(java.lang.String name)
- Specified by:
getCacheDir
in interfaceResourceRepository
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-