Thrift - a different instance of Handler for each Socket

I am developing a proxy server in Thrift. My problem is that every connection going into the proxy uses the same instance of the handler. The client implementation of the proxy server is in the handler, so all clients associate the same connection with the destination server.

I have: n clients β†’ n sockets β†’ 1 handler β†’ 1 socket β†’ 1 server What I want to implement: n clients β†’ n sockets β†’ n handlers β†’ n sockets β†’ 1 server

Now the problem is that if the client changes the local parameter on the server (something specific for each client independently), other clients will also work with the changed environment.

shared_ptr<CassProxyHandler> handler(new CassProxyHandler(adr_s,port_s,keyspace));
shared_ptr<TProcessor> processor(new CassandraProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TFramedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TThreadedServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();

Is there a way to implement a server that creates a new handler instance for each server socket instead of using the same handler?

Thanks for any suggestions or help, @

+5
source share
3 answers

I managed to solve this problem. Java has already implemented the solution. I used the same idea and implemented it in C ++.

First of all, I created TProcessorFactory instead of the TTransport class. It processes TProcessors for each connection. It has a map structure, so its get function returns the corresponding TProcessor for each TTransport. Corresponding (unique) TProcessor for each client.

TServer, TProcessorFactory TProcessor. TServer . getProcessor TProcessor, TProcessorFactory ( ).

, , , , TServer. TNonblockingServer ( ) TThreadPoolServer. . get TProcessorFactory TTransport, TProcessor, . TTransport , .

, TProcessors, ( , TNonblockingServer) TTransport, , , , , , , , . , , , , .

, , , . , : http://diwakergupta.github.com/thrift-missing-guide/

, Thrift , .

@

+4

, , , - - # Thrift ...

https://issues.apache.org/jira/browse/THRIFT-3397

TProcessor , -

new ThreadPoolServer(processorFactory,serverTransport,
                                    transportFactory,protocolFactory);

"processorFactory" - TProcessorFactory.

TPrototypeProcessorFactory < TProcessor, Handler > (object [] handlerArgs), :

TProcessorFactory processorFactory = 
      new TPrototypeProcessorFactory<ThriftGenerated.Processor, MyHandlerClass>(); 

"MyHandlerClass" ThriftGenerated.Iface. , , factory. Internally - factory :

  • "MyHandlerClass" , ( Activator.CreateInstance)

  • "MyHandlerClass" "TControllingHandler", 'server' TServer (, TServer thift)

  • ThriftGenerated.Processor()

# n β†’ n β†’ n β†’ n β†’ 1

, - , , .

+1

, -, - TCP, TCP- .

0

All Articles