Search code examples
code-generationrpcthrift

How do I get Apache Thrift to generate c++ code for a multithreaded server?


I am very new to thrift. Still playing with toy examples with servers and clients working fine except my server generated code is always TSimpleServer, never TThreadedServer.

Even when I run this on the tutorial sample I don't get TThreadedServer server

thrift -r --gen cpp tutorial.thrift

Solution

  • The simple and direct answer is: No way.

    The somewhat longer answer is, that there is a reason why the file is named *.skeleton.*. These skeleton files are only intended as a base to get you started. They are by no means intended to be a complete solution, let alone the silver bullet for all needs.

    But since one of the ideas behind Apache Thrift is modularity, you simply plug in another server type as you need it by changing one line of code:

    TThreadedServer server(processor, serverTransport, transportFactory, protocolFactory);
    

    There is simply no need to implement that in the generator, since

    • there would be too many permutations with all server types, transports, layered transports and protocols supported
    • it is so easy to switch between all those various components by just changing a few lines of code

    C++ is AFAIK the only language that generates skeleton files at all. To my knowledge, no other language has this feature implemented. If you want to study another example with more features involved, look at the Thrift tests implementation under /test/cpp. A lot of things will become much clearer after looking at that code.