From d7ed5b01536d6f814a1171f2523634dc316cda75 Mon Sep 17 00:00:00 2001 From: leventov Date: Tue, 9 Feb 2016 15:03:34 +0700 Subject: [PATCH] Simplify parameter flow on VanillaChronicleHash initialization --- .../hash/impl/VanillaChronicleHash.java | 33 ++++++++----------- .../chronicle/map/ChronicleMapBuilder.java | 11 +++---- .../chronicle/map/VanillaChronicleMap.java | 4 +-- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index b9b1a873f..7d779bb91 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -382,16 +382,19 @@ public abstract class VanillaChronicleHash 0) { - if (ch.read(globalMutableStateBuffer, + if (fileChannel.read(globalMutableStateBuffer, this.headerSize + GLOBAL_MUTABLE_STATE_VALUE_OFFSET + globalMutableStateBuffer.position()) == -1) { throw throwRecoveryOrReturnIOException(file + " truncated", recover); @@ -456,11 +459,6 @@ public abstract class VanillaChronicleHash implements private VanillaChronicleMap createWithNewFile( VanillaChronicleMap map, File file, RandomAccessFile raf, ByteBuffer headerBuffer, int headerSize) throws IOException { - FileChannel fileChannel = raf.getChannel(); - map.initBeforeMapping(file, fileChannel, headerBuffer.limit(), false); - map.createMappedStoreAndSegments(file, raf); + map.initBeforeMapping(file, raf, headerBuffer.limit(), false); + map.createMappedStoreAndSegments(); commitChronicleMapReady(map, raf, headerBuffer, headerSize); establishReplication(map); return map; @@ -1593,7 +1592,7 @@ public final class ChronicleMapBuilder implements Wire wire = new TextWire(headerBytes); VanillaChronicleMap map = wire.getValueIn().typedMarshallable(); assert map != null; - map.initBeforeMapping(file, fileChannel, headerBuffer.limit(), recover); + map.initBeforeMapping(file, raf, headerBuffer.limit(), recover); long expectedFileLength = map.expectedFileSize(); if (!recover && expectedFileLength != file.length()) { throw new IOException("The file " + file + " the map is serialized from " + @@ -1602,13 +1601,13 @@ public final class ChronicleMapBuilder implements } map.initTransientsFromBuilder(this); if (!recover) { - map.createMappedStoreAndSegments(file, raf); + map.createMappedStoreAndSegments(); } else { if (!overrideBuilderConfig) writeNotReady(fileChannel, headerBuffer, headerSize); // if overrideBuilderConfig = true, readiness bit is already set // in writeHeader() call - map.recover(file, raf); + map.recover(); commitChronicleMapReady(map, raf, headerBuffer, headerSize); } establishReplication(map); diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 8ff15c342..ee1dcb4a1 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -147,8 +147,8 @@ public class VanillaChronicleMap initOwnTransients(); } - public void recover(File file, RandomAccessFile raf) throws IOException { - basicRecover(file, raf); + public void recover() throws IOException { + basicRecover(); iterationContext().recoverSegments(); }