State machine for maintaining a single outgoing connection to an endpoint.

See AlsoClientService
Method __init__
Method start Start this ClientService, initiating the connection retry loop.
Method stop Stop trying to connect and disconnect any current connection.
Method whenConnected Retrieve the currently-connected Protocol, or the next one to connect.
Method _init The service has not been started.
Method _connecting The service has started connecting.
Method _waiting The service is waiting for the reconnection period before reconnecting.
Method _connected The service is connected.
Method _disconnecting The service is disconnecting after being asked to shutdown.
Method _restarting The service is disconnecting and has been asked to restart.
Method _stopped The service has been stopped and is disconnected.
Method _connect Start a connection attempt.
Method _runPrepareConnection Run any prepareConnection callback with the connected protocol, ignoring its return value but propagating any failure.
Method _resetFailedAttempts Reset the number of failed attempts.
Method _waitForStop Return a deferred that will fire when the service has finished disconnecting.
Method _stopConnecting Stop pending connection attempt.
Method _stopRetrying Stop pending attempt to reconnect.
Method _disconnect Disconnect the current connection.
Method _connectionMade A connection has been made.
Method _notifyWaiters Notify all pending requests for a connection that a connection has been made.
Method _connectionFailed The current connection attempt failed.
Method _wait Schedule a retry attempt.
Method _ignoreAndWait Schedule a retry attempt, and ignore the Failure passed in.
Method _doWait Undocumented
Method _reconnect The wait between connection attempts is done.
Method _clientDisconnected The current connection has been disconnected.
Method _forgetConnection Forget the current connection.
Method _cancelConnectWaiters Notify all pending requests for a connection that no more connections are expected.
Method _ignoreAndCancelConnectWaiters Notify all pending requests for a connection that no more connections are expected, after ignoring the Failure passed in.
Method _finishStopping Notify all deferreds waiting on the service stopping.
Method _ignoreAndFinishStopping Notify all deferreds waiting on the service stopping, and ignore the Failure passed in.
Method _doFinishStopping Undocumented
Method _currentConnection Return the currently connected protocol.
Method _noConnection Notify the caller that no connection is expected.
Method _awaitingConnection Return a deferred that will fire with the next connected protocol.
Method _deferredSucceededWithNone Return a deferred that has already fired with None.
Method _unawait Fire all outstanding ClientService.whenConnected Deferreds.
Method _deliverConnectionFailure Deliver connection failures to any ClientService.whenConnected Deferreds that have met their failAfterFailures threshold.
def __init__(self, endpoint, factory, retryPolicy, clock, prepareConnection, log): (source)
ParameterslogThe logger for the ClientService instance this state machine is associated to. (type: Logger)
See AlsoClientService.__init__
@_machine.state(True)
def _init(self): (source)

The service has not been started.

@_machine.state()
def _connecting(self): (source)

The service has started connecting.

@_machine.state()
def _waiting(self): (source)

The service is waiting for the reconnection period before reconnecting.

@_machine.state()
def _connected(self): (source)

The service is connected.

@_machine.state()
def _disconnecting(self): (source)

The service is disconnecting after being asked to shutdown.

@_machine.state()
def _restarting(self): (source)

The service is disconnecting and has been asked to restart.

@_machine.state()
def _stopped(self): (source)

The service has been stopped and is disconnected.

@_machine.input()
def start(self): (source)

Start this ClientService, initiating the connection retry loop.

@_machine.output()
def _connect(self): (source)

Start a connection attempt.

def _runPrepareConnection(self, protocol): (source)

Run any prepareConnection callback with the connected protocol, ignoring its return value but propagating any failure.

ParametersprotocolThe protocol of the connection. (type: IProtocol)
ReturnsEither:
  • A Deferred that succeeds with the protocol when the prepareConnection callback has executed successfully.
  • A Deferred that fails when the prepareConnection callback throws or returns a failed Deferred.
  • The protocol, when no prepareConnection callback is defined.
@_machine.output()
def _resetFailedAttempts(self): (source)

Reset the number of failed attempts.

@_machine.input()
def stop(self): (source)

Stop trying to connect and disconnect any current connection.

Returnsa Deferred that fires when all outstanding connections are closed and all in-progress connection attempts halted.
@_machine.output()
def _waitForStop(self): (source)

Return a deferred that will fire when the service has finished disconnecting.

ReturnsDeferred that fires when the service has finished disconnecting.
@_machine.output()
def _stopConnecting(self): (source)

Stop pending connection attempt.

@_machine.output()
def _stopRetrying(self): (source)

Stop pending attempt to reconnect.

@_machine.output()
def _disconnect(self): (source)

Disconnect the current connection.

@_machine.input()
def _connectionMade(self, protocol): (source)

A connection has been made.

ParametersprotocolThe protocol of the connection. (type: IProtocol)
@_machine.output()
def _notifyWaiters(self, protocol): (source)

Notify all pending requests for a connection that a connection has been made.

ParametersprotocolThe protocol of the connection. (type: IProtocol)
@_machine.input()
def _connectionFailed(self, f): (source)

The current connection attempt failed.

@_machine.output()
def _wait(self): (source)

Schedule a retry attempt.

@_machine.output()
def _ignoreAndWait(self, f): (source)

Schedule a retry attempt, and ignore the Failure passed in.

def _doWait(self): (source)
Undocumented
@_machine.input()
def _reconnect(self): (source)

The wait between connection attempts is done.

@_machine.input()
def _clientDisconnected(self): (source)

The current connection has been disconnected.

@_machine.output()
def _forgetConnection(self): (source)

Forget the current connection.

@_machine.output()
def _cancelConnectWaiters(self): (source)

Notify all pending requests for a connection that no more connections are expected.

@_machine.output()
def _ignoreAndCancelConnectWaiters(self, f): (source)

Notify all pending requests for a connection that no more connections are expected, after ignoring the Failure passed in.

@_machine.output()
def _finishStopping(self): (source)

Notify all deferreds waiting on the service stopping.

@_machine.output()
def _ignoreAndFinishStopping(self, f): (source)

Notify all deferreds waiting on the service stopping, and ignore the Failure passed in.

def _doFinishStopping(self): (source)
Undocumented
@_machine.input()
def whenConnected(self, failAfterFailures=None): (source)

Retrieve the currently-connected Protocol, or the next one to connect.

ParametersfailAfterFailuresnumber of connection failures after which the Deferred will deliver a Failure (None means the Deferred will only fail if/when the service is stopped). Set this to 1 to make the very first connection failure signal an error. Use 2 to allow one failure but signal an error if the subsequent retry then fails. (type: int or None)
Returnsa Deferred that fires with a protocol produced by the factory passed to __init__ (type: Deferred that may: )
@_machine.output()
def _currentConnection(self, failAfterFailures=None): (source)

Return the currently connected protocol.

ReturnsDeferred that is fired with currently connected protocol.
@_machine.output()
def _noConnection(self, failAfterFailures=None): (source)

Notify the caller that no connection is expected.

ReturnsDeferred that is fired with CancelledError.
@_machine.output()
def _awaitingConnection(self, failAfterFailures=None): (source)

Return a deferred that will fire with the next connected protocol.

ReturnsDeferred that will fire with the next connected protocol.
@_machine.output()
def _deferredSucceededWithNone(self): (source)

Return a deferred that has already fired with None.

ReturnsA Deferred that has already fired with None.
def _unawait(self, value): (source)

Fire all outstanding ClientService.whenConnected Deferreds.

Parametersvaluethe value to fire the Deferreds with.
@_machine.output()
def _deliverConnectionFailure(self, f): (source)

Deliver connection failures to any ClientService.whenConnected Deferreds that have met their failAfterFailures threshold.

Parametersfthe Failure to fire the Deferreds with.
API Documentation for Twisted, generated by pydoctor at 2018-10-15 19:29:43.