~ubuntu-branches/ubuntu/lucid/landscape-client/lucid-updates

« back to all changes in this revision

Viewing changes to landscape/broker/ping.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-04-10 14:28:48 UTC
  • mfrom: (1.1.27)
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: package-import@ubuntu.com-20120410142848-7xsy4g2xii7y7ntc
ImportĀ upstreamĀ versionĀ 12.04.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
class PingClient(object):
18
18
    """An HTTP client which asks: Are there messages for computer X?
 
19
 
 
20
    @param url: The URL to ask the question to.
 
21
    @type identity: L{landscape.broker.registration.Identity}
 
22
    @param identity: This client's identity.
 
23
    @param get_page: The method to use to retrieve content.  If not specified,
 
24
        landscape.lib.fetch.fetch is used.
19
25
    """
20
26
 
21
27
    def __init__(self, reactor, url, identity, get_page=None):
22
 
        """
23
 
        @param url: The URL to ask the question to.
24
 
        @type identity: L{landscape.broker.registration.Identity}
25
 
        @param identity: This client's identity.
26
 
        """
27
28
        if get_page is None:
28
29
            get_page = fetch
29
30
        self._reactor = reactor
49
50
            def errback(type, value, tb):
50
51
                page_deferred.errback(Failure(value, type, tb))
51
52
            self._reactor.call_in_thread(page_deferred.callback, errback,
52
 
                                         self.get_page, self.url, post=True,
53
 
                                         data=data, headers=headers)
 
53
                                         self.get_page, self.url,
 
54
                                         post=True, data=data,
 
55
                                         headers=headers)
54
56
            page_deferred.addCallback(self._got_result)
55
57
            return page_deferred
56
58
        return defer.succeed(False)
69
71
    """
70
72
    A plugin which pings the Landscape server with HTTP requests to
71
73
    see if a full exchange should be initiated.
 
74
 
 
75
    @param reactor: The reactor to schedule calls with
 
76
    @param url: The URL to ping
 
77
    @param interval: How often to send the pings
 
78
    @param exchanger: The L{landscape.broker.exchange.MessageExchange} to
 
79
        trigger exchanges with.
72
80
    """
73
81
 
74
82
    def __init__(self, reactor, url, identity, exchanger,
75
83
                 interval=30, ping_client_factory=PingClient):
76
 
        """
77
 
        @param reactor: The reactor to schedule calls with
78
 
        @param url: The URL to ping
79
 
        @param interval: How often to send the pings
80
 
        @param exchanger: The L{landscape.broker.exchange.MessageExchange} to
81
 
            trigger exchanges with.
82
 
        """
83
84
        self._url = url
84
85
        self._interval = interval
85
86
        self._identity = identity
103
104
 
104
105
    def start(self):
105
106
        """Start pinging."""
106
 
        self._ping_client = self.ping_client_factory(self._reactor, self._url,
107
 
                                                     self._identity)
 
107
        self._ping_client = self.ping_client_factory(
 
108
            self._reactor, self._url, self._identity)
108
109
        self._call_id = self._reactor.call_every(self._interval, self.ping)
109
110
 
110
111
    def ping(self):
121
122
 
122
123
    def _got_error(self, failure):
123
124
        log_failure(failure,
124
 
                    "Error contacting ping server at %s" % (self._url,))
 
125
                    "Error contacting ping server at %s" %
 
126
                    (self._ping_client.url,))
125
127
 
126
128
    def _handle_set_intervals(self, message):
127
129
        if message["type"] == "set-intervals" and "ping" in message: