Package org.eclipse.orion.server.core.resources

Examples of org.eclipse.orion.server.core.resources.FileLocker


    if (metaStore == null) {
      logger.error("Search indexer cannot find a metastore service"); //$NON-NLS-1$
      return Status.OK_STATUS;
    }
    long start = System.currentTimeMillis();
    FileLocker lock = new FileLocker(lockFile);
    int indexed = 0, userCount = 0, activeUserCount = 0;
    try {
      if (!lock.tryLock()) {
        if (logger.isInfoEnabled()) {
          logger.info("Search indexer: another process is currently indexing"); //$NON-NLS-1$
        }
        schedule(IDLE_DELAY);
        return Status.OK_STATUS;
      }
      List<String> userIds = metaStore.readAllUsers();
      userCount = userIds.size();
      SubMonitor progress = SubMonitor.convert(monitor, userIds.size());
      List<SolrInputDocument> documents = new ArrayList<SolrInputDocument>();
      indexed = 0;
      for (String userId : userIds) {
        UserInfo userInfo = metaStore.readUser(userId);
        if (isActiveUser(userInfo)) {
          activeUserCount++;
          indexed += indexUser(userInfo, progress.newChild(1), documents);
        }
      }
    } catch (CoreException e) {
      handleIndexingFailure(e, null);
    } catch (FileNotFoundException e) {
      // We shouldn't get here
      handleIndexingFailure(e, null);
    } catch (IOException e) {
      // We shouldn't get here
      handleIndexingFailure(e, null);
    } finally {
      if (lock.isValid()) {
        lock.release();
      }
    }
    long duration = System.currentTimeMillis() - start;
    if (logger.isInfoEnabled()) {
      String activity = " (" + activeUserCount + '/' + userCount + " users active)"; //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here


  protected IStatus run(IProgressMonitor monitor) {
    Logger logger = LoggerFactory.getLogger(Indexer.class);
    if (logger.isDebugEnabled())
      logger.debug("Purging indexes"); //$NON-NLS-1$
    long start = System.currentTimeMillis();
    FileLocker lock = new FileLocker(lockFile);
    SolrQuery query = findAllQuery();
    try {
      if (!lock.tryLock()) {
        if (logger.isInfoEnabled()) {
          logger.info("Search index purge: another process is currently running");
        }
        schedule(DEFAULT_DELAY * 2);
        return Status.OK_STATUS;
      }
      QueryResponse solrResponse = this.server.query(query);
      SolrDocumentList result = solrResponse.getResults();
      long numFound = result.getNumFound();
      long processed = 0;
      List<String> listIds = new ArrayList<String>();
      if (numFound > processed) {
        while (true) {
          checkCanceled(monitor);
          markStaleIndexes(result, listIds);
          processed += PAGE_SIZE;
          if (processed >= numFound)
            break;
          query.setParam(CommonParams.START, Long.toString(processed));
          solrResponse = this.server.query(query);
          result = solrResponse.getResults();
          // New indexes may have been added, perhaps
          numFound = result.getNumFound();
        }
      }

      checkCanceled(monitor);
      if (listIds.size() > 0) {
        this.server.deleteById(listIds);
        this.server.commit();
      }
      if (logger.isDebugEnabled())
        logger.debug("\tPurged: " + listIds.size()); //$NON-NLS-1$
    } catch (OperationCanceledException e) {
      //ignore and fall through
    } catch (Exception e) {
      handleIndexingFailure(e);
    } finally {
      if (lock.isValid()) {
        lock.release();
      }
    }
    long duration = System.currentTimeMillis() - start;
    if (logger.isDebugEnabled())
      logger.debug("Purge job took " + duration + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here

      }
      if (!parent.isDirectory()) {
        throw new RuntimeException("Meta File Error, parent is not a folder");
      }
      File newFile = retrieveMetaFile(parent, name);
      FileLocker locker = new FileLocker(newFile);
      try {
        locker.lock();
      } catch (IOException e) {
        Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
        logger.error("Meta File Error, file IO error, could not lock the file", e); //$NON-NLS-1$
        throw new RuntimeException("Meta File Error, file IO error, could not lock the file", e);
      }
      try {
        FileOutputStream fileOutputStream = new FileOutputStream(newFile);
        Charset utf8 = Charset.forName("UTF-8");
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, utf8);
        outputStreamWriter.write(jsonObject.toString(4));
        outputStreamWriter.write("\n");
        outputStreamWriter.flush();
        outputStreamWriter.close();
        fileOutputStream.close();
      } finally {
        locker.release();
      }
    } catch (FileNotFoundException e) {
      Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
      logger.error("Meta File Error, cannot create file under " + parent.toString() + ": invalid file name: " + name); //$NON-NLS-1$
      return false;
View Full Code Here

  public static boolean deleteMetaFile(File parent, String name) {
    if (!isMetaFile(parent, name)) {
      throw new RuntimeException("Meta File Error, cannot delete, does not exist.");
    }
    File savedFile = retrieveMetaFile(parent, name);
    FileLocker locker = new FileLocker(savedFile);
    try {
      locker.lock();
      if (!savedFile.delete()) {
        throw new RuntimeException("Meta File Error, cannot delete file.");
      }
    } catch (IOException e) {
      throw new RuntimeException("Meta File Error, cannot delete file.", e);
    } finally {
      locker.release();
    }
    return true;
  }
View Full Code Here

      if (!isMetaFile(parent, name)) {
        return null;
      }
      File savedFile = retrieveMetaFile(parent, name);
      char[] chars = new char[(int) savedFile.length()];
      FileLocker locker = new FileLocker(savedFile);
      locker.lock();
      try {
        FileInputStream fileInputStream = new FileInputStream(savedFile);
        Charset utf8 = Charset.forName("UTF-8");
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, utf8);
        inputStreamReader.read(chars);
        inputStreamReader.close();
        fileInputStream.close();
      } finally {
        locker.release();
      }
      jsonObject = new JSONObject(new String(chars));
    } catch (FileNotFoundException e) {
      throw new RuntimeException("Meta File Error, file not found", e);
    } catch (IOException e) {
View Full Code Here

    try {
      if (!isMetaFile(parent, name)) {
        throw new RuntimeException("Meta File Error, cannot update, does not exist.");
      }
      File savedFile = retrieveMetaFile(parent, name);
      FileLocker locker = new FileLocker(savedFile);
      locker.lock();
      try {
        FileOutputStream fileOutputStream = new FileOutputStream(savedFile);
        Charset utf8 = Charset.forName("UTF-8");
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, utf8);
        outputStreamWriter.write(jsonObject.toString(4));
        outputStreamWriter.write("\n");
        outputStreamWriter.flush();
        outputStreamWriter.close();
        fileOutputStream.close();
      } finally {
        locker.release();
      }
    } catch (FileNotFoundException e) {
      throw new RuntimeException("Meta File Error, file not found", e);
    } catch (IOException e) {
      Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.resources.FileLocker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.