class documentation

class Transport(object):

View In Hierarchy

Low-level transport class.

This is used on the client side.

This could be replaced by any other class that provides the same semantics to the Client. This means:

  • can send messages and receive messages
  • safe for multithreading
Static Method RetryOnNetworkError Calls a given function, retrying if it fails on a network IO exception.
Method __init__ Constructor for the Client class.
Method Call Send a message and wait for the response.
Method Close Close the socket
Method Recv Try to receive a message from the socket.
Method Send Send a message.
Instance Variable address Undocumented
Instance Variable socket Undocumented
Static Method _Connect Undocumented
Method _CheckSocket Make sure we are connected.
Instance Variable _buffer Undocumented
Instance Variable _ctimeout Undocumented
Instance Variable _msgs Undocumented
Instance Variable _rwtimeout Undocumented
@staticmethod
def RetryOnNetworkError(fn, on_error, retries=15, wait_on_error=5):

Calls a given function, retrying if it fails on a network IO exception.

This allows to re-establish a broken connection and retry an IO operation.

The function receives one an integer argument stating the current retry number, 0 being the first call, 1 being the first retry, 2 the second, and so on.

If any exception occurs, on_error is invoked first with the exception given as an argument. Then, if the exception is a network exception, the function call is retried once more.

def __init__(self, address, timeouts=None, allow_non_master=None):

Constructor for the Client class.

There are two timeouts used since we might want to wait for a long time for a response, but the connect timeout should be lower.

If not passed, we use the default luxi timeouts from the global constants file.

Note that on reading data, since the timeout applies to an invidual receive, it might be that the total duration is longer than timeout value passed (we make a hard limit at twice the read timeout).

Parameters
address:socket addressaddress the transport connects to
timeouts:list of intstimeouts to be used on connect and read/write
allow_non_master:boolskip checks for the master node on errors
def Call(self, msg):

Send a message and wait for the response.

This is just a wrapper over Send and Recv.

def Close(self):

Close the socket

def Recv(self):

Try to receive a message from the socket.

In case we already have messages queued, we just return from the queue. Otherwise, we try to read data with a _rwtimeout network timeout, and making sure we don't go over 2x_rwtimeout as a global limit.

def Send(self, msg):

Send a message.

This just sends a message and doesn't wait for the response.

address =

Undocumented

socket =

Undocumented

@staticmethod
def _Connect(sock, address, timeout, allow_non_master):

Undocumented

def _CheckSocket(self):

Make sure we are connected.

_buffer =

Undocumented

_ctimeout =

Undocumented

_msgs =

Undocumented

_rwtimeout =

Undocumented