public class ResourceRepositoryImpl extends java.lang.Object implements ResourceRepository
| Modifier and Type | Class and Description |
|---|---|
static class |
ResourceRepositoryImpl.FileLayout
Class maintains the info stored in the text file in the cnf directory
that holds our contents.
|
ResourceRepository.Listener, ResourceRepository.ResourceRepositoryEvent, ResourceRepository.TYPE| Modifier and Type | Field and 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 |
(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 |
FILENAME| Constructor and Description |
|---|
ResourceRepositoryImpl() |
| Modifier and Type | Method and 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 necessary
|
java.io.File |
getResource(byte[] rd,
RepositoryPlugin.DownloadListener... blockers)
Get the file belonging to a Resource Descriptor
|
ResourceDescriptorImpl |
getResourceDescriptor(byte[] rd)
List the resources.
|
(package private) void |
ok(RepositoryPlugin.DownloadListener[] blockers,
java.io.File file)
Just report success to all download listeners
|
void |
removeListener(ResourceRepository.Listener rrl)
Remove an event listener
|
private 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 throw
InterruptedException |
java.lang.String |
toString() |
private static java.util.Comparator<SearchableRepository.ResourceDescriptor> RESOURCE_DESCRIPTOR_COMPARATOR
private static final long THRESHOLD
protected static final RepositoryPlugin.DownloadListener[] EMPTY_LISTENER
static JSONCodec codec
private final java.util.List<ResourceRepository.Listener> listeners
private boolean dirty
private ResourceRepositoryImpl.FileLayout index
private java.util.Map<java.net.URI,java.lang.Long> failures
private java.io.File cache
private java.io.File hosting
private Reporter reporter
private java.util.concurrent.Executor executor
private java.io.File indexFile
private URLConnectionHandler connector
final MultiMap<java.io.File,RepositoryPlugin.DownloadListener> queues
final java.util.concurrent.Semaphore limitDownloads
public java.util.List<ResourceDescriptorImpl> filter(java.lang.String repoId, java.lang.String filter) throws java.lang.Exception
filter in interface ResourceRepositoryfilter - An OSGi filter matched against the
SearchableRepository.ResourceDescriptorjava.lang.Exceptionvoid delete(byte[] id)
throws java.lang.Exception
java.lang.Exceptionpublic boolean delete(java.lang.String repoId,
byte[] id)
throws java.lang.Exception
delete in interface ResourceRepositoryjava.lang.Exceptionpublic boolean deleteCache(byte[] id)
throws java.lang.Exception
deleteCache in interface ResourceRepositoryjava.lang.Exceptionpublic boolean add(java.lang.String repoId,
SearchableRepository.ResourceDescriptor rd)
throws java.lang.Exception
add in interface ResourceRepositoryjava.lang.Exceptionpublic java.io.File getResource(byte[] rd,
RepositoryPlugin.DownloadListener... blockers)
throws java.lang.Exception
getResource in interface ResourceRepositoryjava.lang.Exceptionpublic void addListener(ResourceRepository.Listener rrl)
addListener in interface ResourceRepositorypublic void removeListener(ResourceRepository.Listener rrl)
private void setDirty()
public ResourceDescriptorImpl getResourceDescriptor(byte[] rd) throws java.lang.Exception
getResourceDescriptor in interface ResourceRepositoryjava.lang.Exceptionvoid ok(RepositoryPlugin.DownloadListener[] blockers, java.io.File file)
blockers - file - void fail(java.lang.Exception e,
RepositoryPlugin.DownloadListener[] blockers,
java.io.File file)
void download(SearchableRepository.ResourceDescriptor rds, java.io.File path) throws java.lang.Exception
java.lang.Exceptionvoid download0(java.net.URI url,
java.io.File path,
byte[] sha)
throws java.lang.Exception
java.lang.Exceptionprivate void event(ResourceRepository.TYPE type, SearchableRepository.ResourceDescriptor rds, java.lang.Exception exception)
type - rds - exception - private boolean sleep(int i)
InterruptedExceptioni - private void save()
throws java.lang.Exception
java.lang.Exceptionprivate ResourceRepositoryImpl.FileLayout getIndex() throws java.lang.Exception
java.lang.Exceptionpublic void setReporter(Reporter processor)
public void setIndexFile(java.io.File file)
public void setCache(java.io.File cache)
public void setExecutor(java.util.concurrent.Executor executor)
throws java.lang.Exception
java.lang.Exceptionpublic void setURLConnector(URLConnectionHandler connector) throws java.lang.Exception
java.lang.Exceptionpublic java.util.SortedSet<SearchableRepository.ResourceDescriptor> find(java.lang.String repoId, java.lang.String bsn, VersionRange range) throws java.lang.Exception
find in interface ResourceRepositoryjava.lang.Exceptionpublic java.io.File getCacheDir(java.lang.String name)
getCacheDir in interface ResourceRepositorypublic java.lang.String toString()
toString in class java.lang.Object