How can I write a custom container type with Apache Thrift?
I am aware that, by default, any map declaration in Thrift extends HashMap.
Is there a way that I can modify it to extend ConcurrentHashMap instead of HashMap?
For e.g., if Test.thrift is defined as follows:
struct TestData { 1: string id, 2: map details }
How can I make sure that this map is implemented as a ConcurrentHashMap?
Thanks!
There are tree predefined container types (list<R>
, set<T>
and map<K,V>
), which are tied to a suitable, language specific implementation.
While Thrift does enable you to freely construct struct
s in a lot of ways, there is no extension to the basic IDL data types and containers.
Some language bindings, like C++, allow customisation of container implementation (i.e. which classes are actually used in the generated code) by means of IDL annotations. However, this is supported only with a small subset of the languages and AFAIK Java is NOT one of them.
How can I make sure that this map is implemented as a ConcurrentHashMap?
You need to change the Thrift compiler or post-process the generated code artifacts somehow.