Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`application`.`internet`.`_ClientMachine``

class documentation

`class _ClientMachine: (source)`

Constructor: `_ClientMachine(endpoint, factory, retryPolicy, clock, ...)`

View In Hierarchy

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

See Also
`ClientService`

Method | `__init__` | No summary
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 | `_awaitingConnection` | Return a deferred that will fire with the next connected protocol.
Method | `_cancelConnectWaiters` | Notify all pending requests for a connection that no more connections are expected.
Method | `_clientDisconnected` | The current connection has been disconnected.
Method | `_connect` | Start a connection attempt.
Method | `_connected` | The service is connected.
Method | `_connecting` | The service has started connecting.
Method | `_connectionFailed` | The current connection attempt failed.
Method | `_connectionMade` | A connection has been made.
Method | `_currentConnection` | Return the currently connected protocol.
Method | `_deferredSucceededWithNone` | Return a deferred that has already fired with `None`.
Method | `_deliverConnectionFailure` | Deliver connection failures to any `ClientService.whenConnected` `Deferred`s that have met their failAfterFailures threshold.
Method | `_disconnect` | Disconnect the current connection.
Method | `_disconnecting` | The service is disconnecting after being asked to shutdown.
Method | `_doFinishStopping` | Undocumented
Method | `_doWait` | Undocumented
Method | `_finishStopping` | Notify all deferreds waiting on the service stopping.
Method | `_forgetConnection` | Forget the current connection.
Method | `_ignoreAndCancelConnectWaiters` | Notify all pending requests for a connection that no more connections are expected, after ignoring the Failure passed in.
Method | `_ignoreAndFinishStopping` | Notify all deferreds waiting on the service stopping, and ignore the Failure passed in.
Method | `_ignoreAndWait` | Schedule a retry attempt, and ignore the Failure passed in.
Method | `_init` | The service has not been started.
Method | `_noConnection` | Notify the caller that no connection is expected.
Method | `_notifyWaiters` | Notify all pending requests for a connection that a connection has been made.
Method | `_reconnect` | The wait between connection attempts is done.
Method | `_resetFailedAttempts` | Reset the number of failed attempts.
Method | `_restarting` | The service is disconnecting and has been asked to restart.
Method | `_runPrepareConnection` | Run any `prepareConnection` callback with the connected protocol, ignoring its return value but propagating any failure.
Method | `_stopConnecting` | Stop pending connection attempt.
Method | `_stopped` | The service has been stopped and is disconnected.
Method | `_stopRetrying` | Stop pending attempt to reconnect.
Method | `_unawait` | Fire all outstanding `ClientService.whenConnected` `Deferred`s.
Method | `_wait` | Schedule a retry attempt.
Method | `_waitForStop` | Return a deferred that will fire when the service has finished disconnecting.
Method | `_waiting` | The service is waiting for the reconnection period before reconnecting.
Class Variable | `_machine` | Undocumented
Instance Variable | `_awaitingConnected` | notifications to make when connection succeeds, fails, or is cancelled
Instance Variable | `_clock` | Undocumented
Instance Variable | `_connectionInProgress` | Undocumented
Instance Variable | `_endpoint` | Undocumented
Instance Variable | `_factory` | Undocumented
Instance Variable | `_failedAttempts` | Undocumented
Instance Variable | `_log` | Undocumented
Instance Variable | `_prepareConnection` | Undocumented
Instance Variable | `_retryCall` | Undocumented
Instance Variable | `_stopWaiters` | Undocumented
Instance Variable | `_timeoutForAttempt` | Undocumented

def __init__(self, endpoint, factory, retryPolicy, clock, prepareConnection, log): (source)

Parameters
endpoint | Undocumented
factory | Undocumented
retryPolicy | Undocumented
clock | Undocumented
prepareConnection | Undocumented
log:`Logger` | The logger for the `ClientService` instance this state machine is associated to.
See Also
`ClientService.__init__`

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

Start this `ClientService`, initiating the connection retry loop.

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

Stop trying to connect and disconnect any current connection.

Returns
a `Deferred` that fires when all outstanding connections are closed and all in-progress connection attempts halted.

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

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

Parameters
failAfterFailures:`int` or None | number 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.
Returns

`Deferred` that may:

- fire with `IProtocol`
- fail with `CancelledError` when the service is stopped
- fail with e.g. `DNSLookupError` or `ConnectionRefusedError` when the number of consecutive failed connection attempts equals the value of "failAfterFailures"

a Deferred that fires with a protocol produced by the factory passed to `__init__`

@_machine.output()
def _awaitingConnection(self, failAfterFailures=None): (source)

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

Returns
`Deferred` that will fire with the next connected protocol.

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

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

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

The current connection has been disconnected.

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

Start a connection attempt.

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

The service is connected.

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

The service has started connecting.

@_machine.input()
def _connectionFailed(self, f): (source)

The current connection attempt failed.

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

A connection has been made.

Parameters
protocol:`IProtocol` | The protocol of the connection.

@_machine.output()
def _currentConnection(self, failAfterFailures=None): (source)

Return the currently connected protocol.

Returns
`Deferred` that is fired with currently connected protocol.

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

Return a deferred that has already fired with `None`.

Returns
A `Deferred` that has already fired with `None`.

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

Deliver connection failures to any `ClientService.whenConnected` `Deferred`s that have met their failAfterFailures threshold.

Parameters
f | the Failure to fire the `Deferred`s with.

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

Disconnect the current connection.

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

The service is disconnecting after being asked to shutdown.

def _doFinishStopping(self): (source)

Undocumented

def _doWait(self): (source)

Undocumented

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

Notify all deferreds waiting on the service stopping.

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

Forget the current connection.

@_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 _ignoreAndFinishStopping(self, f): (source)

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

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

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

@_machine.state(initial=True)
def _init(self): (source)

The service has not been started.

@_machine.output()
def _noConnection(self, failAfterFailures=None): (source)

Notify the caller that no connection is expected.

Returns
`Deferred` that is fired with `CancelledError`.

@_machine.output()
def _notifyWaiters(self, protocol): (source)

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

Parameters
protocol:`IProtocol` | The protocol of the connection.

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

The wait between connection attempts is done.

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

Reset the number of failed attempts.

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

The service is disconnecting and has been asked to restart.

def _runPrepareConnection(self, protocol): (source)

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

Parameters
protocol:`IProtocol` | The protocol of the connection.
Returns

Either:

- 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 _stopConnecting(self): (source)

Stop pending connection attempt.

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

The service has been stopped and is disconnected.

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

Stop pending attempt to reconnect.

def _unawait(self, value): (source)

Fire all outstanding `ClientService.whenConnected` `Deferred`s.

Parameters
value | the value to fire the `Deferred`s with.

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

Schedule a retry attempt.

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

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

Returns
`Deferred` that fires when the service has finished disconnecting.

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

The service is waiting for the reconnection period before reconnecting.

_machine = (source)

Undocumented

_awaitingConnected: list of (Deferred, count) tuples = (source)

notifications to make when connection succeeds, fails, or is cancelled

_clock = (source)

Undocumented

_connectionInProgress = (source)

Undocumented

_endpoint = (source)

Undocumented

_factory = (source)

Undocumented

_failedAttempts: `int` = (source)

Undocumented

_log = (source)

Undocumented

_prepareConnection = (source)

Undocumented

_retryCall = (source)

Undocumented

_stopWaiters: `list` = (source)

Undocumented

_timeoutForAttempt = (source)

Undocumented