Esempio n. 1
0
class ConnectedEnough(object):
    def __init__(self, storage_farm_broker, threshold):
        self._broker = storage_farm_broker

        self._threshold = int(threshold)
        if self._threshold <= 0:
            raise ValueError("threshold must be positive")
        self._threshold_passed = False

        self._observers = OneShotObserverList()
        self._broker.on_servers_changed(self._check_enough_connected)

    def when_connected_enough(self):
        """
        :returns: a Deferred that fires if/when our high water mark for
        number of connected servers becomes (or ever was) above
        "threshold".
        """
        if self._threshold_passed:
            return defer.succeed(None)
        return self._observers.when_fired()

    def _check_enough_connected(self):
        """
        internal helper
        """
        if self._threshold_passed:
            return
        num_servers = len(self._broker.get_connected_servers())
        if num_servers >= self._threshold:
            self._threshold_passed = True
            self._observers.fire(None)
Esempio n. 2
0
class ConnectedEnough(object):
    def __init__(self, storage_farm_broker, threshold):
        self._broker = storage_farm_broker

        self._threshold = int(threshold)
        if self._threshold <= 0:
            raise ValueError("threshold must be positive")
        self._threshold_passed = False

        self._observers = OneShotObserverList()
        self._broker.on_servers_changed(self._check_enough_connected)

    def when_connected_enough(self):
        """
        :returns: a Deferred that fires if/when our high water mark for
        number of connected servers becomes (or ever was) above
        "threshold".
        """
        if self._threshold_passed:
            return defer.succeed(None)
        return self._observers.when_fired()

    def _check_enough_connected(self):
        """
        internal helper
        """
        if self._threshold_passed:
            return
        num_servers = len(self._broker.get_connected_servers())
        if num_servers >= self._threshold:
            self._threshold_passed = True
            self._observers.fire(None)
Esempio n. 3
0
    def __init__(self, storage_farm_broker, threshold):
        self._broker = storage_farm_broker

        self._threshold = int(threshold)
        if self._threshold <= 0:
            raise ValueError("threshold must be positive")
        self._threshold_passed = False

        self._observers = OneShotObserverList()
        self._broker.on_servers_changed(self._check_enough_connected)
Esempio n. 4
0
    def __init__(self, storage_farm_broker, threshold):
        self._broker = storage_farm_broker

        self._threshold = int(threshold)
        if self._threshold <= 0:
            raise ValueError("threshold must be positive")
        self._threshold_passed = False

        self._observers = OneShotObserverList()
        self._broker.on_servers_changed(self._check_enough_connected)