diff --git a/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/WireStore.java b/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/WireStore.java index 3a0b0215c8..d854be6e0d 100644 --- a/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/WireStore.java +++ b/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/WireStore.java @@ -48,7 +48,7 @@ public interface WireStore extends ReferenceCounted, Marshallable { /** * @return the first readable position */ - long readPosition(); + // long readPosition(); /** * @return the first writable position @@ -85,4 +85,5 @@ void install( throws IOException; MappedBytes mappedBytes(); + } diff --git a/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/single/SingleChronicleQueueStore.java b/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/single/SingleChronicleQueueStore.java index 287fe64612..aa956d878b 100755 --- a/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/single/SingleChronicleQueueStore.java +++ b/chronicle-queue/src/main/java/net/openhft/chronicle/queue/impl/single/SingleChronicleQueueStore.java @@ -55,7 +55,7 @@ public class SingleChronicleQueueStore implements WireStore { private final WireType wireType; private final Roll roll; Bounds bounds = new Bounds(); - private MappedBytes mappedBytes; + private MappedFile mappedFile; private Closeable resourceCleaner; private final ReferenceCounter refCount = ReferenceCounter.onReleased(this::performRelease); private long appendTimeout = 1_000; @@ -87,14 +87,10 @@ public class SingleChronicleQueueStore implements WireStore { this.resourceCleaner = null; this.builder = null; this.wireType = wireType; - this.mappedBytes = mappedBytes; + this.mappedFile = mappedBytes.mappedFile(); this.indexing = new Indexing(wireType, mappedBytes); } - @Override - public long readPosition() { - return this.bounds.getReadPosition(); - } @Override public long writePosition() { @@ -198,7 +194,7 @@ public void install( long length, boolean created, long cycle, - ChronicleQueueBuilder builder, + @NotNull ChronicleQueueBuilder builder, @NotNull Function wireSupplier, @Nullable Closeable closeable) throws IOException { @@ -211,11 +207,17 @@ public void install( } } + + /** + * @return creates a new instance of mapped bytes, because, for example the tailer and appender + * can be at diffent locations. + */ @Override public MappedBytes mappedBytes() { - return new MappedBytes(mappedBytes.mappedFile()); + return new MappedBytes(mappedFile);//.withSizes(this.chunkSize, this.overlapSize); } + // ************************************************************************* // Utilities // ************************************************************************* @@ -296,7 +298,7 @@ private long read( final StringBuilder sb = Wires.acquireStringBuilder(); // todo improve this line - final ValueIn vi = wireType.apply(context).read(sb); + final ValueIn vi = wire.read(sb); if ("index".contentEquals(sb)) { return read(wire, reader, marshaller); @@ -457,7 +459,7 @@ long write( @Override public void writeMarshallable(@NotNull WireOut wire) { - MappedFile mappedFile = mappedBytes.mappedFile(); + wire.write(MetaDataField.bounds).marshallable(this.bounds) .write(MetaDataField.roll).object(this.roll) .write(MetaDataField.chunkSize).int64(mappedFile.chunkSize()) @@ -475,16 +477,16 @@ public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException { long chunkSize = wire.read(MetaDataField.chunkSize).int64(); long overlapSize = wire.read(MetaDataField.overlapSize).int64(); - this.mappedBytes = (MappedBytes) wire.bytes(); - - final MappedBytes mappedBytes = new MappedBytes(this.mappedBytes.mappedFile()); - indexing = new Indexing(wireType, mappedBytes.withSizes(chunkSize, overlapSize)); + final MappedBytes mappedBytes = (MappedBytes) (wire.bytes()); + this.mappedFile = mappedBytes.mappedFile(); + indexing = new Indexing(wireType, mappedBytes.withSizes(chunkSize, + overlapSize)); wire.read(MetaDataField.indexing).marshallable(indexing); } - // ************************************************************************* - // Marshallable - // ************************************************************************* +// ************************************************************************* +// Marshallable +// ************************************************************************* enum MetaDataField implements WireKey { bounds,