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 {
public:
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>(
make_shared<YourServiceProcessorFactory>(handlerFactory),
make_shared<transport::TServerSocket>(port),
make_shared<transport::TBufferedTransportFactory>(),
make_shared<protocol::TBinaryProtocolFactory>());
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" <[email protected]> wrote on 12/12/2013 09:40:21 AM:
> From: "Martin Waller" <[email protected]>
> To: <[email protected]>,
> 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
to
> hold a context on the server for each client that has connected. The
> TServerEventHandler createContext looks as though it should do it for
you
> but I see no way of accessing this in the code that implements the
Iface.
>
>
>
> Does anyone know of any ways to achieve this?
>
>
>
> Many thanks
>
>
>
> Martin
>