TAsyncClientBase

Asynchronous Thrift service client which returns the results as TFutures an uses a TAsyncManager to perform the actual work.

TAsyncClientBase serves as a supertype for all TAsyncClients for the same service, which might be instantiated with different concrete protocol types (there is no covariance for template type parameters), and extends TFutureInterface!Interface. If Interface is derived from another service BaseInterface, it also extends TAsyncClientBase!BaseInterface.

TAsyncClient implements TAsyncClientBase and offers two constructors with the following signatures:

this(TAsyncTransport trans, TTransportFactory tf, TProtocolFactory pf);
this(TAsyncTransport trans, TTransportFactory itf, TTransportFactory otf,
  TProtocolFactory ipf, TProtocolFactory opf);

Again, if Interface represents a derived Thrift service, TAsyncClient!Interface is also derived from TAsyncClient!BaseInterface.

TAsyncClient can exclusively be used with TAsyncTransports, as it needs to access the associated TAsyncManager. To set up any wrapper transports (e.g. buffered, framed) on top of it and to instanciate the protocols to use, TTransportFactory and TProtocolFactory instances are passed to the constructors – the three argument constructor is a shortcut if the same transport and protocol are to be used for both input and output, which is the most common case.

If the same transport factory is passed for both input and output transports, only a single wrapper transport will be created and used for both directions. This allows easy implementation of protocols like SSL.

Just as TClient does, TAsyncClient also takes two optional template arguments which can be used for specifying the actual TProtocol implementation used for optimization purposes, as virtual calls can completely be eliminated then. If the actual types of the protocols instantiated by the factories used does not match the ones statically specified in the template parameters, a TException is thrown during construction.

  1. interface TAsyncClientBase(Interface)
    interface TAsyncClientBase : TFutureInterface!Interface(
    Interface
    ) if (
    isBaseService!Interface
    ) {}
  2. interface TAsyncClientBase(Interface)
  3. template TAsyncClient(Interface, InputProtocol = TProtocol, OutputProtocol = void)

Members

Functions

transport
TAsyncTransport transport()

The underlying TAsyncTransport used by this client instance.

Examples

// A simple Thrift service.
interface Foo { int foo(); }

// Create a TAsyncSocketManager – thrift.async.libevent is used for this
// example.
auto manager = new TLibeventAsyncManager;

// Set up an async transport to use.
auto socket = new TAsyncSocket(manager, host, port);

// Create a client instance.
auto client = new TAsyncClient!Foo(
  socket,
  new TBufferedTransportFactory, // Wrap the socket in a TBufferedTransport.
  new TBinaryProtocolFactory!() // Use the Binary protocol.
);

// Call foo and use the returned future.
auto result = client.foo();
pragma(msg, typeof(result)); // TFuture!int
int resultValue = result.waitGet(); // Waits until the result is available.

Meta