public class IndexReader extends java.lang.Object implements java.lang.Iterable<ChunkReader>, java.io.Closeable
ChunkReaders, to
read all the required records.| Modifier and Type | Class and Description |
|---|---|
private static class |
IndexReader.ChunkReaderIterator
Internal iterator implementation that lazily opens and closes the returned
ChunkReaders as this iterator
is being consumed. |
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<java.lang.String> |
chunkNames |
private boolean |
incremental |
private java.lang.String |
indexId |
private WritableResourceHandler |
local |
private java.util.Properties |
localIndexProperties |
private java.util.Date |
publishedTimestamp |
private ResourceHandler |
remote |
private java.util.Properties |
remoteIndexProperties |
| Constructor and Description |
|---|
IndexReader(WritableResourceHandler local,
ResourceHandler remote) |
| Modifier and Type | Method and Description |
|---|---|
private java.util.List<java.lang.String> |
calculateChunkNames()
Calculates the chunk names that needs to be fetched.
|
private boolean |
canRetrieveAllChunks()
Verifies incremental update is possible, as all the diff chunks we need are still enlisted in remote properties.
|
void |
close()
Closes the underlying
ResourceHandlers. |
java.util.List<java.lang.String> |
getChunkNames()
Returns unmodifiable list of actual chunks that needs to be pulled from remote
ResourceHandler. |
java.lang.String |
getIndexId()
Returns the index context ID that published index has set.
|
java.util.Date |
getPublishedTimestamp()
Returns the
Date when remote index was last published. |
boolean |
isIncremental()
Returns
true if incremental update is about to happen. |
java.util.Iterator<ChunkReader> |
iterator()
Returns an
Iterator of ChunkReaders, that if read in sequence, provide all the (incremental)
updates from the index. |
private void |
syncLocalWithRemote()
Stores the remote index properties into local index properties, preparing local
WritableResourceHandler
for future incremental updates. |
private final WritableResourceHandler local
private final ResourceHandler remote
private final java.util.Properties localIndexProperties
private final java.util.Properties remoteIndexProperties
private final java.lang.String indexId
private final java.util.Date publishedTimestamp
private final boolean incremental
private final java.util.List<java.lang.String> chunkNames
public IndexReader(WritableResourceHandler local, ResourceHandler remote) throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getIndexId()
Record.Type.DESCRIPTOR but does not have to be.public java.util.Date getPublishedTimestamp()
Date when remote index was last published.public boolean isIncremental()
true if incremental update is about to happen. If incremental update, the iterator() will
return only the diff from the last update.public java.util.List<java.lang.String> getChunkNames()
ResourceHandler. Those are
incremental chunks or the big main file, depending on result of isIncremental(). Empty list means local
index is up to date, and iterator() will return empty iterator.public void close()
throws java.io.IOException
ResourceHandlers. In case of incremental update use, it also assumes that user
consumed all the iterator and integrated it, hence, it will update the WritableResourceHandler contents to
prepare it for future incremental update. If this is not desired (ie. due to aborted update), then this method
should NOT be invoked, but rather the ResourceHandlers that caller provided in constructor of
this class should be closed manually.close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic java.util.Iterator<ChunkReader> iterator()
Iterator of ChunkReaders, that if read in sequence, provide all the (incremental)
updates from the index. It is caller responsibility to either consume fully this iterator, or to close current
ChunkReader if aborting.iterator in interface java.lang.Iterable<ChunkReader>private void syncLocalWithRemote()
throws java.io.IOException
WritableResourceHandler
for future incremental updates.java.io.IOExceptionprivate java.util.List<java.lang.String> calculateChunkNames()
private boolean canRetrieveAllChunks()