Package org.apache.maven.index.reader
Class IndexReader
- java.lang.Object
-
- org.apache.maven.index.reader.IndexReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Iterable<ChunkReader>
public class IndexReader extends java.lang.Object implements java.lang.Iterable<ChunkReader>, java.io.Closeable
Maven 2 Index reader that handles incremental updates if possible and provides one or moreChunkReader
s, to read all the required records.- Since:
- 5.1.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
IndexReader.ChunkReaderIterator
Internal iterator implementation that lazily opens and closes the returnedChunkReader
s as this iterator is being consumed.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description IndexReader(WritableResourceHandler local, ResourceHandler remote)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 underlyingResourceHandler
s.java.util.List<java.lang.String>
getChunkNames()
Returns unmodifiable list of actual chunks that needs to be pulled from remoteResourceHandler
.java.lang.String
getIndexId()
Returns the index context ID that published index has set.java.util.Date
getPublishedTimestamp()
Returns theDate
when remote index was last published.boolean
isIncremental()
Returnstrue
if incremental update is about to happen.java.util.Iterator<ChunkReader>
iterator()
Returns anIterator
ofChunkReader
s, 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 localWritableResourceHandler
for future incremental updates.
-
-
-
Field Detail
-
local
private final WritableResourceHandler local
-
remote
private final ResourceHandler remote
-
localIndexProperties
private final java.util.Properties localIndexProperties
-
remoteIndexProperties
private final java.util.Properties remoteIndexProperties
-
indexId
private final java.lang.String indexId
-
publishedTimestamp
private final java.util.Date publishedTimestamp
-
incremental
private final boolean incremental
-
chunkNames
private final java.util.List<java.lang.String> chunkNames
-
-
Constructor Detail
-
IndexReader
public IndexReader(WritableResourceHandler local, ResourceHandler remote) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getIndexId
public java.lang.String getIndexId()
Returns the index context ID that published index has set. Usually it is equal to "repository ID" used inRecord.Type.DESCRIPTOR
but does not have to be.
-
getPublishedTimestamp
public java.util.Date getPublishedTimestamp()
Returns theDate
when remote index was last published.
-
isIncremental
public boolean isIncremental()
Returnstrue
if incremental update is about to happen. If incremental update, theiterator()
will return only the diff from the last update.
-
getChunkNames
public java.util.List<java.lang.String> getChunkNames()
Returns unmodifiable list of actual chunks that needs to be pulled from remoteResourceHandler
. Those are incremental chunks or the big main file, depending on result ofisIncremental()
. Empty list means local index is up to date, anditerator()
will return empty iterator.
-
close
public void close() throws java.io.IOException
Closes the underlyingResourceHandler
s. In case of incremental update use, it also assumes that user consumed all the iterator and integrated it, hence, it will update theWritableResourceHandler
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 theResourceHandler
s that caller provided in constructor of this class should be closed manually.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
iterator
public java.util.Iterator<ChunkReader> iterator()
Returns anIterator
ofChunkReader
s, 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 currentChunkReader
if aborting.- Specified by:
iterator
in interfacejava.lang.Iterable<ChunkReader>
-
syncLocalWithRemote
private void syncLocalWithRemote() throws java.io.IOException
Stores the remote index properties into local index properties, preparing localWritableResourceHandler
for future incremental updates.- Throws:
java.io.IOException
-
calculateChunkNames
private java.util.List<java.lang.String> calculateChunkNames()
Calculates the chunk names that needs to be fetched.
-
canRetrieveAllChunks
private boolean canRetrieveAllChunks()
Verifies incremental update is possible, as all the diff chunks we need are still enlisted in remote properties.
-
-