예제 #1
0
 def __init__(self, ip, port, type, db):
     #self._config = config
     self._ip = ip
     self._port = port
     self._type = type
     self._db = db
     self._discoverer = Discoverer(self._type)
 def __init__(self, ip, port, type, db):
     #self._config = config
     self._ip = ip
     self._port = port
     self._type = type
     self._db = db
     self._discoverer = Discoverer(self._type)
예제 #3
0
    def __init__(self, config_file=None):
        self._config_manager = ConfigManager(config_file)

        self._server = Server(self._config_manager.server_config,
                              self._config_manager.content_db,
                              self._config_manager.identity)

        self._discoverer = Discoverer(self._config_manager.discoverer_config, server_config=self._config_manager.server_config)

        self._synchronizer = Synchronizer(self._discoverer,
                                          self._config_manager.synchronizer_config,
                                          self._config_manager.content_db)
예제 #4
0
class DandelionApp:

    def __init__(self, config_file=None):
        self._config_manager = ConfigManager(config_file)

        self._server = Server(self._config_manager.server_config,
                              self._config_manager.content_db,
                              self._config_manager.identity)

        self._discoverer = Discoverer(self._config_manager.discoverer_config, server_config=self._config_manager.server_config)

        self._synchronizer = Synchronizer(self._discoverer,
                                          self._config_manager.synchronizer_config,
                                          self._config_manager.content_db)

    def run_ui(self):

        self._ui = UI(self._config_manager.ui_config,
                      self._config_manager.content_db,
                      self._config_manager.identity,
                      self._server,
                      self._discoverer,
                      self._synchronizer)

        self._ui.run()

    def run_gui(self):
        from dandelion.gui.gui import GUI
        self._gui = GUI(self._config_manager.ui_config,
                        self._config_manager.content_db,
                        self._config_manager.identity,
                        self._server,
                        self._synchronizer)

    def exit(self):
        self._synchronizer.stop()
        self._discoverer.stop()
        self._server.stop()
        self._config_manager.write_file()
class Synchronizer(Service):
    
    def __init__(self, ip, port, type, db):
        #self._config = config
        self._ip = ip
        self._port = port
        self._type = type
        self._db = db
        self._discoverer = Discoverer(self._type)
        
    def start(self):
        """Start the service. Block until the service is running."""
        #print('SYNCHRONIZER: Starting')
        self._stop_requested = False
        self._thread = Thread(target=self._sync_loop)
        self._thread.start()
        self._running = True
    
    def stop(self):
        """Stop the service. Block until the service is running."""
        
        self._stop_requested = True
        #print('SYNCHRONIZER: Stopping')
        self._thread.join(0.1)
        if self._thread.is_alive():
            raise Exception # Timeout
            
        self._running = False
        
    
    def restart(self):
        """Stop then start the service. Blocking call"""
        self.stop()
        self.start()
    
    @property
    def status(self):
        """A string with information about the service"""
        print(''.join(['Synchronizer status: Running: ', str(self._running)]))
        
    
    @property 
    def running(self):
        """Returns True if the service is running, False otherwise"""
        return self._running
        
    def _sync_loop(self):
        #print('SYNCHRONIZER: Running')

        t1 = time.time()
        while not self._stop_requested:
            t2 = time.time()

            """Should we sync or just keep checking the stop condition?"""
            if t2 - t1 < 10:
                time.sleep(0.01) # Don't busy wait
                continue
            
            #print("SYNCHRONIZER: Time for a sync")
            
            # Should use the discoverer here...
            host = "localhost"
            port = 1337
            
            with Client(host, port, self._db) as client:
                client.execute_transaction()
            
            t1 = time.time()
    
    def start(self):
        """Start the service. Block until the service is running."""
        print('SYNCHRONIZER: Starting')
        self._stop_requested = False
        self._thread = Thread(target=self._sync_loop)
        self._thread.start()
        self._running = True
        
        self._discoverer.start()
    
    def stop(self):
        """Stop the service. Block until the service is running."""
        
        self._stop_requested = True
        print('SYNCHRONIZER: Stopping')
        self._thread.join(0.1)
        if self._thread.is_alive():
            raise Exception # Timeout
            
        self._discoverer.stop()
        self._running = False
        
    
    def restart(self):
        """Stop then start the service. Blocking call"""
        self.stop()
        self.start()
    
    @property
    def status(self):
        """A string with information about the service"""
        print(''.join(['Synchronizer status: Running: ', str(self._running)]))
        
    
    @property 
    def running(self):
        """Returns True if the service is running, False otherwise"""
        return self._running
        
    def _sync_loop(self):
        print('SYNCHRONIZER: Running')

        t1 = time.time()
        while not self._stop_requested:
            t2 = time.time()

            """Should we sync or just keep checking the stop condition?"""
            if t2 - t1 < 10:
                time.sleep(0.01) # Don't busy wait
                continue
            
            # Should use the discoverer here...
            
            info_dict = self._discoverer.get_results()
            
            """
            with Client(host, port, self._db) as client:
                client.execute_transaction()
            """
            t1 = time.time()
예제 #6
0
class Synchronizer(Service):
    def __init__(self, ip, port, type, db):
        #self._config = config
        self._ip = ip
        self._port = port
        self._type = type
        self._db = db
        self._discoverer = Discoverer(self._type)

    def start(self):
        """Start the service. Block until the service is running."""
        #print('SYNCHRONIZER: Starting')
        self._stop_requested = False
        self._thread = Thread(target=self._sync_loop)
        self._thread.start()
        self._running = True

    def stop(self):
        """Stop the service. Block until the service is running."""

        self._stop_requested = True
        #print('SYNCHRONIZER: Stopping')
        self._thread.join(0.1)
        if self._thread.is_alive():
            raise Exception  # Timeout

        self._running = False

    def restart(self):
        """Stop then start the service. Blocking call"""
        self.stop()
        self.start()

    @property
    def status(self):
        """A string with information about the service"""
        print(''.join(['Synchronizer status: Running: ', str(self._running)]))

    @property
    def running(self):
        """Returns True if the service is running, False otherwise"""
        return self._running

    def _sync_loop(self):
        #print('SYNCHRONIZER: Running')

        t1 = time.time()
        while not self._stop_requested:
            t2 = time.time()
            """Should we sync or just keep checking the stop condition?"""
            if t2 - t1 < 10:
                time.sleep(0.01)  # Don't busy wait
                continue

            #print("SYNCHRONIZER: Time for a sync")

            # Should use the discoverer here...
            host = "localhost"
            port = 1337

            with Client(host, port, self._db) as client:
                client.execute_transaction()

            t1 = time.time()

    def start(self):
        """Start the service. Block until the service is running."""
        print('SYNCHRONIZER: Starting')
        self._stop_requested = False
        self._thread = Thread(target=self._sync_loop)
        self._thread.start()
        self._running = True

        self._discoverer.start()

    def stop(self):
        """Stop the service. Block until the service is running."""

        self._stop_requested = True
        print('SYNCHRONIZER: Stopping')
        self._thread.join(0.1)
        if self._thread.is_alive():
            raise Exception  # Timeout

        self._discoverer.stop()
        self._running = False

    def restart(self):
        """Stop then start the service. Blocking call"""
        self.stop()
        self.start()

    @property
    def status(self):
        """A string with information about the service"""
        print(''.join(['Synchronizer status: Running: ', str(self._running)]))

    @property
    def running(self):
        """Returns True if the service is running, False otherwise"""
        return self._running

    def _sync_loop(self):
        print('SYNCHRONIZER: Running')

        t1 = time.time()
        while not self._stop_requested:
            t2 = time.time()
            """Should we sync or just keep checking the stop condition?"""
            if t2 - t1 < 10:
                time.sleep(0.01)  # Don't busy wait
                continue

            # Should use the discoverer here...

            info_dict = self._discoverer.get_results()
            """
            with Client(host, port, self._db) as client:
                client.execute_transaction()
            """
            t1 = time.time()