public void read(
     final long position,
     final long size,
     final ByteBuffer directByteBuffer,
     final AIOCallback aioPackage)
     throws HornetQException {
   checkOpened();
   if (poller == null) {
     startPoller();
   }
   pendingWrites.countUp();
   maxIOSemaphore.acquireUninterruptibly();
   try {
     read(handler, position, size, directByteBuffer, aioPackage);
   } catch (HornetQException e) {
     // Release only if an exception happened
     maxIOSemaphore.release();
     pendingWrites.countDown();
     throw e;
   } catch (RuntimeException e) {
     // Release only if an exception happened
     maxIOSemaphore.release();
     pendingWrites.countDown();
     throw e;
   }
 }
  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();
    }
  }
  public void write(
      final long position,
      final long size,
      final ByteBuffer directByteBuffer,
      final AIOCallback aioCallback) {
    if (aioCallback == null) {
      throw new NullPointerException("Null Callback");
    }

    checkOpened();
    if (poller == null) {
      startPoller();
    }

    pendingWrites.countUp();

    if (writeExecutor != null) {
      maxIOSemaphore.acquireUninterruptibly();

      writeExecutor.execute(
          new Runnable() {
            public void run() {
              long sequence = nextWritingSequence.getAndIncrement();

              try {
                write(handler, sequence, position, size, directByteBuffer, aioCallback);
              } catch (HornetQException e) {
                callbackError(
                    aioCallback, sequence, directByteBuffer, e.getType().getCode(), e.getMessage());
              } catch (RuntimeException e) {
                callbackError(
                    aioCallback,
                    sequence,
                    directByteBuffer,
                    HornetQExceptionType.INTERNAL_ERROR.getCode(),
                    e.getMessage());
              }
            }
          });
    } else {
      maxIOSemaphore.acquireUninterruptibly();

      long sequence = nextWritingSequence.getAndIncrement();

      try {
        write(handler, sequence, position, size, directByteBuffer, aioCallback);
      } catch (HornetQException e) {
        callbackError(
            aioCallback, sequence, directByteBuffer, e.getType().getCode(), e.getMessage());
      } catch (RuntimeException e) {
        callbackError(
            aioCallback,
            sequence,
            directByteBuffer,
            HornetQExceptionType.INTERNAL_ERROR.getCode(),
            e.getMessage());
      }
    }
  }
 public void fill(final long position, final int blocks, final long size, final byte fillChar)
     throws HornetQException {
   checkOpened();
   AsynchronousFileImpl.fill(handler, position, blocks, size, fillChar);
 }
 public long size() throws HornetQException {
   checkOpened();
   return size0(handler);
 }