@NotNull @Override public File file() { return mappedFile.file(); }
@NotNull @Override public File file() { return mappedFile.file(); }
static File getFile(MappedBytes bytes) { if (bytes == null) return new File("none"); MappedFile mappedFile = bytes.mappedFile(); assert (mappedFile != null); File file = mappedFile.file(); assert (file != null); return file; }
@Test public void checkReferenceCountingAndCheckFileDeletion() { MappedFile mappedFile; try (ChronicleQueue queue = binary(getTmpDir()) .rollCycle(RollCycles.TEST_SECONDLY) .build()) { ExcerptAppender appender = queue.acquireAppender(); try (DocumentContext documentContext1 = appender.writingDocument()) { documentContext1.wire().write().text("some text"); } try (DocumentContext documentContext = queue.createTailer().readingDocument()) { mappedFile = toMappedFile(documentContext); Assert.assertEquals("some text", documentContext.wire().read().text()); } } waitFor(mappedFile::isClosed, "mappedFile is not closed"); if (OS.isWindows()) { System.err.println("#460 Cannot test delete after close on windows"); return; } // this used to fail on windows Assert.assertTrue(mappedFile.file().delete()); }
@NotNull @Override public File file() { return mappedFile.file(); }
@NotNull @Override public File file() { return mappedFile.file(); }
static File getFile(MappedBytes bytes) { if (bytes == null) return new File("none"); return bytes.mappedFile().file(); }
@Override public long realCapacity() { try { return mappedFile.actualSize(); } catch (IORuntimeException e) { Jvm.warn().on(getClass(), "Unable to obtain the real size for " + mappedFile.file(), e); return 0; } }
protected MappedBytes(@NotNull MappedFile mappedFile, String name) throws IllegalStateException { super(NoBytesStore.noBytesStore(), NoBytesStore.noBytesStore().writePosition(), NoBytesStore.noBytesStore().writeLimit(), name); this.mappedFile = reserve(mappedFile); this.backingFileIsReadOnly = !mappedFile.file().canWrite(); assert !mappedFile.isClosed(); clear(); }
@Override public boolean writeEOF(@NotNull Wire wire, long timeoutMS) { String fileName = mappedFile.file().getAbsolutePath(); // just in case we are about to release this if (wire.bytes().tryReserve()) { try { wire.writeEndOfWire(timeoutMS, TimeUnit.MILLISECONDS, writePosition()); if (wire.bytes().writePosition() > 4 && Wires.isEndOfFile(wire.bytes().readVolatileInt(wire.bytes().writePosition() - 4))) { // only if we just written EOF QueueFileShrinkManager.scheduleShrinking(mappedFile.file(), wire.bytes().writePosition()); return true; } } finally { wire.bytes().release(); } } else { try (MappedBytes bytes = MappedBytes.mappedBytes(mappedFile.file(), mappedFile.chunkSize())) { Wire wire0 = WireType.valueOf(wire).apply(bytes); wire0.writeEndOfWire(timeoutMS, TimeUnit.MILLISECONDS, writePosition()); if (wire.bytes().writePosition() > 4 && Wires.isEndOfFile(wire.bytes().readVolatileInt(wire.bytes().writePosition() - 4))) { QueueFileShrinkManager.scheduleShrinking(mappedFile.file(), wire.bytes().writePosition()); return true; } } catch (Exception e) { Jvm.warn().on(getClass(), "unable to write the EOF file=" + fileName, e); } } return false; }