Ignore:
Timestamp:
Feb 25, 2012, 8:27:56 PM (9 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Let wokkel.component.Component reconnect if first attempt fails.

Author: ralphm.
Fixes #75.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/component.py

    r166 r169  
    55
    66"""
    7 XMPP External Component utilities
     7XMPP External Component utilities.
    88"""
    99
     
    2121
    2222class Component(StreamManager, service.Service):
     23    """
     24    XMPP External Component service.
     25
     26    This service is a XMPP stream manager that connects as an External
     27    Component to an XMPP server, as described in
     28    U{XEP-0114<http://xmpp.org/extensions/xep-0114.html>}.
     29    """
    2330    def __init__(self, host, port, jid, password):
    2431        self.host = host
     
    2936        StreamManager.__init__(self, factory)
    3037
     38
    3139    def _authd(self, xs):
     40        """
     41        Called when stream initialization has completed.
     42
     43        This replaces the C{send} method of the C{XmlStream} instance
     44        that represents the current connection so that outgoing stanzas
     45        always have a from attribute set to the JID of the component.
     46        """
    3247        old_send = xs.send
    3348
     
    4156        StreamManager._authd(self, xs)
    4257
     58
    4359    def initializationFailed(self, reason):
    4460        """
     
    5167        reason.raiseException()
    5268
     69
    5370    def startService(self):
     71        """
     72        Start the service and connect to the server.
     73        """
    5474        service.Service.startService(self)
    5575
     76        self._connection = self._getConnection()
     77
     78
     79    def stopService(self):
     80        """
     81        Stop the service, close the connection and prevent reconnects.
     82        """
     83        service.Service.stopService(self)
     84
    5685        self.factory.stopTrying()
    57         self._connection = self._getConnection()
    58 
    59     def stopService(self):
    60         service.Service.stopService(self)
    61 
    6286        self._connection.disconnect()
    6387
     88
    6489    def _getConnection(self):
     90        """
     91        Create a connector that connects to the server.
     92        """
    6593        return reactor.connectTCP(self.host, self.port, self.factory)
    6694
Note: See TracChangeset for help on using the changeset viewer.