Package foolscap :: Module pb :: Class Listener
[hide private]
[frames] | no frames]

Class Listener

source code

  twisted.internet.protocol.Factory --+    
                                      |    
twisted.internet.protocol.ServerFactory --+
                                          |
                                         Listener

I am responsible for a single listening port, which may connect to multiple Tubs. I have a strports-based Service, which I will attach as a child of one of my Tubs. If that Tub disconnects, I will reparent the Service to a remaining one.

Unauthenticated Tubs use a TubID of 'None'. There may be at most one such Tub attached to any given Listener.

Instance Methods [hide private]
 
__init__(self, port, options={}, negotiationClass=<class foolscap.negotiate.Negotiation at 0x877850c>) source code
 
getPortnum(self)
When this Listener was created with a strport string of '0' or 'tcp:0' (meaning 'please allocate me something'), and if the Listener is active (it is attached to a Tub which is in the 'running' state), this method will return the port number that was allocated.
source code
 
__repr__(self) source code
 
addTub(self, tub) source code
 
removeTub(self, tub) source code
 
getService(self) source code
 
addRedirect(self, tubID, location) source code
 
removeRedirect(self, tubID) source code
 
startFactory(self)
This will be called before I begin listening on a Port or Connector.
source code
 
stopFactory(self)
This will be called before I stop listening on all Ports/Connectors.
source code
 
buildProtocol(self, addr)
Return a Broker attached to me (as the service provider).
source code
 
lookupTubID(self, tubID) source code

Inherited from twisted.internet.protocol.Factory: __providedBy__, doStart, doStop

Class Variables [hide private]
  noisy = False

Inherited from twisted.internet.protocol.Factory: __implemented__, __provides__, numPorts, protocol

Method Details [hide private]

__init__(self, port, options={}, negotiationClass=<class foolscap.negotiate.Negotiation at 0x877850c>)
(Constructor)

source code 
Parameters:
  • port (string) - a twisted.application.strports -style description.

getPortnum(self)

source code 

When this Listener was created with a strport string of '0' or 'tcp:0' (meaning 'please allocate me something'), and if the Listener is active (it is attached to a Tub which is in the 'running' state), this method will return the port number that was allocated. This is useful for the following pattern:

   t = Tub()
   l = t.listenOn('tcp:0')
   t.setLocation('localhost:%d' % l.getPortnum())

startFactory(self)

source code 

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.

Overrides: twisted.internet.protocol.Factory.startFactory
(inherited documentation)

stopFactory(self)

source code 

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.

Overrides: twisted.internet.protocol.Factory.stopFactory
(inherited documentation)

buildProtocol(self, addr)

source code 

Return a Broker attached to me (as the service provider).

Parameters:
  • addr - an object implementing twisted.internet.interfaces.IAddress
Overrides: twisted.internet.protocol.Factory.buildProtocol