Package org.apache.maven.index.reader
Class IndexWriter
- java.lang.Object
-
- org.apache.maven.index.reader.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
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
incremental
private static int
INDEX_V1
private WritableResourceHandler
local
private java.util.Properties
localIndexProperties
private java.lang.String
nextChunkCounter
private java.lang.String
nextChunkName
-
Constructor Summary
Constructors Constructor Description IndexWriter(WritableResourceHandler local, java.lang.String indexId, boolean incrementalSupported)
-
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 underlyingResourceHandler
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 theDate
when index was last published ornull
if this is first publishing.boolean
isIncremental()
Returnstrue
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.
-
-
-
Field Detail
-
INDEX_V1
private static final int INDEX_V1
- See Also:
- Constant Field Values
-
local
private final WritableResourceHandler local
-
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 theDate
when index was last published ornull
if this is first publishing. In other words,returnsnull
whenisIncremental()
returnsfalse
. After this writer is closed, the return value is updated to "now" (inmethod
.
-
isIncremental
public boolean isIncremental()
Returnstrue
if incremental publish is about to happen.
-
getChainId
public java.lang.String getChainId()
Returns the chain id of published index. IfisIncremental()
isfalse
, 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 underlyingResourceHandler
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 theResourceHandler
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
-
calculateNextChunkCounter
private java.lang.String calculateNextChunkCounter()
Calculates the chunk names that needs to be fetched.
-
-