Class IndexReader

All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<ChunkReader>

public class IndexReader extends Object implements Iterable<ChunkReader>, Closeable
Maven Index reader that handles incremental updates, if possible, and provides one or more ChunkReaders, to read all the required records. Instances of this class MUST BE handled as resources (have them closed once done with them), it is user responsibility to close them, ideally in try-with-resource block.

Every involved instance, this IndexReader, provided ChunkReader, and used ResourceHandlers are Closeable, and all have to be explicitly closed, best in try-with-resource.

  • Constructor Details

  • Method Details

    • getIndexId

      public String getIndexId()
      Returns the index context ID that published index has set. Usually it is equal to "repository ID" used in Record.Type.DESCRIPTOR but does not have to be.
    • getPublishedTimestamp

      public Date getPublishedTimestamp()
      Returns the Date when remote index was last published.
    • isIncremental

      public boolean isIncremental()
      Returns true if incremental update is about to happen. If incremental update, the iterator() will return only the diff from the last update.
    • getChunkNames

      public List<String> getChunkNames()
      Returns unmodifiable list of actual chunks that needs to be pulled from remote 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.
    • close

      public void close() throws IOException
      Closes the underlying 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.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • iterator

      public Iterator<ChunkReader> iterator()
      Returns an 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.
      Specified by:
      iterator in interface Iterable<ChunkReader>