AW: how to have two protocols on same TServerSocket?

2012-03-23 Thread Roger Meier
Hi

Java implementation provides guessProtocolFactory == server can support
json and binary

-roger

 -Ursprüngliche Nachricht-
 Von: sergiu F [mailto:fs...@yahoo.com]
 Gesendet: Freitag, 23. März 2012 14:57
 An: user@thrift.apache.org
 Betreff: how to have two protocols on same TServerSocket?
 
 
 Hi,
 
 It is possible to have two kind of protocols mapped on same port? For
 example this code accept clients having json and binary. Code works fine
only
 if requests from clients come in same order: json,binary,json,binary
 
 thanks
 serj
 
             TServerSocket serverTransport = new TServerSocket(7912);
             TJSONProtocol.Factory f = new TJSONProtocol.Factory();
 
             TimeServer.Processor processor = new TimeServer.Processor(new
 TimeServerImpl());
             final TServer jsonServer = new TThreadPoolServer(new
 TThreadPoolServer.Args(serverTransport).
                     processor(processor).protocolFactory(f));
 
             final TServer binaryServer = new TThreadPoolServer(new
 TThreadPoolServer.Args(serverTransport).processor(processor));
 
             new Thread(new Runnable(){
                 @Override
                 public void run() {
                     System.out.println(Starting serverJSON on port 7912
...);
                     jsonServer.serve();
                 }
 
             }).start();
 
             new Thread(new Runnable(){
                 @Override
                 public void run() {
                     System.out.println(Starting serverBINARY on port 7912
...);
                     binaryServer.serve();
                 }
 
             }).start();



Re: AW: how to have two protocols on same TServerSocket?

2012-03-23 Thread sergiu F


Thank you for your answer.

How can I use guessProtocolFactory? From what I see in thrift source code, the 
only way to accept any protocol is to create my own class that extends 
org.apache.thrift.protocol.TProtocol. I think detecting protocol can be done in 
readMessageBegin() method.

Is there any other way to use guessProtocolFactory?

Best regards
serj