nopasaran.controllers.factory.WorkerClientFactory

class nopasaran.controllers.factory.WorkerClientFactory(state_machine, variable)

Bases: ReconnectingClientFactory

A factory for creating WorkerClientProtocol instances.

This factory is responsible for creating client protocols and managing reconnection.

__init__(state_machine, variable)

Initialize the WorkerClientFactory.

Args:

state_machine: The state machine object. variable: The variable object.

Methods

__init__(state_machine, variable)

Initialize the WorkerClientFactory.

buildProtocol(addr)

Create an instance of a subclass of Protocol.

clientConnectionFailed(connector, reason)

Called when a connection has failed to connect.

clientConnectionLost(connector, unused_reason)

Called when an established connection is lost.

doStart()

Make sure startFactory is called.

doStop()

Make sure stopFactory is called.

forProtocol(protocol, *args, **kwargs)

Create a factory for the given protocol.

logPrefix()

Describe this factory for log messages.

resetDelay()

Call this method after a successful connection: it resets the delay and the retry counter.

retry([connector])

Have this connector connect again, after a suitable delay.

startFactory()

This will be called before I begin listening on a Port or Connector.

startedConnecting(connector)

Called when a connection has been started.

stopFactory()

This will be called before I stop listening on all Ports/Connectors.

stopTrying()

Put a stop to any attempt to reconnect in progress.

Attributes

clock

connector

continueTrying

delay

factor

initialDelay

jitter

maxDelay

maxRetries

noisy

numPorts

retries

buildProtocol(addr: <InterfaceClass twisted.internet.interfaces.IAddress>) Protocol | None

Create an instance of a subclass of Protocol.

The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.

Alternatively, L{None} may be returned to immediately close the new connection.

Override this method to alter how Protocol instances get created.

@param addr: an object implementing L{IAddress}

clientConnectionFailed(connector, reason)

Called when a connection has failed to connect.

It may be useful to call connector.connect() - this will reconnect.

@type reason: L{twisted.python.failure.Failure}

clientConnectionLost(connector, unused_reason)

Called when an established connection is lost.

It may be useful to call connector.connect() - this will reconnect.

@type reason: L{twisted.python.failure.Failure}

doStart()

Make sure startFactory is called.

Users should not call this function themselves!

doStop()

Make sure stopFactory is called.

Users should not call this function themselves!

classmethod forProtocol(protocol, *args, **kwargs)

Create a factory for the given protocol.

It sets the C{protocol} attribute and returns the constructed factory instance.

@param protocol: A L{Protocol} subclass

@param args: Positional arguments for the factory.

@param kwargs: Keyword arguments for the factory.

@return: A L{Factory} instance wired up to C{protocol}.

logPrefix()

Describe this factory for log messages.

protocol

alias of WorkerClientProtocol

resetDelay()

Call this method after a successful connection: it resets the delay and the retry counter.

retry(connector=None)

Have this connector connect again, after a suitable delay.

startFactory()

This will be called before I begin listening on a Port or Connector.

It will only be called once, even if the factory is connected to multiple ports.

This can be used to perform ‘unserialization’ tasks that are best put off until things are actually running, such as connecting to a database, opening files, etcetera.

startedConnecting(connector)

Called when a connection has been started.

You can call connector.stopConnecting() to stop the connection attempt.

@param connector: a Connector object.

stopFactory()

This will be called before I stop listening on all Ports/Connectors.

This can be overridden to perform ‘shutdown’ tasks such as disconnecting database connections, closing files, etc.

It will be called, for example, before an application shuts down, if it was connected to a port. User code should not call this function directly.

stopTrying()

Put a stop to any attempt to reconnect in progress.