Search in sources :

Example 1 with MappedFile

use of net.openhft.chronicle.bytes.MappedFile in project Chronicle-Queue by OpenHFT.

the class PretoucherState method getFile.

static File getFile(MappedBytes bytes) {
    if (bytes == null)
        return new File("none");
    MappedFile mappedFile = bytes.mappedFile();
    if (mappedFile == null)
        return new File("none");
    File file = mappedFile.file();
    if (file == null)
        return new File("none");
    return file;
}
Also used : MappedFile(net.openhft.chronicle.bytes.MappedFile) MappedFile(net.openhft.chronicle.bytes.MappedFile) File(java.io.File)

Example 2 with MappedFile

use of net.openhft.chronicle.bytes.MappedFile in project Chronicle-Queue by OpenHFT.

the class QueueDumpMain method dump.

public static void dump(File filename, PrintWriter pw) throws FileNotFoundException {
    MappedFile mappedFile = MappedFile.mappedFile(filename, 64 << 20, 16 << 20);
    Bytes bytes = mappedFile.bytes();
    pw.print("# Magic: ");
    for (int i = 0; i < 8; i++) pw.print((char) bytes.readUnsignedByte());
    pw.println();
    while (true) {
        long spb = bytes.readUnsignedInt();
        if (!Wires.isKnownLength(spb))
            break;
        pw.print("--- !");
        pw.print(SBP_TYPES[((int) (spb >>> 30))]);
        pw.println();
        long start = bytes.position();
        BytesUtil.toString(bytes, pw, start, start, start + Wires.lengthOf(spb));
        pw.println();
        bytes.skip(Wires.lengthOf(spb));
    }
    pw.flush();
}
Also used : MappedFile(net.openhft.chronicle.bytes.MappedFile) Bytes(net.openhft.chronicle.bytes.Bytes)

Example 3 with MappedFile

use of net.openhft.chronicle.bytes.MappedFile in project Chronicle-Queue by OpenHFT.

the class MappingReferenceCountTest method testMappingReferenceCount.

/**
 * tests that blocks are acquired and released as needed
 *
 * @
 */
@Test
public void testMappingReferenceCount() {
    File tempFile = File.createTempFile("chronicle", "q");
    try {
        int BLOCK_SIZE = 4096;
        final MappedFile mappedFile = MappedFile.mappedFile(tempFile.getName(), BLOCK_SIZE, 8);
        final Bytes bytes = mappedFile.bytes();
        // write into block 1
        bytes.writeLong(4096 + 8, Long.MAX_VALUE);
        // Assert.assertEquals(1, mappedFile.getRefCount(1));
        assertEquals("refCount: 2, 0, 2", mappedFile.referenceCounts());
        // we move from block 1 to block 2
        bytes.writeLong((4096 * 2) + 8, Long.MAX_VALUE);
        // assertEquals(0, mappedFile.getRefCount(1));
        // assertEquals(1, mappedFile.getRefCount(2));
        assertEquals("refCount: 3, 0, 1, 2", mappedFile.referenceCounts());
        // we move from block 2 back to block 1
        bytes.writeLong((4096 * 1) + 8, Long.MAX_VALUE);
        // assertEquals(1, mappedFile.getRefCount(1));
        // assertEquals(0, mappedFile.getRefCount(2));
        assertEquals("refCount: 3, 0, 2, 1", mappedFile.referenceCounts());
        // we move from block 2 back to block 1
        bytes.writeLong((4096 * 3) + 8, Long.MAX_VALUE);
        // assertEquals(1, mappedFile.getRefCount(3));
        assertEquals("refCount: 4, 0, 1, 1, 2", mappedFile.referenceCounts());
        bytes.release();
        mappedFile.close();
        assertEquals("refCount: 0, 0, 0, 0, 0", mappedFile.referenceCounts());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        tempFile.delete();
    }
}
Also used : MappedFile(net.openhft.chronicle.bytes.MappedFile) Bytes(net.openhft.chronicle.bytes.Bytes) FileNotFoundException(java.io.FileNotFoundException) MappedFile(net.openhft.chronicle.bytes.MappedFile) File(java.io.File) Test(org.junit.Test)

Aggregations

MappedFile (net.openhft.chronicle.bytes.MappedFile)3 File (java.io.File)2 Bytes (net.openhft.chronicle.bytes.Bytes)2 FileNotFoundException (java.io.FileNotFoundException)1 Test (org.junit.Test)1