Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright (c) 2014, Facebook, Inc. All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. #
"""Base Class for easy interfacing with thrift services.
`ThriftClient` can be used directly, or subclassed. If subclassed, you can override a variety of attributes in order to make instantiation more natural:
MODULE - The generated thrift module. Should include Iface and Client HOST - A default host to connect to. Possibly a vip. PORT - A default port to connect to. PATH - An http path to request. Enables HTTP client mode. TRANSPORT_CLASS - By default, `TFramedTransport` for socket servers, `TBufferedTransport` for HTTP servers. PROTOCOL_CLASS - By default, `TBinaryProtocol` CONNECT_TIMEOUT - By default, 3.0 seconds
Instantiation should be done via the class methods, `for_hostport()`, and `for_localhost()` as appropriate. These helpers more aggressively require `port` and `host` arguments as appropriate. Generic construction arguments override the class attribute defaults:
`module` - Generated thrift module. `host` - IP address to connect to. `port` - Port to connect to. `path` - HTTP URI path to request. Enables HTTP client mode. `connect_timeout` - Socket connection timeout `transport_class` - Thrift transport class `protocol_class` - Thrift protocol class
Additional features are configurable with other arguments:
`lazy` - Default: True, connect on first RPC invocation, instead of at construction time.
Connections are made lazily, when the first rpc invocation occurs, so you do need to wrap client instantiation with a try-catch. """
connect_timeout=None, transport_class=None, protocol_class=None, path=None):
self.CONNECT_TIMEOUT)
# For non-http, default should be TFramed, for http, default TBuffered else:
self.TRANSPORT_CLASS, fallback_transport) self.PROTOCOL_CLASS)
else: self._connect()
else:
# TODO: Automatically connect on timed out connections
|