You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/05/20 21:07:38 UTC
svn commit: r1125513 - in
/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base:
file/FileFactory.java objectfile/ObjectFileDiskDirect.java
objectfile/ObjectFileMem.java objectfile/ObjectFileStorage.java
Author: andy
Date: Fri May 20 19:07:38 2011
New Revision: 1125513
URL: http://svn.apache.org/viewvc?rev=1125513&view=rev
Log: (empty)
Removed:
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileDiskDirect.java
Modified:
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java?rev=1125513&r1=1125512&r2=1125513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java Fri May 20 19:07:38 2011
@@ -1,15 +1,19 @@
/*
* (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
+ * (c) Copyright 2011 Epimorphics Ltd.
* All rights reserved.
* [See end of file]
*/
package com.hp.hpl.jena.tdb.base.file;
-import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile;
-import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileDiskDirect;
-import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileMem;
-import com.hp.hpl.jena.tdb.base.objectfile.StringFile;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileMem ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileStorage ;
+import com.hp.hpl.jena.tdb.base.objectfile.StringFile ;
+import com.hp.hpl.jena.tdb.base.storage.Storage ;
+import com.hp.hpl.jena.tdb.base.storage.StorageFile ;
+import com.hp.hpl.jena.tdb.base.storage.StorageMem ;
public class FileFactory
{
@@ -20,10 +24,23 @@ public class FileFactory
{ return new StringFile(createObjectFileMem()) ; }
public static ObjectFile createObjectFileDisk(String filename)
- { return new ObjectFileDiskDirect(filename) ; }
+ {
+ Storage store = new StorageFile(filename) ;
+ return new ObjectFileStorage(store) ;
+ }
public static ObjectFile createObjectFileMem()
- { return new ObjectFileMem() ; }
+ {
+ if ( true )
+ // Older code.
+ return new ObjectFileMem() ;
+ else
+ {
+ // Newer way.
+ Storage store = new StorageMem("mem") ;
+ return new ObjectFileStorage(store) ;
+ }
+ }
public static PlainFile createPlainFileDisk(String filename)
{ return new PlainFilePersistent(filename) ; }
@@ -34,6 +51,7 @@ public class FileFactory
/*
* (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
+ * (c) Copyright 2011 Epimorphics Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java?rev=1125513&r1=1125512&r2=1125513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java Fri May 20 19:07:38 2011
@@ -34,6 +34,7 @@ public class ObjectFileMem implements Ob
public ObjectFileMem()
{ }
+ // Could have been ObjectFileStorage + a byte array.
@Override
public long length()
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java?rev=1125513&r1=1125512&r2=1125513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java Fri May 20 19:07:38 2011
@@ -41,7 +41,7 @@ public class ObjectFileStorage implement
private ByteBuffer lengthBuffer = ByteBuffer.allocate(SizeOfInt) ;
// Delayed write buffer.
- private ByteBuffer output = ByteBuffer.allocate(ObjectFileWriteCacheSize) ;
+ private final ByteBuffer writeBuffer ;
private int bufferSize ;
private final Storage file ; // Access to storage
@@ -52,35 +52,46 @@ public class ObjectFileStorage implement
private ByteBuffer allocByteBuffer = null ;
private long allocLocation = -1 ;
+ public ObjectFileStorage(Storage file)
+ {
+ this(file, ObjectFileWriteCacheSize) ;
+ }
+
public ObjectFileStorage(Storage file, int bufferSize)
{
this.file = file ;
this.bufferSize = bufferSize ;
filesize = file.length() ;
+ writeBuffer = ByteBuffer.allocate(bufferSize) ;
}
@Override
public long write(ByteBuffer bb)
{
-
int len = bb.limit() - bb.position() ;
- if ( output.limit()+len > output.capacity() )
+ if ( writeBuffer.limit()+len > writeBuffer.capacity() )
// No room - flush.
flushOutputBuffer() ;
- // Is there room now?
- // XXX
- System.err.println("Use the delayed write buffer") ;
-
- lengthBuffer.clear() ;
- lengthBuffer.putInt(0, len) ;
+ if ( writeBuffer.limit()+len > writeBuffer.capacity() )
+ {
+ long x = rawWrite(bb) ;
+ return x ;
+ }
+ writeBuffer.put(bb) ;
+ return len ;
+ }
+
+ private long rawWrite(ByteBuffer bb)
+ {
long location = filesize ;
int x = file.write(bb, location) ;
long loc2 = location+SizeOfInt ;
x += file.write(bb, loc2) ;
filesize = filesize+x ;
return location ;
+
}
@Override
@@ -89,10 +100,10 @@ public class ObjectFileStorage implement
// Include space for length.
int spaceRequired = maxBytes + SizeOfInt ;
// Find space.
- if ( spaceRequired > output.remaining() )
+ if ( spaceRequired > writeBuffer.remaining() )
flushOutputBuffer() ;
- if ( spaceRequired > output.remaining() )
+ if ( spaceRequired > writeBuffer.remaining() )
{
// Too big.
inAllocWrite = true ;
@@ -103,14 +114,14 @@ public class ObjectFileStorage implement
// Will fit.
inAllocWrite = true ;
- int start = output.position() ;
+ int start = writeBuffer.position() ;
// id (but don't tell the caller yet).
allocLocation = filesize+start ;
// Slice it.
- output.position(start + SizeOfInt) ;
- output.limit(start+spaceRequired) ;
- ByteBuffer bb = output.slice() ;
+ writeBuffer.position(start + SizeOfInt) ;
+ writeBuffer.limit(start+spaceRequired) ;
+ ByteBuffer bb = writeBuffer.slice() ;
allocByteBuffer = bb ;
return bb ;
@@ -126,28 +137,28 @@ public class ObjectFileStorage implement
if ( allocLocation == -1 )
// It was too big to use the buffering.
- return write(buffer) ;
+ return rawWrite(buffer) ;
int actualLength = buffer.limit()-buffer.position() ;
// Insert object length
int idx = (int)(allocLocation-filesize) ;
- output.putInt(idx, actualLength) ;
+ writeBuffer.putInt(idx, actualLength) ;
// And bytes to idx+actualLength+4 are used
inAllocWrite = false;
allocByteBuffer = null ;
int newLen = idx+actualLength+4 ;
- output.position(newLen);
- output.limit(output.capacity()) ;
+ writeBuffer.position(newLen);
+ writeBuffer.limit(writeBuffer.capacity()) ;
return allocLocation ;
}
private void flushOutputBuffer()
{
long location = filesize ;
- output.flip();
- int x = file.write(output) ;
+ writeBuffer.flip();
+ int x = file.write(writeBuffer) ;
filesize += x ;
- output.clear() ;
+ writeBuffer.clear() ;
}
@@ -160,21 +171,21 @@ public class ObjectFileStorage implement
// Maybe it's in the in the write buffer
if ( loc >= filesize )
{
- if ( loc > filesize+output.capacity() )
+ if ( loc > filesize+writeBuffer.capacity() )
throw new IllegalArgumentException("ObjectFile.read: Bad read: "+loc) ;
- int x = output.position() ;
- int y = output.limit() ;
+ int x = writeBuffer.position() ;
+ int y = writeBuffer.limit() ;
int offset = (int)(loc-filesize) ;
- int len = output.getInt(offset) ;
+ int len = writeBuffer.getInt(offset) ;
int posn = offset + SizeOfInt ;
// Slice the data bytes,
- output.position(posn) ;
- output.limit(posn+len) ;
- ByteBuffer bb = output.slice() ;
- output.limit(y) ;
- output.position(x) ;
+ writeBuffer.position(posn) ;
+ writeBuffer.limit(posn+len) ;
+ ByteBuffer bb = writeBuffer.slice() ;
+ writeBuffer.limit(y) ;
+ writeBuffer.position(x) ;
return bb ;
}