Пример #1
0
        # where this service is running.
        self.udp_server = UDPServer(MULTICAST_GROUP, lambda *args, **keys: ThreadedUDPMulticastRequestHandler(
            UDPObservableSingleton.instance.observable.update_received_list,
            host_ip, self._sending_thread.expand_timeout, *args, **keys))

        self._receiver_thread = Thread(target=self.udp_server.serve_forever, daemon=True)

        self._logger = Log.get_logger(self.__class__.__name__)

    def start(self):
        if not self._sending_thread.is_alive():
            self._logger.info("Started SenderThread.")
            self._sending_thread.start()

        if not self._receiver_thread.is_alive():
            self._logger.info("Started UDPServer.")
            self._receiver_thread.start()

    def stop(self):
        if self._sending_thread.is_alive():
            self._logger.info("Stopping SenderThread...")
            self._sending_thread.stop()

        if self._receiver_thread.is_alive():
            self._logger.info("Stopping UDPServer...")
            self.udp_server.shutdown()
            self.udp_server.server_close()


synchronize(UDPUpdateObseravable, "add_observer remove_observer notify_observers" +
            "set_changed clear_changed has_changed update_received_list")
Пример #2
0
            if self.has_changed():
                return

            tmp_copy = self._observers.copy()

            self.clear_changed()

        for x in tmp_copy:
            x.update(self, arg)

    def update_private_data(self):
        private_data = random.randint(0, 10)
        self.notify_observers(private_data)


synchronize(ObservableImplementation, "add_observer remove_observer notify_observers" +
            "set_changed clear_changed has_changed")


# end class

class ObserverInterface(metaclass=ABCMeta):
    """Observer pattern: Observer interface"""

    @abstractmethod
    def update(self, observable, arg):
        pass


# end class

class Observer(ObserverInterface):
Пример #3
0
    def __str__(self):
        """Shall return a string representation of the _dict attribute.


        :return: string representation of the _dict attribute.
        """
        rtn = ''

        cpy_dict = self._dict.copy()

        for k in iter(cpy_dict):
            rtn = (rtn + "{0}:\n {1}").format(k, str(cpy_dict[k]))
        return rtn


synchronize(ListHandler, "add_or_override_entry rmv_entry get_entry to_json decode")


class Entry(object):
    """This class holds the attributes of a host within the network.
    """

    def __init__(self, is_master=False, pyro_uri="", last_time_active=-1):
        """Shall initialize the attributes with the given (default-) parameters.


        :param is_master: defines if is this entry a master node
        :param pyro_uri: the pyro uri of this entry
        :param last_time_active: the timestamp of the last activity received from the remote host.
        :return: None
        """