1919/**
2020 * Manages versioning and checksum for a stream of content.
2121 * @param <T> Type of content to be read/written
22+ *
23+ * @opensearch.internal
2224 */
2325public class VersionedCodecStreamWrapper <T > {
24- // This can be updated to hold a parserFactory and get relevant parsers based on the stream versions
25- private final StreamReadWriteHandler <T > parser ;
26+ // TODO This can be updated to hold a streamReadWriteHandlerFactory and get relevant handler based on the stream versions
27+ private final StreamReadWriteHandler <T > streamReadWriteHandler ;
2628 private final int currentVersion ;
2729 private final String codec ;
2830
2931 /**
30- * @param parser parser to read/write stream from T
32+ * @param streamReadWriteHandler handler to read/write stream from T
3133 * @param currentVersion latest supported version of the stream
3234 * @param codec: stream codec
3335 */
34- public VersionedCodecStreamWrapper (StreamReadWriteHandler <T > parser , int currentVersion , String codec ) {
35- this .parser = parser ;
36+ public VersionedCodecStreamWrapper (StreamReadWriteHandler <T > streamReadWriteHandler , int currentVersion , String codec ) {
37+ this .streamReadWriteHandler = streamReadWriteHandler ;
3638 this .currentVersion = currentVersion ;
3739 this .codec = codec ;
3840 }
@@ -47,7 +49,7 @@ public VersionedCodecStreamWrapper(StreamReadWriteHandler<T> parser, int current
4749 public T readStream (IndexInput indexInput ) throws IOException {
4850 ChecksumIndexInput checksumIndexInput = new BufferedChecksumIndexInput (indexInput );
4951 int readStreamVersion = checkHeader (checksumIndexInput );
50- T content = getParserForVersion (readStreamVersion ).readContent (checksumIndexInput );
52+ T content = getHandlerForVersion (readStreamVersion ).readContent (checksumIndexInput );
5153 checkFooter (checksumIndexInput );
5254 return content ;
5355 }
@@ -59,7 +61,7 @@ public T readStream(IndexInput indexInput) throws IOException {
5961 */
6062 public void writeStream (IndexOutput indexOutput , T content ) throws IOException {
6163 this .writeHeader (indexOutput );
62- getParserForVersion (this .currentVersion ).writeContent (indexOutput , content );
64+ getHandlerForVersion (this .currentVersion ).writeContent (indexOutput , content );
6365 this .writeFooter (indexOutput );
6466 }
6567
@@ -69,6 +71,7 @@ public void writeStream(IndexOutput indexOutput, T content) throws IOException {
6971 * @return header version found in the input stream
7072 */
7173 private int checkHeader (IndexInput indexInput ) throws IOException {
74+ // TODO Once versioning strategy is decided we'll add support for min/max supported versions
7275 return CodecUtil .checkHeader (indexInput , this .codec , this .currentVersion , this .currentVersion );
7376 }
7477
@@ -98,11 +101,12 @@ private void writeFooter(IndexOutput indexOutput) throws IOException {
98101 }
99102
100103 /**
101- * Returns relevant parser for the version
104+ * Returns relevant handler for the version
102105 * @param version stream content version
103106 */
104- private StreamReadWriteHandler <T > getParserForVersion (int version ) {
105- // TODO implement parser factory and pick relevant parser based on version
106- return this .parser ;
107+ private StreamReadWriteHandler <T > getHandlerForVersion (int version ) {
108+ // TODO implement factory and pick relevant handler based on version.
109+ // It should also take into account min and max supported versions
110+ return this .streamReadWriteHandler ;
107111 }
108112}
0 commit comments