Examples of ByteBufferNode


Examples of com.alibaba.rocketmq.research.rpc.LinkedByteBufferList.ByteBufferNode

            while (!this.isStoped()) {
                try {
                    this.selector.select(1000);
                    int writeSizeZeroTimes = 0;
                    while (true) {
                        ByteBufferNode node = Connection.this.linkeByteBufferList.waitForPut(100);
                        if (node != null) {
                            node.getByteBufferRead().limit(node.getWriteOffset().get());
                            int writeSize = this.socketChannel.write(node.getByteBufferRead());
                            if (writeSize > 0) {
                            }
                            else if (writeSize == 0) {
                                if (++writeSizeZeroTimes >= 3) {
                                    break;
View Full Code Here

Examples of net.sf.joafip.file.entity.ByteBufferNode

  }

  @Override
  public void closeImpl() throws FileIOException {
    try {
      ByteBufferNode current = first;
      while (current != null) {
        final ByteBuffer byteBuffer = current.getByteBuffer();
        // if (!current.close()) {
        // throw new FileIOErrorException(CLOSED + current.getIndex(),
        // file, current.getCloseTrace());
        // }
        unMap(byteBuffer, current.getIndex(), current.isToBeWrote());
        current = current.getNext();
      }
      byteBufferCacheMap.clear();
      first = null;// NOPMD
      last = null;// NOPMD
      fileChannel.truncate(fileContentSize);
View Full Code Here

Examples of net.sf.joafip.file.entity.ByteBufferNode

    currentPositionInFile = positionInFile;
  }

  @Override
  public void flushImpl() throws FileIOException {
    ByteBufferNode current = first;
    while (current != null) {
      final ByteBuffer byteBuffer = current.getByteBuffer();
      if (byteBuffer.isDirect()) {
        ((MappedByteBuffer) byteBuffer).force();
      } else {
        final long index = current.getIndex();
        writeByteBuffer(byteBuffer, index);
        byteBufferCacheMap.remove(index);
        remove(current);
      }
      current = current.getNext();
    }
  }
View Full Code Here

Examples of net.sf.joafip.file.entity.ByteBufferNode

    }
  }

  private void unMapIfMapped(final long size) throws FileIOErrorException {
    long index = (size >> bitsForBufferSize) + 1;
    ByteBufferNode byteBufferNode = byteBufferCacheMap.remove(index);
    while (byteBufferNode != null) {
      remove(byteBufferNode);
      final ByteBuffer byteBuffer = byteBufferNode.getByteBuffer();
      // if (!byteBufferNode.close()) {
      // throw new FileIOErrorException(CLOSED
      // + byteBufferNode.getIndex(), file,
      // byteBufferNode.getCloseTrace());
      // }
      unMap(byteBuffer, index, byteBufferNode.isToBeWrote());
      index++;
      byteBufferNode = byteBufferCacheMap.remove(index);
    }
  }
View Full Code Here

Examples of net.sf.joafip.file.entity.ByteBufferNode

  private ByteBuffer getMappedByteBuffer(final long index,
      final boolean forWrite) throws FileIOErrorException {
    final long positionInFile = index << bitsForBufferSize;
    final ByteBuffer byteBuffer;
    ByteBufferNode byteBufferNode = byteBufferCacheMap.get(index);
    if (byteBufferNode == null) {
      if (positionInFile >= filePhysicalSize) {
        byteBuffer = ByteBuffer.allocate(bufferSize);
        for (int count = 0; count < bufferSize; count++) {
          byteBuffer.put((byte) 0);
        }
      } else {
        byteBuffer = fileChannelMap(FileChannel.MapMode.READ_WRITE,
            positionInFile, bufferSize);
      }

      byteBufferNode = new ByteBufferNode(byteBuffer, index);
      byteBufferCacheMap.put(index, byteBufferNode);
      add(byteBufferNode);
      if (byteBufferCacheMap.size() > maxNumberOfBuffer) {
        // ASSERTX
        final long indexOfLast = last.getIndex();
        assert index != indexOfLast : "index=" + index + " size="
            + byteBufferCacheMap.size() + " maxNbBuffer="
            + maxNumberOfBuffer;
        final ByteBufferNode removed = byteBufferCacheMap
            .remove(indexOfLast);
        // ASSERTX
        assert removed == last;// NOPMD same instance
        remove(last);
        final ByteBuffer lastMappedByteBuffer = removed.getByteBuffer();
        // if (!removed.close()) {
        // throw new FileIOErrorException(CLOSED + removed.getIndex(),
        // file, removed.getCloseTrace());
        // }
        unMap(lastMappedByteBuffer, indexOfLast, removed.isToBeWrote());
      }

    } else {
      // ASSERTX
      assert byteBufferNode.getIndex() == index;
View Full Code Here

Examples of net.sf.joafip.file.entity.ByteBufferNode

    byteBufferNode.setPrevious(null);
    first = byteBufferNode;
  }

  private void remove(final ByteBufferNode byteBufferNode) {
    final ByteBufferNode previous = byteBufferNode.getPrevious();
    final ByteBufferNode next = byteBufferNode.getNext();
    if (previous == null) {
      first = next;
    } else {
      previous.setNext(next);
    }
    if (next == null) {
      last = previous;
    } else {
      next.setPrevious(previous);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.