@Override
  public ScheduleOptions getOptions(Config config) {
    ScheduleOptions options = scheduler.NOW();
    options.canRunConcurrently(false);
    options.onLeaderOnly(true);
    options.name(config.getWorkspace().getJobName());

    return options;
  }
Exemplo n.º 2
0
  @Activate
  protected final void activate(Map<String, Object> config) throws RepositoryException {
    if (!capabilityHelper.isOak()) {
      log.info("Cowardly refusing to create indexes on non-Oak instance.");
      return;
    }

    final String ensureDefinitionsPath =
        PropertiesUtil.toString(
            config.get(PROP_ENSURE_DEFINITIONS_PATH), DEFAULT_ENSURE_DEFINITIONS_PATH);

    final String oakIndexesPath =
        PropertiesUtil.toString(config.get(PROP_OAK_INDEXES_PATH), DEFAULT_OAK_INDEXES_PATH);

    log.info("Ensuring Oak Indexes [ {} ~> {} ]", ensureDefinitionsPath, oakIndexesPath);

    if (StringUtils.isBlank(ensureDefinitionsPath)) {
      throw new IllegalArgumentException(
          "OSGi Configuration Property `"
              + PROP_ENSURE_DEFINITIONS_PATH
              + "` "
              + "cannot be blank.");
    } else if (StringUtils.isBlank(oakIndexesPath)) {
      throw new IllegalArgumentException(
          "OSGi Configuration Property `" + PROP_OAK_INDEXES_PATH + "` " + "cannot be blank.");
    }

    // Start the indexing process asynchronously, so the activate won't get blocked
    // by rebuilding a synchronous index

    EnsureOakIndexJobHandler sih =
        new EnsureOakIndexJobHandler(this, oakIndexesPath, ensureDefinitionsPath);
    ScheduleOptions options = scheduler.NOW();
    String name =
        String.format(
            "Ensure index %s => %s", new Object[] {oakIndexesPath, ensureDefinitionsPath});
    options.name(name);
    options.canRunConcurrently(false);
    scheduler.schedule(sih, options);
    log.info("Job scheduled to update the index");
  }