Пример #1
0
  public void close() throws IOException {
    flush();

    if (!commitExecutor.isShutdown()) {
      commitExecutor.shutdown();
      try {
        if (!commitExecutor.awaitTermination(5, TimeUnit.MINUTES))
          throw new OException("Background data flush task can not be stopped.");
      } catch (InterruptedException e) {
        OLogManager.instance().error(this, "Data flush thread was interrupted");

        Thread.interrupted();
        throw new OException("Data flush thread was interrupted", e);
      }
    }

    synchronized (syncObject) {
      for (OFileClassic fileClassic : files.values()) {
        if (fileClassic.isOpen()) fileClassic.close();
      }

      if (nameIdMapHolder != null) {
        nameIdMapHolder.setLength(0);
        for (Map.Entry<String, Long> entry : nameIdMap.entrySet()) {
          writeNameIdEntry(new NameFileIdEntry(entry.getKey(), entry.getValue()), false);
        }
        nameIdMapHolder.getFD().sync();
        nameIdMapHolder.close();
      }
    }
  }
Пример #2
0
  public boolean isOpen(long fileId) {
    synchronized (syncObject) {
      OFileClassic fileClassic = files.get(fileId);
      if (fileClassic != null) return fileClassic.isOpen();

      return false;
    }
  }
Пример #3
0
  public long isOpen(String fileName) throws IOException {
    synchronized (syncObject) {
      initNameIdMapping();

      final Long fileId = nameIdMap.get(fileName);
      if (fileId == null) return -1;

      final OFileClassic fileClassic = files.get(fileId);
      if (fileClassic == null || !fileClassic.isOpen()) return -1;

      return fileId;
    }
  }
Пример #4
0
 public void setSoftlyClosed(long fileId, boolean softlyClosed) throws IOException {
   synchronized (syncObject) {
     OFileClassic fileClassic = files.get(fileId);
     if (fileClassic != null && fileClassic.isOpen()) fileClassic.setSoftlyClosed(softlyClosed);
   }
 }
Пример #5
0
 private void openFile(OFileClassic fileClassic) throws IOException {
   if (fileClassic.exists()) {
     if (!fileClassic.isOpen()) fileClassic.open();
   } else fileClassic.create(-1);
 }