public void close() throws Exception {
    checkOpened();

    writeLock.lock();

    try {

      while (!pendingWrites.await(60000)) {
        HornetQJournalLogger.LOGGER.couldNotGetLock(fileName);
      }

      while (!maxIOSemaphore.tryAcquire(maxIO, 60, TimeUnit.SECONDS)) {
        HornetQJournalLogger.LOGGER.couldNotGetLock(fileName);
      }

      maxIOSemaphore = null;
      if (poller != null) {
        stopPoller();
      }

      if (handler != null) {
        AsynchronousFileImpl.closeInternal(handler);
        AsynchronousFileImpl.addMax(-maxIO);
      }
      opened = false;
      handler = null;
    } finally {
      writeLock.unlock();
    }
  }