/** * gets the refCount a given index, or returns 0, if the there is no mapping for this index * * @param index * @return the mapping at this {@code index} * @throws IndexOutOfBoundsException if the index is out of range */ public int getRefCount(long index) { try { for (MappedMemory m : maps) { if (m.index() == index) return m.refCount(); } } catch (Exception e) { return 0; } return 0; }
/** * gets the refCount a given index, or returns 0, if the there is no mapping for this index * * @param index * @return the mapping at this {@code index} * @throws IndexOutOfBoundsException if the index is out of range */ public int getRefCount(long index) { try { for (MappedMemory m : maps) { if (m.index() == index) return m.refCount(); } } catch (Exception e) { return 0; } return 0; }
private synchronized MappedMemory acquire0(long index) throws IOException { if (map1 != null) map1.release(); map1 = map0; map0 = new MappedMemory(fileChannel.map(FileChannel.MapMode.READ_WRITE, index * blockSize, blockSize + overlapSize), index); map0.reserve(); maps.add(map0); // clean up duds. for (int i = maps.size() - 1; i >= 0; i--) { if (maps.get(i).refCount() <= 0) maps.remove(i); } return map0; }
private synchronized MappedMemory acquire0(long index) throws IOException { if (map1 != null) map1.release(); map1 = map0; map0 = new MappedMemory(fileChannel.map(FileChannel.MapMode.READ_WRITE, index * blockSize, blockSize + overlapSize), index); map0.reserve(); maps.add(map0); // clean up duds. for (int i = maps.size() - 1; i >= 0; i--) { if (maps.get(i).refCount() <= 0) maps.remove(i); } return map0; }
public synchronized void close() throws IOException { if (map1 != null) { map1.release(); map1 = null; } if (map0 != null) { map0.release(); map0 = null; } // clean up errant maps. int count = 0; for (int i = maps.size() - 1; i >= 0; i--) { if (maps.get(i).refCount() <= 0) { maps.get(i).close(); count++; } } if (count > 1) { LoggerFactory.getLogger(MappedFile.class).info("{} memory mappings left unreleased, num= {}", filename, count); } maps.clear(); fileChannel.close(); }
public synchronized void close() throws IOException { if (map1 != null) { map1.release(); map1 = null; } if (map0 != null) { map0.release(); map0 = null; } // clean up errant maps. int count = 0; for (int i = maps.size() - 1; i >= 0; i--) { if (maps.get(i).refCount() <= 0) { maps.get(i).close(); count++; } } if (count > 1) { LoggerFactory.getLogger(MappedFile.class).info("{} memory mappings left unreleased, num= {}", filename, count); } maps.clear(); fileChannel.close(); }