File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
topic/src/main/java/tech/ydb/topic Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ package tech .ydb .topic .description ;
2+
3+ import java .util .Map ;
4+ import java .util .concurrent .ConcurrentHashMap ;
5+
6+ /**
7+ * Register for custom topic codec. Local to TopicClient
8+ *
9+ * @author Evgeny Kuvardin
10+ **/
11+ public class CodecRegistryImpl implements CodecRegistry {
12+
13+ /**
14+ * Make customCodecMap concurrent since register/unregister/read can be from different threads
15+ */
16+ final Map <Integer , CustomTopicCodec > customCodecMap ;
17+
18+ public CodecRegistryImpl () {
19+ customCodecMap = new ConcurrentHashMap <>();
20+ }
21+
22+ @ Override
23+ public CustomTopicCodec registerCustomCodec (int codec , CustomTopicCodec customTopicCodec ) {
24+ assert customTopicCodec != null ;
25+
26+ if (Codec .getInstance ().isReserved (codec )) {
27+ throw new RuntimeException (
28+ "Create custom codec for reserved code not allowed: " + codec + " .Use code more than 10000" );
29+ }
30+
31+ return customCodecMap .put (codec , customTopicCodec );
32+ }
33+
34+ @ Override
35+ public CustomTopicCodec unregisterCustomCodec (int codec ) {
36+ if (Codec .getInstance ().isReserved (codec )) {
37+ throw new RuntimeException (
38+ "Create custom codec for reserved code not allowed: " + codec + " .Use code more than 10000" );
39+ }
40+
41+ return customCodecMap .remove (codec );
42+ }
43+
44+ @ Override
45+ public CustomTopicCodec getCustomCodec (int codec ) {
46+ return customCodecMap .get (codec );
47+ }
48+ }
Original file line number Diff line number Diff line change 2424import tech .ydb .topic .TopicClient ;
2525import tech .ydb .topic .TopicRpc ;
2626import tech .ydb .topic .description .CodecRegistry ;
27+ import tech .ydb .topic .description .CodecRegistryImpl ;
2728import tech .ydb .topic .description .Consumer ;
2829import tech .ydb .topic .description .ConsumerDescription ;
2930import tech .ydb .topic .description .CustomTopicCodec ;
You can’t perform that action at this time.
0 commit comments