/** * Releases all mapped resources for the file, allowing the VM to unmap the file. * No operations are possible after calling this method without first * reinitializing the object. */ public synchronized void unmap() { if (itemToPhaseSeqMap != null) { itemToPhaseSeqMap.unmap(); } if (blockFile != null) { try { releaseHeadBlock(); releaseReallocateBlock(); releaseTailBlock(); } catch (IOException ex) { logger.warn("IOException in unmap()", ex); } blockFile.unmap(); } }
/** * Reads the head block from blockFile. If the current head buffer already * holds the head block then nothing is done. If the head buffer contains a * different block then it is freed first (writing it to the file). This is * similar to {@link #allocateHeadBlock} only it will not allocate a new * block from the file, and always reads the contents of the existing block * in the file. * * @param blockId The block number of the head block. * @throws IOException if an I/O error occurs. */ private void readHeadBlock(int blockId) throws IOException { if (headBlock != null) { if (blockId == (int) headBlock.getBlockId()) { return; } releaseHeadBlock(); } headBlock = findBlock(blockId); if (headBlock == null) { headBlock = blockFile.readBlock(objectPool, blockId); } headBlockDirty = false; }
/** * Allocates a buffer from blockFile to hold the head block. If the current * head buffer already holds the head block then nothing is done. If the head * buffer contains a different block then it is released first (writing the * head block to the file). This method uses a previous version of the * block, unless no block with that ID exists yet, in which case a new block * is read in, or allocated if it does not exist in the file either. If the * block existed in the file, then its contents will be ignored. Contrast * this to {@link #readHeadBlock} where the contents of the block on the disk * are always read. * * @param blockId The block number of the head block. * @throws IOException if an I/O error occurs. */ private void allocateHeadBlock(int blockId) throws IOException { if (headBlock != null) { if (blockId == (int) headBlock.getBlockId()) { headBlockDirty = false; return; } releaseHeadBlock(); } headBlock = findBlock(blockId); if (headBlock == null) { headBlock = blockFile.allocateBlock(objectPool, blockId); } headBlockDirty = false; }
releaseHeadBlock(); nextBlockId = 2; blockFile.setNrBlocks(nextBlockId);