@Override protected boolean removeEldestEntry(Map.Entry<T, VanillaMappedBytes> eldest) { boolean removed = size() >= maximumCacheSize; if (removed && releaseOnRemove) { eldest.getValue().release(); } return removed; } },
@Override protected boolean removeEldestEntry(Map.Entry<T, VanillaMappedBytes> eldest) { boolean removed = size() >= maximumCacheSize; if (removed && releaseOnRemove) { eldest.getValue().release(); } return removed; } },
@Override public void close() { final Iterator<Map.Entry<T, VanillaMappedBytes>> it = this.cache.entrySet().iterator(); while (it.hasNext()) { Map.Entry<T, VanillaMappedBytes> entry = it.next(); entry.getValue().release(); if (this.cleanOnClose && !entry.getValue().unmapped()) { entry.getValue().cleanup(); entry.getValue().close(); it.remove(); } else if (entry.getValue().unmapped()) { entry.getValue().close(); it.remove(); } } this.cache.clear(); }
private void setDataBuffer(long dataLookup) throws IOException { if (dataBuffer != null) { dataBuffer.release(); } dataBuffer = IndexedChronicle.this.dataFileCache.acquire(dataLookup); dataStartAddr = dataBuffer.address(); }
protected VanillaMappedBytes acquire0(long index) throws IOException { if (this.mb1 != null) { this.mb1.release(); } this.mb1 = this.mb0; this.mb0 = this.mappedFile.bytes(index * this.blockSize, this.blockSize, index); this.mb0.reserve(); bytes.add(this.mb0); for (int i = bytes.size() - 1; i >= 0; i--) { if (bytes.get(i).unmapped()) { bytes.remove(i); } } return this.mb0; }
protected void releaseIndexBytes() { if (indexBytes != null) { if (builder.syncOnRoll()) { indexBytes.force(); } indexBytes.release(); indexBytes = null; } }
@Override public synchronized void close() throws IOException { if (this.mb0 != null && !this.mb0.unmapped()) { this.mb0.release(); this.mb0 = null; } if (this.mb1 != null && !this.mb1.unmapped()) { this.mb1.release(); this.mb1 = null; } for (int i = bytes.size() - 1; i >= 0; i--) { bytes.get(i).cleanup(); } this.bytes.clear(); this.mappedFile.close(); }
private void setIndexBuffer(long index, boolean prefetch) throws IOException { if (indexBuffer != null) { indexBuffer.release(); } indexBuffer = IndexedChronicle.this.indexFileCache.acquire(index); indexPositionAddr = indexStartAddr = indexBuffer.address(); indexStartOffset = index * indexBlockSize; }
protected VanillaMappedBytes acquire0(long index) throws IOException { if (this.mb1 != null) { this.mb1.release(); } this.mb1 = this.mb0; this.mb0 = this.mappedFile.bytes(index * this.blockSize, this.blockSize, index); this.mb0.reserve(); bytes.add(this.mb0); for (int i = bytes.size() - 1; i >= 0; i--) { if (bytes.get(i).unmapped()) { bytes.remove(i); } } return this.mb0; }
private void setDataBuffer(long dataLookup) throws IOException { if (dataBuffer != null) { dataBuffer.release(); } dataBuffer = IndexedChronicle.this.dataFileCache.acquire(dataLookup); dataStartAddr = dataBuffer.address(); }
@Override public void close() { final Iterator<Map.Entry<T,VanillaMappedBytes>> it = this.cache.entrySet().iterator(); while(it.hasNext()) { Map.Entry<T,VanillaMappedBytes> entry = it.next(); entry.getValue().release(); if(this.cleanOnClose && !entry.getValue().unmapped()) { entry.getValue().cleanup(); entry.getValue().close(); it.remove(); } else if(entry.getValue().unmapped()) { entry.getValue().close(); it.remove(); } } this.cache.clear(); }
@Override public synchronized void close() throws IOException { if (this.mb0 != null && !this.mb0.unmapped()) { this.mb0.release(); this.mb0 = null; } if (this.mb1 != null && !this.mb1.unmapped()) { this.mb1.release(); this.mb1 = null; } for (int i = bytes.size() - 1; i >= 0; i--) { bytes.get(i).cleanup(); } this.bytes.clear(); this.mappedFile.close(); } }
protected void releaseDataBytes() { if (dataBytes != null) { if (builder.syncOnRoll()) { dataBytes.force(); } dataBytes.release(); dataBytes = null; } } }
private void setIndexBuffer(long index, boolean prefetch) throws IOException { if (indexBuffer != null) { indexBuffer.release(); } indexBuffer = IndexedChronicle.this.indexFileCache.acquire(index); indexPositionAddr = indexStartAddr = indexBuffer.address(); indexStartOffset = index * indexBlockSize; }
public VanillaMappedBytes append(int cycle, long indexValue, boolean synchronous, long[] position) throws IOException { for (int indexCount = lastIndexFile(cycle, 0); indexCount < 10000; indexCount++) { VanillaMappedBytes vmb = indexFor(cycle, indexCount, true); long position0 = append(vmb, indexValue, synchronous); if (position0 >= 0) { position[0] = position0; return vmb; } vmb.release(); } throw new AssertionError(); }
public VanillaMappedBytes append( int cycle, long indexValue, boolean synchronous, int lastIndex, long[] position) throws IOException { for (int indexCount = lastIndex; indexCount < 10000; indexCount++) { VanillaMappedBytes vmb = indexFor(cycle, indexCount, true); long position0 = append(vmb, indexValue, synchronous); if (position0 >= 0) { position[0] = position0; return vmb; } vmb.release(); } throw new AssertionError( "Unable to write index" + indexValue + "on cycle " + cycle + "(" + dateCache.valueFor(cycle).text + ")" ); }
/** * This method returns the very last index in the chronicle. Not to be confused with lastWrittenIndex(), * this method returns the actual last index by scanning the underlying data even the appender has not * been activated. * @return The last index in the file */ public long lastIndex() { int cycle = (int) indexCache.lastCycle(); int lastIndexCount = indexCache.lastIndexFile(cycle, -1); if (lastIndexCount >= 0) { try { final VanillaMappedBytes buffer = indexCache.indexFor(cycle, lastIndexCount, false); final long indices = VanillaIndexCache.countIndices(buffer); buffer.release(); final long indexEntryNumber = (indices > 0) ? indices - 1 : 0; return (((long) cycle) << entriesForCycleBits) + (((long) lastIndexCount) << indexBlockLongsBits) + indexEntryNumber; } catch (IOException e) { throw new AssertionError(e); } } else { return -1; } }
/** * This method returns the very last index in the chronicle. Not to be confused with * lastWrittenIndex(), this method returns the actual last index by scanning the underlying data * even the appender has not been activated. * * @return The last index in the file */ @Override public long lastIndex() { int cycle = (int) indexCache.lastCycle(); int lastIndexCount = indexCache.lastIndexFile(cycle, -1); if (lastIndexCount >= 0) { try { final VanillaMappedBytes buffer = indexCache.indexFor(cycle, lastIndexCount, false); if (buffer != null) { final long indices = VanillaIndexCache.countIndices(buffer); buffer.release(); final long indexEntryNumber = (indices > 0) ? indices - 1 : 0; return (((long) cycle) << entriesForCycleBits) + (((long) lastIndexCount) << indexBlockLongsBits) + indexEntryNumber; } else { return -1; } } catch (IOException e) { throw new AssertionError(e); } } else { return -1; } }
if (position < 0) { if (indexBytes != null) { indexBytes.release(); indexBytes = null;