public interface DescriptorReader
This descriptor source is likely the most widely used one, possibly
in combination with DescriptorCollector
to synchronize
descriptors from the CollecTor service.
Reading descriptors is done in a batch which starts after setting any configuration options and initiating the read process.
Code sample:
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
// Read descriptors from local directory called in/.
descriptorReader.addDirectory(new File("in"));
Iterator<DescriptorFile> descriptorFiles =
descriptorReader.readDescriptors();
while (descriptorFiles.hasNext()) {
DescriptorFile descriptorFile = descriptorFiles.next();
for (Descriptor descriptor : descriptorFile.getDescriptors()) {
if ((descriptor instanceof RelayNetworkStatusConsensus)) {
// Only process network status consensuses, ignore the rest.
RelayNetworkStatusConsensus consensus =
(RelayNetworkStatusConsensus) descriptor;
processConsensus(consensus);
}
}
}
Modifier and Type | Method and Description |
---|---|
void |
addDirectory(java.io.File directory)
Add a local directory to read descriptors from, which may contain
descriptor files or tarballs containing descriptor files.
|
void |
addTarball(java.io.File tarball)
Add a tarball to read descriptors from, which may be uncompressed,
bz2-compressed, or xz-compressed.
|
java.util.SortedMap<java.lang.String,java.lang.Long> |
getExcludedFiles()
Return files and last modified timestamps of files that exist in the
input directory or directories, but that have been excluded from
parsing, because they haven't changed since they were last read.
|
java.util.SortedMap<java.lang.String,java.lang.Long> |
getParsedFiles()
Return files and last modified timestamps of files that exist in the
input directory or directories and that have been parsed.
|
java.util.Iterator<DescriptorFile> |
readDescriptors()
Read the previously configured descriptors and make them available
via the returned blocking iterator.
|
void |
setExcludedFiles(java.util.SortedMap<java.lang.String,java.lang.Long> excludedFiles)
Exclude files if they haven't changed since the corresponding last
modified timestamps.
|
void |
setExcludeFiles(java.io.File historyFile)
Exclude files that are listed in the given history file and that
haven't changed since they have last been read.
|
void |
setFailUnrecognizedDescriptorLines()
Fail descriptor parsing when encountering an unrecognized line.
|
void |
setMaxDescriptorFilesInQueue(int max)
Don't keep more than this number of parsed descriptor files in the
queue.
|
void addDirectory(java.io.File directory)
void addTarball(java.io.File tarball)
void setExcludeFiles(java.io.File historyFile)
Add a new line for each descriptor that is read in this execution and remove lines for files that don't exist anymore.
Lines in the history file contain the last modified time in milliseconds since the epoch and the absolute path of a file.
void setExcludedFiles(java.util.SortedMap<java.lang.String,java.lang.Long> excludedFiles)
Can be used instead of (or in addition to) a history file.
java.util.SortedMap<java.lang.String,java.lang.Long> getExcludedFiles()
Can be used instead of (or in addition to) a history file when combined with the set of parsed files.
java.util.SortedMap<java.lang.String,java.lang.Long> getParsedFiles()
Can be used instead of (or in addition to) a history file when combined with the set of excluded files.
void setFailUnrecognizedDescriptorLines()
This option is not set by default, because the Tor specifications allow for new lines to be added that shall be ignored by older Tor versions. But some applications may want to handle unrecognized descriptor lines explicitly.
void setMaxDescriptorFilesInQueue(int max)
The default is 100, but if descriptor files contain hundreds or even thousands of descriptors, that default may be too high.
java.util.Iterator<DescriptorFile> readDescriptors()
Whenever the reader runs out of descriptors and expects to provide more shortly after, it blocks the caller. This method can only be run once.