Exemple #1
0
    def __init__(self, path, zk_hosts, waiting_in_secs=5, sc=dummy_statsd,
                 file_path=None):
        """Constructor for the data watcher.

        Args:
            path: the path to the znode to watch the data change on.
            zk_hosts: the zookeeper endpoint list.
                the list should have the following format:
                ['observerzookeeper010:2181',
                 'observerzookeeper011:2181',
                 'observerzookeeper012:2181',
                 'observerzookeeper013:2181',
                 'observerzookeeper014:2181',
                 'observerzookeeper015:2181']
            waiting_in_secs: the waiting time in seconds,
                when the operations on zookeeper fail; by default, 5 second.
            sc: the statsd client
            file_path: the local file to watch. When it is set, the data
                watcher does not talk to zk for monitoring data changes.
        """
        self._path = path
        self._path_stats_name = _escape_path_for_stats_name(path)
        self._waiting_in_secs = waiting_in_secs
        self.zk_hosts = zk_hosts
        self._sc = sc
        self._file_path = file_path
        self._file_path_stats_name = _escape_path_for_stats_name(file_path)
        # Stat is for allowing to return the stat of data with attribute
        # 'version'
        self.Stat = namedtuple('Stat', ['version'])
Exemple #2
0
    def __init__(self, path, zk_hosts, waiting_in_secs=5, sc=dummy_statsd,
                 file_path=None):
        """Constructor for the server set.

        Args:
            zk_hosts: the zk hosts list.
            path: the root path of the server set.
            waiting_in_secs: the waiting time in seconds,
                when the operations on zookeeper fail; by default, 5 second.
            sc: the statsd client
            file_path: the local file to watch. When it is set, the server
                set does not talk to zk for monitoring data changes.
        """
        self._path = path
        self._path_stats_name = _escape_path_for_stats_name(path)
        self._waiting_in_secs = waiting_in_secs
        self._is_destroyed = False
        self.zk_hosts = zk_hosts
        self._sc = sc
        self._file_path = file_path
        self._file_path_stats_name = _escape_path_for_stats_name(file_path)