Example #1
0
  private IStatus rebuildIndexCompletely(SubMonitor monitor)
      throws CorruptIndexException, LockObtainFailedException, IOException, CoreException {

    MultiStatus multiStatus = new MultiStatus(TasksIndexCore.ID_PLUGIN, 0, null, null);

    // get indexable tasks from the task list
    final TaskListState taskListState = new TaskListState();
    taskList.run(taskListState, monitor.newChild(0));

    monitor.beginTask(
        Messages.TaskListIndex_task_rebuilding_index, taskListState.indexableTasks.size());
    try {
      IndexWriter writer;
      try {
        writer = createIndexWriter(true);
      } catch (CorruptIndexException e) {
        if (directory instanceof FSDirectory) {
          cleanDirectory(((FSDirectory) directory).getFile());
          writer = createIndexWriter(true);
        } else {
          throw e;
        }
      }
      try {

        for (ITask task : taskListState.indexableTasks) {
          if (taskIsIndexable(task, null)) {
            try {
              TaskData taskData = dataManager.getTaskData(task);
              add(writer, task, taskData);
            } catch (CoreException e) {
              // an individual task data error should not prevent the index from updating
              multiStatus.add(e.getStatus());
            }
          }
          monitor.worked(1);
        }
        synchronized (this) {
          rebuildIndex = false;
        }
      } finally {
        writer.close();
      }
    } finally {
      monitor.done();
    }
    return multiStatus;
  }
Example #2
0
  private void initialize() {
    if (!rebuildIndex) {
      IndexReader indexReader = null;
      try {
        indexReader = getIndexReader();
      } catch (Exception e) {
        // ignore, this can happen if the index is corrupt
      }
      if (indexReader == null) {
        rebuildIndex = true;
      }
    }
    maintainIndexJob = new MaintainIndexJob();
    dataManager.addListener(this);
    taskList.addChangeListener(this);
    repositoryManager.addListener(this);

    scheduleIndexMaintenance(MaintainIndexType.STARTUP);
  }
Example #3
0
  public void close() {
    dataManager.removeListener(this);
    taskList.removeChangeListener(this);
    repositoryManager.removeListener(this);

    maintainIndexJob.cancel();
    try {
      maintainIndexJob.join();
    } catch (InterruptedException e) {
      // ignore
    }

    Lock writeLock = indexReaderLock.writeLock();
    writeLock.lock();
    try {
      synchronized (this) {
        if (indexReader != null) {
          try {
            indexReader.close();
          } catch (IOException e) {
            // ignore
          }
          indexReader = null;
        }
      }
      if (directory != null) {
        try {
          directory.close();
        } catch (IOException e) {
          StatusHandler.log(
              new Status(
                  IStatus.ERROR,
                  TasksIndexCore.ID_PLUGIN,
                  "Cannot close index: " + e.getMessage(),
                  e)); //$NON-NLS-1$
        }
      }
    } finally {
      writeLock.unlock();
    }
  }