/** * Method that will try to create a {@link StreamyMemBuffer} with configured allocator, * using specified arguments. * If construction fails (due to allocation limits), * null will be returned. */ @SuppressWarnings("resource") public final SB tryCreateStreamyBuffer(int minSegmentsForBuffer, int maxSegmentsForBuffer) { S initialSegments = _segmentAllocator.allocateSegments(minSegmentsForBuffer, null); // may not be able to allocate segments; if so, need to fail if (initialSegments == null) { return null; } SB buffer = _createStreamyBuffer(minSegmentsForBuffer, maxSegmentsForBuffer, initialSegments); if (_streamyDecorator != null) { buffer = _streamyDecorator.decorateMemBuffer(buffer); } return buffer; }
@Override // from Closeable -- note, does NOT throw IOException public synchronized final void close() { // first do regular cleanup clear(); // then free the head/tail node as well _usedSegmentsCount = 0; // 24-Apr-2013, tatu: As per #16, must ensure proper cleaning if (_head != null) { _head.markFree(); _segmentAllocator.releaseSegment(_head); _head = _tail = null; } // and any locally recycled buffers as well S seg = _firstFreeSegment; _firstFreeSegment = null; _freeSegmentCount = 0; while (seg != null) { S next = seg.getNext(); _segmentAllocator.releaseSegment(seg); seg = next; } // one more thing: wake up thread(s) that are blocked (if any) this.notifyAll(); }
protected MemBufferBase(SegmentAllocator<S> allocator, int minSegmentsToAllocate, int maxSegmentsToAllocate, S initialSegments) { _segmentAllocator = allocator; _segmentSize = allocator.getSegmentSize(); _maxSegmentsForReuse = minSegmentsToAllocate; _maxSegmentsToAllocate = maxSegmentsToAllocate; // all but one of segments goes to the free list _firstFreeSegment = initialSegments.getNext(); // and first one is used as both head and tail initialSegments.relink(null); _head = _tail = initialSegments; // also, better initialize initial segment for writing and reading _head.initForWriting(); _head.initForReading(); _usedSegmentsCount = 1; // Sanity checks? if yes, uncomment this... /* int count = count(_firstFreeSegment); if (count != _freeSegmentCount) { throw new IllegalStateException("Bad initial _freeSegmentCount ("+_freeSegmentCount+"): but only got "+count+" linked"); } */ _freeSegmentCount = minSegmentsToAllocate-1; }
protected MemBufferBase(SegmentAllocator<S> allocator, int minSegmentsToAllocate, int maxSegmentsToAllocate, S initialSegments) { _segmentAllocator = allocator; _segmentSize = allocator.getSegmentSize(); _maxSegmentsForReuse = minSegmentsToAllocate; _maxSegmentsToAllocate = maxSegmentsToAllocate; // all but one of segments goes to the free list _firstFreeSegment = initialSegments.getNext(); // and first one is used as both head and tail initialSegments.relink(null); _head = _tail = initialSegments; // also, better initialize initial segment for writing and reading _head.initForWriting(); _head.initForReading(); _usedSegmentsCount = 1; // Sanity checks? if yes, uncomment this... /* int count = count(_firstFreeSegment); if (count != _freeSegmentCount) { throw new IllegalStateException("Bad initial _freeSegmentCount ("+_freeSegmentCount+"): but only got "+count+" linked"); } */ _freeSegmentCount = minSegmentsToAllocate-1; }
/** * Method that will try to create a {@link ChunkyMemBuffer} with configured allocator, * using specified arguments. * If construction fails (due to allocation limits), * null will be returned. */ @SuppressWarnings("resource") public final CB tryCreateChunkyBuffer(int minSegmentsForBuffer, int maxSegmentsForBuffer) { S initialSegments = _segmentAllocator.allocateSegments(minSegmentsForBuffer, null); // may not be able to allocate segments; if so, need to fail if (initialSegments == null) { return null; } CB buffer = _createChunkyBuffer(minSegmentsForBuffer, maxSegmentsForBuffer, initialSegments); // Need to decorate it? if (_chunkyDecorator != null) { buffer = _chunkyDecorator.decorateMemBuffer(buffer); } return buffer; }
@Override // from Closeable -- note, does NOT throw IOException public synchronized final void close() { // first do regular cleanup clear(); // then free the head/tail node as well _usedSegmentsCount = 0; // 24-Apr-2013, tatu: As per #16, must ensure proper cleaning if (_head != null) { _head.markFree(); _segmentAllocator.releaseSegment(_head); _head = _tail = null; } // and any locally recycled buffers as well S seg = _firstFreeSegment; _firstFreeSegment = null; _freeSegmentCount = 0; while (seg != null) { S next = seg.getNext(); _segmentAllocator.releaseSegment(seg); seg = next; } // one more thing: wake up thread(s) that are blocked (if any) this.notifyAll(); }
/** * Method that will try to create a {@link StreamyMemBuffer} with configured allocator, * using specified arguments. * If construction fails (due to allocation limits), * null will be returned. */ @SuppressWarnings("resource") public final SB tryCreateStreamyBuffer(int minSegmentsForBuffer, int maxSegmentsForBuffer) { S initialSegments = _segmentAllocator.allocateSegments(minSegmentsForBuffer, null); // may not be able to allocate segments; if so, need to fail if (initialSegments == null) { return null; } SB buffer = _createStreamyBuffer(minSegmentsForBuffer, maxSegmentsForBuffer, initialSegments); if (_streamyDecorator != null) { buffer = _streamyDecorator.decorateMemBuffer(buffer); } return buffer; }
_segmentAllocator.releaseSegment(old);
/** * Method that will try to create a {@link ChunkyMemBuffer} with configured allocator, * using specified arguments. * If construction fails (due to allocation limits), * null will be returned. */ @SuppressWarnings("resource") public final CB tryCreateChunkyBuffer(int minSegmentsForBuffer, int maxSegmentsForBuffer) { S initialSegments = _segmentAllocator.allocateSegments(minSegmentsForBuffer, null); // may not be able to allocate segments; if so, need to fail if (initialSegments == null) { return null; } CB buffer = _createChunkyBuffer(minSegmentsForBuffer, maxSegmentsForBuffer, initialSegments); // Need to decorate it? if (_chunkyDecorator != null) { buffer = _chunkyDecorator.decorateMemBuffer(buffer); } return buffer; }
_segmentAllocator.releaseSegment(old);
BytesSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment); if (newFree == null) { return false;
LongsSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment); if (newFree == null) { return false;
BytesSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment); if (newFree == null) { return false;
LongsSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment); if (newFree == null) { return false;
LongsSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment); if (newFree == null) { return false;
LongsSegment newFree = _segmentAllocator.allocateSegments(segmentsToAlloc, _firstFreeSegment); if (newFree == null) { return false;
LongsSegment newFree = _segmentAllocator.allocateSegments(1, _firstFreeSegment); if (newFree == null) { return false;
BytesSegment newFree = _segmentAllocator.allocateSegments(1, _firstFreeSegment); if (newFree == null) { return false;
LongsSegment newFree = _segmentAllocator.allocateSegments(1, _firstFreeSegment); if (newFree == null) { return false;
BytesSegment newFree = _segmentAllocator.allocateSegments(1, _firstFreeSegment); if (newFree == null) { return false;