19
19
/**
20
20
* Manages versioning and checksum for a stream of content.
21
21
* @param <T> Type of content to be read/written
22
+ *
23
+ * @opensearch.internal
22
24
*/
23
25
public 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 ;
26
28
private final int currentVersion ;
27
29
private final String codec ;
28
30
29
31
/**
30
- * @param parser parser to read/write stream from T
32
+ * @param streamReadWriteHandler handler to read/write stream from T
31
33
* @param currentVersion latest supported version of the stream
32
34
* @param codec: stream codec
33
35
*/
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 ;
36
38
this .currentVersion = currentVersion ;
37
39
this .codec = codec ;
38
40
}
@@ -47,7 +49,7 @@ public VersionedCodecStreamWrapper(StreamReadWriteHandler<T> parser, int current
47
49
public T readStream (IndexInput indexInput ) throws IOException {
48
50
ChecksumIndexInput checksumIndexInput = new BufferedChecksumIndexInput (indexInput );
49
51
int readStreamVersion = checkHeader (checksumIndexInput );
50
- T content = getParserForVersion (readStreamVersion ).readContent (checksumIndexInput );
52
+ T content = getHandlerForVersion (readStreamVersion ).readContent (checksumIndexInput );
51
53
checkFooter (checksumIndexInput );
52
54
return content ;
53
55
}
@@ -59,7 +61,7 @@ public T readStream(IndexInput indexInput) throws IOException {
59
61
*/
60
62
public void writeStream (IndexOutput indexOutput , T content ) throws IOException {
61
63
this .writeHeader (indexOutput );
62
- getParserForVersion (this .currentVersion ).writeContent (indexOutput , content );
64
+ getHandlerForVersion (this .currentVersion ).writeContent (indexOutput , content );
63
65
this .writeFooter (indexOutput );
64
66
}
65
67
@@ -69,6 +71,7 @@ public void writeStream(IndexOutput indexOutput, T content) throws IOException {
69
71
* @return header version found in the input stream
70
72
*/
71
73
private int checkHeader (IndexInput indexInput ) throws IOException {
74
+ // TODO Once versioning strategy is decided we'll add support for min/max supported versions
72
75
return CodecUtil .checkHeader (indexInput , this .codec , this .currentVersion , this .currentVersion );
73
76
}
74
77
@@ -98,11 +101,12 @@ private void writeFooter(IndexOutput indexOutput) throws IOException {
98
101
}
99
102
100
103
/**
101
- * Returns relevant parser for the version
104
+ * Returns relevant handler for the version
102
105
* @param version stream content version
103
106
*/
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 ;
107
111
}
108
112
}
0 commit comments