package profiles;


/**
 * Gestore di una tabella di routing. Si occupa di aggiornare periodicamente la
 * tabella.
 *
 * @author Lorenzo Moretti
 * @version 1.0
 */
public class RoutingManager extends Thread {
  long updateFrequency = 50000;
  boolean keepUpdating = true;
  RoutingTable routingTable;
  BasicService basicService;

  public RoutingManager(RoutingTable rt, BasicService bs) {
    routingTable = rt;
    basicService = bs;
  }

  public void run() {
    keepUpdating = true;

    while (keepUpdating) {

      // Aggiorna la tabella di routing
      routingTable.update(basicService);

      try {
        sleep(updateFrequency);
      }
      catch (InterruptedException ex) {
        ex.printStackTrace();
      }
    }

  }

  public void setUpdateFrequency(long uf) {
    updateFrequency = uf;
  }

  public long getUpdateFrequency() {
    return updateFrequency;
  }

  public void stopUpdating() {
    keepUpdating = false;
  }
}