private boolean initializeDataSource(DataSourceVO<?> vo) {
    synchronized (runningDataSources) {
      // If the data source is already running, just quit.
      if (isDataSourceRunning(vo.getId())) return false;

      // Ensure that the data source is enabled.
      Assert.isTrue(vo.isEnabled());

      // Create and initialize the runtime version of the data source.
      DataSourceRT dataSource = vo.createDataSourceRT();
      dataSource.initialize();

      // Add it to the list of running data sources.
      runningDataSources.add(dataSource);

      // Add the enabled points to the data source.
      List<DataPointVO> dataSourcePoints = new DataPointDao().getDataPoints(vo.getId(), null);
      for (DataPointVO dataPoint : dataSourcePoints) {
        if (dataPoint.isEnabled()) startDataPoint(dataPoint);
      }

      LOG.info("Data source '" + vo.getName() + "' initialized");

      return true;
    }
  }
  public void saveDataSource(DataSourceVO<?> vo) {
    // If the data source is running, stop it.
    stopDataSource(vo.getId());

    // In case this is a new data source, we need to save to the database first so that it has a
    // proper id.
    new DataSourceDao().saveDataSource(vo);

    // If the data source is enabled, start it.
    if (vo.isEnabled()) {
      if (initializeDataSource(vo)) startDataSourcePolling(vo);
    }
  }
  //
  // Lifecycle
  public synchronized void initialize(boolean safe) {
    if (started) throw new ShouldNeverHappenException("RuntimeManager already started");

    // Set the started indicator to true.
    started = true;

    // Get the RTM defs from modules
    List<RuntimeManagerDefinition> defs =
        ModuleRegistry.getDefinitions(RuntimeManagerDefinition.class);
    Collections.sort(
        defs,
        new Comparator<RuntimeManagerDefinition>() {
          @Override
          public int compare(RuntimeManagerDefinition def1, RuntimeManagerDefinition def2) {
            return def1.getInitializationPriority() - def2.getInitializationPriority();
          }
        });

    // Start everything with priority up to and including 4.
    int rtmdIndex = startRTMDefs(defs, safe, 0, 4);

    // Initialize data sources that are enabled. Start by organizing all enabled data sources by
    // start priority.
    DataSourceDao dataSourceDao = new DataSourceDao();
    List<DataSourceVO<?>> configs = dataSourceDao.getDataSources();
    Map<DataSourceDefinition.StartPriority, List<DataSourceVO<?>>> priorityMap =
        new HashMap<DataSourceDefinition.StartPriority, List<DataSourceVO<?>>>();
    for (DataSourceVO<?> config : configs) {
      if (config.isEnabled()) {
        if (safe) {
          config.setEnabled(false);
          dataSourceDao.saveDataSource(config);
        } else if (config.getDefinition() != null) {
          List<DataSourceVO<?>> priorityList =
              priorityMap.get(config.getDefinition().getStartPriority());
          if (priorityList == null) {
            priorityList = new ArrayList<DataSourceVO<?>>();
            priorityMap.put(config.getDefinition().getStartPriority(), priorityList);
          }
          priorityList.add(config);
        }
      }
    }

    // Initialize the prioritized data sources. Start the polling later.
    List<DataSourceVO<?>> pollingRound = new ArrayList<DataSourceVO<?>>();
    for (DataSourceDefinition.StartPriority startPriority :
        DataSourceDefinition.StartPriority.values()) {
      List<DataSourceVO<?>> priorityList = priorityMap.get(startPriority);
      if (priorityList != null) {
        for (DataSourceVO<?> config : priorityList) {
          if (initializeDataSource(config)) pollingRound.add(config);
        }
      }
    }

    // Tell the data sources to start polling. Delaying the polling start gives the data points a
    // chance to
    // initialize such that point listeners in meta points and set point handlers can run properly.
    for (DataSourceVO<?> config : pollingRound) startDataSourcePolling(config);

    // Run everything else.
    rtmdIndex = startRTMDefs(defs, safe, rtmdIndex, Integer.MAX_VALUE);

    // Start the publishers that are enabled
    PublisherDao publisherDao = new PublisherDao();
    List<PublisherVO<? extends PublishedPointVO>> publishers = publisherDao.getPublishers();
    for (PublisherVO<? extends PublishedPointVO> vo : publishers) {
      if (vo.isEnabled()) {
        if (safe) {
          vo.setEnabled(false);
          publisherDao.savePublisher(vo);
        } else startPublisher(vo);
      }
    }

    // Schedule the Backup Task if necessary
    // No way to set the default value for Bools in SystemSettingsDao so must do here
    if (SystemSettingsDao.getBooleanValue(SystemSettingsDao.BACKUP_ENABLED, true)) {
      BackupWorkItem.schedule();
    }
  }