コード例 #1
0
  @DwrPermission(admin = true)
  public ProcessResult togglePublisher(int publisherId) {
    ProcessResult response = new ProcessResult();

    PublisherVO<? extends PublishedPointVO> publisher =
        Common.runtimeManager.getPublisher(publisherId);

    publisher.setEnabled(!publisher.isEnabled());
    Common.runtimeManager.savePublisher(publisher);

    response.addData("enabled", publisher.isEnabled());
    response.addData("id", publisherId);

    return response;
  }
コード例 #2
0
  public void savePublisher(PublisherVO<? extends PublishedPointVO> vo) {
    // If the data source is running, stop it.
    stopPublisher(vo.getId());

    // In case this is a new publisher, we need to save to the database first so that it has a
    // proper id.
    new PublisherDao().savePublisher(vo);

    // If the publisher is enabled, start it.
    if (vo.isEnabled()) startPublisher(vo);
  }
コード例 #3
0
  private void startPublisher(PublisherVO<? extends PublishedPointVO> vo) {
    synchronized (runningPublishers) {
      // If the publisher is already running, just quit.
      if (isPublisherRunning(vo.getId())) return;

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

      // Create and start the runtime version of the publisher.
      PublisherRT<?> publisher = vo.createPublisherRT();
      publisher.initialize();

      // Add it to the list of running publishers.
      runningPublishers.add(publisher);
    }
  }
コード例 #4
0
  //
  // 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();
    }
  }