Beispiel #1
0
    def __init__(self, observable_update_callback, host_ip, sender_callback, *args, **keys):
        """Shall initialize the given parameters as attributes and call the constructor of the super class.

        The observable_update_callback is in fact the update method of the observable
        implementation (in this case it may be UDPUpdateObservable). This method is called
        as a request is precessed by the handle method. As long as the received data is not
        sent by the the same host as it was received (I sent data to myself), the callback
        method is called. I define the "I sent data to myself"-thing as kickback.

        As a result of receiving lists from other hosts, the rhythm of sending our list
        to the multicast group has to be expanded. This is done by calling the sender_callback
        method. Which in fact is to expand the time of the sending rhythm.

        :param observable_update_callback: The callback of the observable implementation
        :param host_ip: The ip address of the host, where this handler is running
        :param sender_callback: The callback of the sending Thread.
        :param args: arguments for the BaseRequestHandler
        :param keys: keys for the BaseRequestHandler
        :return: None
        """
        self._observable_callback = observable_update_callback
        self._sender_callback = sender_callback

        self._own_ip = host_ip
        self._logger = Log.get_logger(self.__class__.__name__)
        BaseRequestHandler.__init__(self, *args, **keys)
Beispiel #2
0
    def __init__(self):
        """Shall initialize the list and a logger.

        :return: None
        """
        super().__init__()
        self._observers = []  # list of observers
        self.logger = Log.get_logger(self.__class__.__name__)
Beispiel #3
0
    def __init__(self):
        """Shall initialize the attributes and call the constructor of the super class.


        :return: None
        """
        super().__init__()
        self.runs = Event()

        # initial timeout
        self._timeout = self.TIMEOUT

        # the list handler singleton object to access the listhandler instance
        self.singleton = ListHandlerSingleton()

        # logger for logging purpose
        self.logger = Log.get_logger(name=self.__class__.__name__)
Beispiel #4
0
    def __init__(self, host_ip):
        """Initializes the attributes

        :param host_ip: The ip of the network interface where this service is running.
        :return: None
        """

        # initializes the Sender Thread
        self._sending_thread = UDPSenderThread()

        # initializes the udpserver with our ThreadedUDPMulticastRequestHandler

        # as arguments for the constructor of the RequestHandler we have to pass
        # the update method of the Observable Implementation and the ip-address of the network interface
        # 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__)
Beispiel #5
0
def main(argv):
    interface_name = None
    if len(argv) > 0:
        interface_name = argv[0]

    list_handler_singleton = ListHandlerSingleton()
    udp_observable_singleton = UDPObservableSingleton()

    logger = Log.get_logger("main")

    try:

        if interface_name:
            wlan_ip_addr = get_ip_address(interface_name)
        else:
            # determine current ip-address of the interface wlan0
            wlan_ip_addr = get_ip_address(INTERFACE_NAME)
    except OSError:
        logger.error("Not connected to any network on adapter %s. Please check the connection of %s.", INTERFACE_NAME,
                     INTERFACE_NAME)
        exit(1)
    logger.info("Selected network address: %s", wlan_ip_addr)

    # add own ip + empty Entry object to dict
    list_handler_singleton.handler.add_or_override_entry(wlan_ip_addr, Entry())

    udp_manager = UDPManager(wlan_ip_addr)

    udp_manager.start()

    observer = Observer()

    observer.subscribe_observed(udp_observable_singleton.observable)

    input("Enter to Exit.\n")

    udp_manager.stop()
Beispiel #6
0
 def add_observer(self, observer):
     if observer not in self._observers:
         self._observers.append(observer)
     Log.debug(self, "registered observer %s", observer)
Beispiel #7
0
 def update(self, observable, arg):
     # TODO: implement update function
     Log.info("Me: %s Data: %s", self, arg)
Beispiel #8
0
 def update(self, observable, arg):
     self.list.append(arg)
     # TODO: implement update function
     Log.info(self, "Data: %s", str(arg))