class ClientService(Service): (source)
Constructor: ClientService(endpoint, factory, retryPolicy, clock, prepareConnection)
A ClientService
maintains a single outgoing connection to a client endpoint, reconnecting after a configurable timeout when a connection fails, either before or after connecting.
Present Since | |
16.1.0 |
Method | __init__ |
No summary |
Method | start |
Start this ClientService , initiating the connection retry loop. |
Method | stop |
Stop attempting to reconnect and close any existing connections. |
Method | when |
Retrieve the currently-connected Protocol , or the next one to connect. |
Class Variable | _log |
Undocumented |
Instance Variable | _machine |
Undocumented |
Inherited from Service
:
Method | __getstate__ |
Undocumented |
Method | disown |
Use this API to remove an IService from an IServiceCollection . |
Method | privileged |
Do preparation work for starting the service. |
Method | set |
Set the name of the service. |
Method | set |
Set the parent of the service. This method is responsible for setting the parent attribute on this service (the child service). |
Instance Variable | name |
A str which is the name of the service or None. |
Instance Variable | parent |
An IServiceCollection which is the parent or None. |
Instance Variable | running |
A boolean which indicates whether the service is running. |
IStreamClientEndpoint
, factory: IProtocolFactory
, retryPolicy: Callable[ [ int], float] | None
= None, clock: IReactorTime | None
= None, prepareConnection: Callable[ [ IProtocol], object] | None
= None):
(source)
¶
Parameters | |
endpoint:IStreamClientEndpoint | A stream client endpoint provider which will be used to connect when the service starts. |
factory:IProtocolFactory | A protocol factory which will be used to create clients for the endpoint. |
retryCallable[ | A policy configuring how long ClientService will wait between attempts to connect to endpoint; a callable taking (the number of failed connection attempts made in a row (int )) and returning the number of seconds to wait before making another attempt. |
clock:IReactorTime | None | The clock used to schedule reconnection. It's mainly useful to be parametrized in tests. If the factory is serialized, this attribute will not be serialized, and the default value (the reactor) will be restored when deserialized. |
prepareCallable[ | A single argument The prepareConnection callable may raise an exception or return a
Present Since Twisted 18.7.0 |
Retrieve the currently-connected Protocol
, or the next one to connect.
Parameters | |
failint 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 | |
| a Deferred that fires with a protocol produced by the factory passed to __init__ |