Class IndexWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class IndexWriter
    extends java.lang.Object
    implements java.io.Closeable
    Maven 2 Index writer that writes chunk and maintains published property file.

    Currently no incremental update is supported, as the deleteion states should be maintained by caller. Hence, this writer will always produce the "main" chunk only.

    Since:
    5.1.2
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String calculateNextChunkCounter()
      Calculates the chunk names that needs to be fetched.
      void close()
      Closes the underlying ResourceHandler and synchronizes published index properties, so remote clients becomes able to consume newly published index.
      java.lang.String getChainId()
      Returns the chain id of published index.
      java.lang.String getIndexId()
      Returns the index context ID that published index has set.
      java.lang.String getNextChunkName()
      Returns the next chunk name about to be published.
      java.util.Date getPublishedTimestamp()
      Returns the Date when index was last published or null if this is first publishing.
      boolean isIncremental()
      Returns true if incremental publish is about to happen.
      int writeChunk​(java.util.Iterator<java.util.Map<java.lang.String,​java.lang.String>> iterator)
      Writes out the record iterator and returns the written record count.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • localIndexProperties

        private final java.util.Properties localIndexProperties
      • incremental

        private final boolean incremental
      • nextChunkCounter

        private final java.lang.String nextChunkCounter
      • nextChunkName

        private final java.lang.String nextChunkName
    • Constructor Detail

      • IndexWriter

        public IndexWriter​(WritableResourceHandler local,
                           java.lang.String indexId,
                           boolean incrementalSupported)
                    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.
      • getPublishedTimestamp

        public java.util.Date getPublishedTimestamp()
        Returns the Date when index was last published or null if this is first publishing. In other words,returns null when isIncremental() returns false. After this writer is closed, the return value is updated to "now" (in method.
      • isIncremental

        public boolean isIncremental()
        Returns true if incremental publish is about to happen.
      • getChainId

        public java.lang.String getChainId()
        Returns the chain id of published index. If isIncremental() is false, this is the newly generated chain ID.
      • getNextChunkName

        public java.lang.String getNextChunkName()
        Returns the next chunk name about to be published.
      • writeChunk

        public int writeChunk​(java.util.Iterator<java.util.Map<java.lang.String,​java.lang.String>> iterator)
                       throws java.io.IOException
        Writes out the record iterator and returns the written record count.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Closes the underlying ResourceHandler and synchronizes published index properties, so remote clients becomes able to consume newly published index. If sync is not desired (ie. due to aborted publish), then this method should NOT be invoked, but rather the ResourceHandler that caller provided in constructor of this class should be closed manually.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • calculateNextChunkCounter

        private java.lang.String calculateNextChunkCounter()
        Calculates the chunk names that needs to be fetched.