Search in sources :

Example 1 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 2 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 3 with Block

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

the class AbstractTestObjectFile method objectfile_02.

@Test
public void objectfile_02() {
    Block block = file.allocWrite(10);
    fill(block.getByteBuffer());
    file.completeWrite(block);
    long x1 = block.getId();
    assertEquals(0, x1);
    ByteBuffer bb = file.read(x1);
    // position
    assertTrue(sameValue(block.getByteBuffer(), bb));
}
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 4 with Block

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

the class ObjectFileLogger method allocWrite.

@Override
public Block allocWrite(int maxBytes) {
    Block blk = other.allocWrite(maxBytes);
    info("allocWrite(" + maxBytes + ") -> " + blk.getId());
    return blk;
}
Also used : Block(org.apache.jena.tdb.base.block.Block)

Example 5 with Block

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

the class ObjectFileStorage method allocWrite.

@Override
public Block allocWrite(int bytesSpace) {
    //log.info("AW("+bytesSpace+"):"+state()) ;
    if (inAllocWrite)
        Log.error(this, "In the middle of an alloc-write");
    // Include space for length.
    int spaceRequired = bytesSpace + SizeOfInt;
    // Find space.
    if (writeBuffer != null && spaceRequired > writeBuffer.remaining())
        flushOutputBuffer();
    if (writeBuffer == null || spaceRequired > writeBuffer.remaining()) {
        // Too big. Have flushed buffering if buffering.
        inAllocWrite = true;
        ByteBuffer bb = ByteBuffer.allocate(bytesSpace);
        allocBlock = new Block(filesize, bb);
        allocLocation = -1;
        //log.info("AW:"+state()+"-> ----") ;
        return allocBlock;
    }
    // Will fit.
    inAllocWrite = true;
    int start = writeBuffer.position();
    // Old values for restoration
    oldBufferPosn = start;
    oldBufferLimit = writeBuffer.limit();
    // id (but don't tell the caller yet).
    allocLocation = filesize + start;
    // Slice it.
    writeBuffer.putInt(bytesSpace);
    writeBuffer.position(start + SizeOfInt);
    writeBuffer.limit(start + spaceRequired);
    ByteBuffer bb = writeBuffer.slice();
    allocBlock = new Block(allocLocation, bb);
    if (logging)
        log("AW: %s->0x%X", state(), allocLocation);
    return allocBlock;
}
Also used : Block(org.apache.jena.tdb.base.block.Block) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Block (org.apache.jena.tdb.base.block.Block)37 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)7 MappedByteBuffer (java.nio.MappedByteBuffer)2 BaseTest (org.apache.jena.atlas.junit.BaseTest)2 TDBException (org.apache.jena.tdb.TDBException)2 Adler32 (java.util.zip.Adler32)1 BlockException (org.apache.jena.tdb.base.block.BlockException)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