thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Craig <>
Subject Re: Client Context.
Date Thu, 12 Dec 2013 16:22:01 GMT
If you are using C++, there is a way to get per-client context on your 
Iface implementation.  Here's some C++11 style code to give you an idea of 
what to do.  (note: I did not attempt to compile this, so it probably has 
at least one really stupid bug in it).

class YourIfCloneFactory : public YourServiceNamespace::YourIfFactory {
  virtual ~YourIfCloneFactory() {}

  virtual YourServiceNamespace::YourIf* getHandler(const 
::apache::thrift::TConnectionInfo& connInfo)
    return new YourHandler;
  virtual void releaseHandler(YourServiceNamespace::YourIf* handler)
    delete handler;

using namespace apache::thrift;
using namespace YourServiceNamespace;
using boost::make_shared;

auto handlerFactory = make_shared<YourIfCloneFactory>();
auto server = make_shared<server::TThreadedServer>(

With this approach, you will have a new instance of your handler class for 
every client.  You have access to the connInfo object if you want to pass 
that information to your handler's ctor.

"Martin Waller" <> wrote on 12/12/2013 09:40:21 AM:

> From: "Martin Waller" <>
> To: <>, 
> Date: 12/12/2013 10:07 AM
> Subject: Client Context.
> Hi, 
> I'm very new to Thrift and the first issue that I have hit is inability 
> hold a context on the server for each client that has connected. The
> TServerEventHandler createContext looks as though it should do it for 
> but I see no way of accessing this in the code that implements the 
> Does anyone know of any ways to achieve this?
> Many thanks
> Martin

View raw message