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();
    }
  }
 /**
  * @throws HornetQException
  * @throws InterruptedException
  */
 private void stopPoller() throws HornetQException, InterruptedException {
   AsynchronousFileImpl.stopPoller(handler);
   // We need to make sure we won't call close until Poller is
   // completely done, or we might get beautiful GPFs
   pollerLatch.await();
 }