Search in sources :

Example 6 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class AbstractTestBlockMgr method file02.

@Test
public void file02() {
    Block block = blockMgr.allocate(BlkSize);
    ByteBuffer bb = block.getByteBuffer();
    fill(bb, (byte) 1);
    long id = block.getId();
    blockMgr.write(block);
    blockMgr.release(block);
    Block block2 = blockMgr.getRead(id);
    ByteBuffer bb2 = block2.getByteBuffer();
    assertEquals(bb2.capacity(), BlkSize);
    assertEquals(bb2.get(0), (byte) 1);
    assertEquals(bb2.get(BlkSize - 1), (byte) 1);
    blockMgr.release(block2);
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 7 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class ObjectFileTrans method allocWrite.

@Override
public Block allocWrite(int maxBytes) {
    if (passthrough)
        return base.allocWrite(maxBytes);
    Block block = transObjects.allocWrite(maxBytes);
    block = new Block(block.getId() + otherAllocOffset, block.getByteBuffer());
    return block;
}
Also used : Block(org.apache.jena.tdb.base.block.Block)

Example 8 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class DumpOps method dumpBlockMgr.

public static void dumpBlockMgr(PrintStream out, BlockMgr blkMgr) {
    try {
        for (int id = 0; id < 9999999; id++) {
            if (!blkMgr.valid(id))
                break;
            Block blk = blkMgr.getRead(id);
            out.print("id=" + blk.getId() + "  ");
            ByteBufferLib.print(out, blk.getByteBuffer());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Block(org.apache.jena.tdb.base.block.Block) TDBException(org.apache.jena.tdb.TDBException)

Example 9 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class NodeLib method encodeStore.

public static long encodeStore(Node node, ObjectFile file) {
    // Buffer pool?
    // Nodes can be writtern during reads.
    // Make sure this operation is sync'ed. 
    int maxSize = nodec.maxSize(node);
    Block block = file.allocWrite(maxSize);
    try {
        int len = nodec.encode(node, block.getByteBuffer(), null);
        file.completeWrite(block);
        return block.getId();
    } catch (TDBException ex) {
        file.abortWrite(block);
        throw ex;
    }
}
Also used : TDBException(org.apache.jena.tdb.TDBException) Block(org.apache.jena.tdb.base.block.Block)

Example 10 with Block

use of org.apache.jena.tdb.base.block.Block in project jena by apache.

the class AbstractTestBlockAccessFixedSize method fileaccess_04.

@Test
public void fileaccess_04() {
    Block b1 = data(file, blkSize);
    Block b2 = data(file, blkSize);
    file.write(b1);
    file.write(b2);
    long x = b1.getId();
    Block b8 = file.read(b1.getId());
    Block b9 = file.read(b1.getId());
    assertNotSame(b8, b9);
    assertTrue(b8.getId() == b9.getId());
}
Also used : Block(org.apache.jena.tdb.base.block.Block) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

Block (org.apache.jena.tdb.base.block.Block)42 ByteBuffer (java.nio.ByteBuffer)15 Test (org.junit.Test)11 BaseTest (org.apache.jena.atlas.junit.BaseTest)10 MappedByteBuffer (java.nio.MappedByteBuffer)2 TDBException (org.apache.jena.tdb.TDBException)2 Adler32 (java.util.zip.Adler32)1 BlockException (org.apache.jena.tdb.base.block.BlockException)1 BlockAccess (org.apache.jena.tdb.base.file.BlockAccess)1 ObjectFile (org.apache.jena.tdb.base.objectfile.ObjectFile)1 RecordBufferPage (org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)1 FileRef (org.apache.jena.tdb.sys.FileRef)1