jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [44/65] [abbrv] jena git commit: JENA-1397: Rename java packages
Date Tue, 03 Oct 2017 19:34:30 GMT
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/migrate/L.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/migrate/L.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/migrate/L.java
new file mode 100644
index 0000000..8702c00
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/migrate/L.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.migrate;
+
+import java.io.IOException ;
+import java.io.OutputStream ;
+import java.io.OutputStreamWriter ;
+import java.io.Writer ;
+import java.nio.ByteBuffer ;
+import java.nio.charset.StandardCharsets ;
+import java.util.UUID ;
+import java.util.concurrent.* ;
+import java.util.concurrent.locks.Lock ;
+import java.util.function.Supplier ;
+
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.Bytes ;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.shared.uuid.JenaUUID ;
+
+/** Misc class */
+public class L {
+    
+    // Not to be confused with UUID.nameUUIDFromBytes (a helper for version 3 UUIDs)
+    /**
+     * Java UUID to bytes (most significant first)
+     */
+    public static byte[] uuidAsBytes(UUID uuid) {
+        return uuidAsBytes(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()) ;
+    }
+    
+    /**
+     * Jena UUID to bytes (most significant first)
+     */
+    public static byte[] uuidAsBytes(JenaUUID uuid) {
+        return uuidAsBytes(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()) ;
+    }
+    
+    /** UUID, as two longs, as bytes */ 
+    public static byte[] uuidAsBytes(long mostSignificantBits, long leastSignificantBits) {
+        byte[] bytes = new byte[16] ;
+        Bytes.setLong(mostSignificantBits, bytes, 0); 
+        Bytes.setLong(leastSignificantBits, bytes, 8);
+        return bytes ;
+    }
+    
+    /** A UUID string to bytes */ 
+    public static byte[] uuidAsBytes(String str) {
+        return uuidAsBytes(UUID.fromString(str)) ;
+    }
+    
+    public static String uuidToString(long mostSignificantBits, long leastSignificantBits) {
+        return new UUID(mostSignificantBits, leastSignificantBits).toString() ;
+        //JenaUUID.toString(mostSignificantBits, leastSignificantBits)
+    }
+    
+    private static ExecutorService executor = Executors.newCachedThreadPool() ; 
+    
+    /**
+     * Run asynchronously on another thread ; the thread has started
+     * when this function returns.
+     */
+    public static void async(Runnable r) {
+        Semaphore semaStart = new Semaphore(0, true) ;
+        Runnable r2 = () -> {
+            semaStart.release(1) ;
+            r.run();
+        } ;
+        executor.execute(r2);
+        semaStart.acquireUninterruptibly();
+    }
+    
+    /** Run synchronously but on another thread. */
+    public static void syncOtherThread(Runnable r) {
+        runCallable(()->{
+            r.run();
+            return null ;
+        }) ;
+    }
+
+    /** Run synchronously but on another thread. */
+    public static <T> T syncCallThread(Supplier<T> r) {
+        return runCallable(() -> {
+            T t = r.get() ;
+            return t ;
+        }) ;
+    }
+    
+    private static <T> T runCallable(Callable<T> action) {
+        try { return executor.submit(action).get() ; }
+        catch (Exception e) {
+            e.printStackTrace();
+            return null ;
+        }
+    }
+    
+
+    /** Execute. Preform the "before" action, then main action.
+     *  Always call the "after" runnable if the "bafore" succeeded.
+     *  Becareful about argument order. 
+     * @param action
+     * @param before
+     * @param after
+     */
+    public static void withBeforeAfter(Runnable action, Runnable before, Runnable after) {
+        before.run(); 
+        try { action.run(); }
+        finally { after.run();  }
+    }
+
+    /** Execute. Preform the "before" action, then main action.
+     *  Always call the "after" runnable if the "bafore" succeeded.
+     *  Becareful about argument order. 
+     * @param action
+     * @param before
+     * @param after
+     */
+    public static <V> V callWithBeforeAfter(Supplier<V> action, Runnable before, Runnable after) {
+        before.run(); 
+        try { return action.get() ; } 
+        finally { after.run();  }
+    }
+
+    /** Execute; always call the "after" runnable */
+    public static void withAfter(Runnable action, Runnable after) {
+        try { action.run(); } 
+        finally { after.run();  }
+    }
+
+    /** Execute and return a value; always call the "after" runnable */
+    public static <V> V callWithAfter(Supplier<V> action, Runnable after) {
+        try { return action.get() ; }
+        finally { after.run();  }
+    }
+
+    /** Run inside a Lock */
+    public static  <V> V callWithLock(Lock lock, Supplier<V> r) {
+        return callWithBeforeAfter(r, ()->lock.lock(), ()->lock.unlock()) ;  
+    }
+    
+    /** Run inside a Lock */
+    public static void withLock(Lock lock, Runnable r) {
+        withBeforeAfter(r, ()->lock.lock(), ()->lock.unlock()) ;
+    }
+    
+    // ==> IO.writeWholeFileAsUTF8
+    
+    /** Write a string to a file as UTF-8. The file is closed after the operation.
+     * @param filename
+     * @param content String to be writtem
+     * @throws IOException
+     */
+    
+    public static void writeStringAsUTF8(String filename, String content) throws IOException {
+        try ( OutputStream out = IO.openOutputFileEx(filename) ) {
+            writeStringAsUTF8(out, content) ;
+            out.flush() ;
+        }
+    }
+
+    /** Read a whole stream as UTF-8
+     * 
+     * @param out       OutputStream to be read
+     * @param content   String to be written
+     * @throws  IOException
+     */
+    public static void writeStringAsUTF8(OutputStream out, String content) throws IOException {
+        Writer w = new OutputStreamWriter(out, StandardCharsets.UTF_8) ;
+        w.write(content);
+        w.flush();
+        // Not close.
+    }
+
+    // ==> IO.writeWholeFileAsUTF8
+    
+    /** String to ByteBuffer */
+    public static ByteBuffer stringToByteBuffer(String str) {
+        byte[] b = StrUtils.asUTF8bytes(str) ;
+        return ByteBuffer.wrap(b) ;
+    }
+    
+    /** ByteBuffer to String */
+    public static String byteBufferToString(ByteBuffer bb) {
+        byte[] b = new byte[bb.remaining()] ;
+        bb.get(b) ;
+        return StrUtils.fromUTF8bytes(b) ;
+    }
+
+
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/FileLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/FileLib.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/FileLib.java
new file mode 100644
index 0000000..2c0733e
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/FileLib.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.sys;
+
+import java.io.FileNotFoundException ;
+import java.io.IOException ;
+import java.io.RandomAccessFile ;
+import java.nio.channels.FileChannel ;
+
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.dboe.base.file.ChannelManager;
+import org.apache.jena.dboe.base.file.FileException;
+
+// => IO
+public class FileLib
+{
+    // Check whether still used.
+    
+    public static FileChannel openUnmanaged(String filename) {
+        return openUnmanaged(filename, "rw") ;
+    }
+
+    // And operation from BufferChannelFile
+    
+    public static FileChannel openUnmanaged(String filename, String mode) {
+        try {
+            @SuppressWarnings("resource")
+            RandomAccessFile out = new RandomAccessFile(filename, mode) ;
+            FileChannel channel = out.getChannel() ;
+            return channel ;
+        }
+        catch (FileNotFoundException e) {
+            IO.exception(e) ;
+            return null ;
+        }
+    }
+
+    // TODO remove and call ChannelManager directly 
+    public static FileChannel openManaged(String filename) {
+        return openManaged(filename, "rw") ;
+    }
+
+    // TODO remove and call ChannelManager directly 
+    public static FileChannel openManaged(String filename, String mode) {
+        return ChannelManager.acquire(filename, mode) ;
+    }
+
+    public static long size(FileChannel channel) {
+        try {
+            return channel.size() ;
+        } catch (IOException ex)
+        { IO.exception(ex) ; return -1L ; }
+    }
+
+    public static void truncate(FileChannel channel, long posn) {
+        try { channel.truncate(posn) ; }
+        catch (IOException ex) { IO.exception(ex) ; }
+    }
+
+    public static void close(FileChannel channel) {
+        ChannelManager.release(channel) ;
+    }
+
+    public static void sync(FileChannel channel) {
+        try {
+            channel.force(true) ;
+        } catch (IOException ex)
+        { throw new FileException("FileBase.sync", ex) ; }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Names.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Names.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Names.java
new file mode 100644
index 0000000..71cf253
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Names.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.sys;
+
+/** Names of things in TDB */
+public class Names
+{
+    /** Filename of the TDB configuration file */
+    public static final String TDB_CONFIG_FILE = "tdb.cfg" ;
+    
+    /** Filename of the TDB lock file */
+    public static final String TDB_LOCK_FILE = "tdb.lock" ; 
+    
+    /* System files */
+    public static final String extJournal               = "jrnl" ;
+    /* Component Transactional State */    
+    public static final String extState                 = "cts" ;           
+    
+    public static final String journalFileBase          = "journal" ;
+    public static final String journalFile              = journalFileBase+"."+extJournal ;
+
+    // ++ Elsewhere
+    /* RDF indexes */
+    public static final String primaryIndexTriples      = "SPO" ; 
+    public static final String[] tripleIndexes          = { primaryIndexTriples, "POS", "OSP" } ;
+
+    public static final String primaryIndexQuads        = "GSPO" ; 
+    public static final String[] quadIndexes            = { primaryIndexQuads, "GPOS", "GOSP", "POSG", "OSPG", "SPOG"} ;
+    
+    public static final String primaryIndexPrefix       = "GPU" ;
+    public static final String[] prefixIndexes          = { primaryIndexPrefix } ;
+    // ++ Elsewhere
+    
+    /* B+Trees - nodes file and records file */
+    public static final String extBptState              = "bpt" ;
+    public static final String extBptTree               = "idn" ;
+    public static final String extBptRecords            = "dat" ;
+
+//    /* B+Trees - single file per tree */
+//    public static final String btExt                    = "idx" ;
+    
+    /* ExtHash - dictionary file*/
+    public static final String extHashExt               = "exh" ;
+    public static final String extHashBucketExt         = "dat" ;
+
+    public static final String datasetConfig            = "config-tdb" ;        // name of the TDB configuration file.
+
+    /* Node files */
+    public static final String extBdfState              = "bdf" ;           // Node state
+    public static final String extObjNodeData           = "obj" ;
+    public static final String nodeTableBaseName        = "nodes" ;         // Node table
+
+    /** Prefixes file */
+    public static final String prefixTableBaseName      = "prefixes" ;      // Prefix node table 
+    
+    /** Optimizer / stats */
+    public static final String optStats                 = "stats.opt" ;
+    public static final String optFixed                 = "fixed.opt" ;
+    public static final String optNone                  = "none.opt" ; 
+    public static final String optDefault               = optFixed ;
+    
+    public static final String extMeta                  = "info" ;
+    public static final String directoryMetafile        = "this" ;          // Root name of the directory for a metafile.  
+
+    /** Name to indicate in-memory */ 
+    public static final String memName                  = "--mem--" ;
+
+    public static boolean isMem(String name)            { return memName.equals(name) ; }
+    
+    // ---- Names for Java properties in metadata files
+    
+    public static String makeKey(String root, String...elements)
+    { return makeName(root, elements) ; }
+    
+    public static String makeName(String root, String...elements)
+    {
+        StringBuilder sb = new StringBuilder() ;
+        sb.append(root) ;
+        for ( String s : elements )
+        {
+            if ( ! s.startsWith(".") )
+                sb.append(".") ;
+            sb.append(s) ;
+        }
+        return sb.toString() ;
+    }
+    
+    // Component elements.
+    public static final String elNode                 = "node" ;
+    public static final String elBPlusTree            = "bptree" ;
+    public static final String elIndex                = "index" ;
+    public static final String elObject               = "object" ;
+    
+    public static final String elType                 = "type" ;
+    public static final String elLayout               = "layout" ;
+    public static final String elVersion              = "version" ;
+    public static final String elTimestamp            = "timestamp" ;
+    public static final String elCreated              = "created" ;
+    
+    // Root names.
+    public static final String keyNS                    = "tdb" ;
+    public static final String keyNSNode                = makeName(keyNS, elNode) ;
+    public static final String keyNSBPlusTree           = makeName(keyNS, elBPlusTree) ;
+    
+    // Location metadata - in the directory wide metadata file.
+    public static final String kVersion               = makeName(keyNS, elVersion) ;
+    public static final String kCreatedDate           = makeName(keyNS, elTimestamp) ;    
+
+    // Node table metadata
+    public static final String kNodeTableType         = makeName(keyNS, elNode, elType) ;
+    public static final String kNodeTableLayout       = makeName(keyNS, elNode, elLayout) ;
+
+//    // Object file
+//    public static final String kObjectTableType         = makeName(keyNS, elObject, elType) ;
+//    
+//    // Default index metadata - in the index metadata file.
+//    
+//    public static final String kIndexType             = makeName(keyNS, elIndex, elType) ;
+//    public static final String kIndexFileLayout       = makeName(keyNS, elIndex, elLayout) ;
+    
+    // See also BPlusTreeParams for keyNSBPlusTree derived names.
+    
+//    // Current values
+//    public static final String currentIndexType         = IndexType.BPlusTree.getName() ;
+//    public static final String currentIndexFileVersion  = "v1" ;
+
+    // Property strings - Setup
+    
+    public static final String pNode2NodeIdCacheSize       = "tdb.cache.node2nodeid.size" ;
+    public static final String pNodeId2NodeCacheSize       = "tdb.cache.nodeid2node.size" ;
+    public static final String pNodeMissesCacheSize        = "tdb.cache.nodeMiss.size" ;
+    public static final String pBlockWriteCacheSize        = "tdb.cache.blockwrite.size" ;
+    public static final String pBlockReadCacheSize         = "tdb.cache.blockread.size" ;
+    public static final String pSyncTick                   = "tdb.synctick" ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/ProcessUtils.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/ProcessUtils.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/ProcessUtils.java
new file mode 100644
index 0000000..0fd210c
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/ProcessUtils.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.sys;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ProcessUtils {
+
+    private static int myPid = -1;
+
+    /**
+     * Tries to get the PID of the current process caching it for future calls
+     * since it won't change throughout the life of the process
+     * 
+     * @param fallback
+     *            Fallback PID to return if unable to determine the PID i.e. an
+     *            error code to return
+     * 
+     * @return PID of current process or provided {@code fallback} if unable to
+     *         determine PID
+     */
+    public static int getPid(int fallback) {
+        if (myPid != -1)
+            return myPid;
+
+        String runtimeBeanName = ManagementFactory.getRuntimeMXBean().getName();
+        if (runtimeBeanName == null) {
+            return useFallbackPid(fallback);
+        }
+
+        // Bean name will have format PID@hostname so we try to parse the PID
+        // portion
+        int index = runtimeBeanName.indexOf("@");
+        if (index < 0)
+            return useFallbackPid(fallback);
+        try {
+            // Parse and cache for future reuse
+            String pidData = runtimeBeanName.substring(0, index);
+            myPid = Integer.parseInt(pidData);
+            return myPid;
+        } catch (NumberFormatException e) {
+            // Invalid PID
+            return useFallbackPid(fallback);
+        }
+    }
+
+    private static int useFallbackPid(int fallback) {
+        // In the case where we can't determine our PID then treat ourselves as
+        // no owner and cache for future use
+        myPid = fallback;
+        return myPid;
+    }
+
+    /**
+     * Determines whether a given PID is alive
+     * 
+     * @param pid
+     *            PID
+     * @return True if the given PID is alive or unknown, false if it is dead
+     */
+    public static boolean isAlive(int pid) {
+        String pidStr = Integer.toString(pid);
+        try {
+            List<String> data = getProcessInfo(pidStr);
+
+            // Expect a line to contain the PID to indicate the process is
+            // alive
+            for (String lineData : data) {
+                if (lineData.contains(pidStr))
+                    return true;
+            }
+
+            // Did not find any lines mentioning the PID so we can safely
+            // assume that process is dead
+            return false;
+        } catch (IOException e) {
+            // If any error running the process to check for the live process
+            // then our check failed and for safety we assume the process is
+            // alive
+
+            Sys.errlog
+                    .warn("Your platform does not support checking process liveness so TDB disk locations cannot be reliably locked to prevent possible corruption due to unsafe multi-JVM usage");
+            return true;
+        }
+    }
+
+    /**
+     * Gets whether the platform we are running on will cause us to treat
+     * negative (i.e. invalid) PIDs as alive because of the format in which the
+     * command line process monitor application for the system returns errors
+     * for invalid PIDs
+     * 
+     * @return True if a negative PID is treated as alive on this platform or we
+     *         cannot determine liveness for PIDs on this platform, false
+     *         otherwise
+     */
+    public static boolean negativePidsTreatedAsAlive() {
+        return isAlive(-1);
+    }
+
+    /**
+     * Gets process information based on the given PID string
+     * 
+     * @param pidStr
+     *            PID string
+     * @return Output of running the OSes appropriate command line task info
+     *         application
+     * @throws IOException
+     *             Thrown if there is a problem running the command line
+     *             application or reading the data returned
+     */
+    private static List<String> getProcessInfo(String pidStr) throws IOException {
+        Process p;
+        if (Sys.isWindows) {
+            // Use the Windows tasklist utility
+            ProcessBuilder builder = new ProcessBuilder("tasklist", "/FI", "PID eq " + pidStr);
+            builder.redirectErrorStream(true);
+            p = builder.start();
+        } else {
+            // Use the ps utility
+            ProcessBuilder builder = new ProcessBuilder("ps", "-p", pidStr);
+            builder.redirectErrorStream(true);
+            p = builder.start();
+        }
+
+        // Run and read data from the process
+        try(BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
+            List<String> data = new ArrayList<>();
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                data.add(line);
+            }
+            return data;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Sys.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Sys.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Sys.java
new file mode 100644
index 0000000..05faccb
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/Sys.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.sys;
+
+import java.nio.ByteOrder;
+import java.util.concurrent.Executor ;
+import java.util.concurrent.Executors ;
+
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.dboe.DBOpEnvException;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+/** Low level environment */ 
+public class Sys
+{
+    static final Logger log = LoggerFactory.getLogger("Sys") ;
+    
+    /** System log - use for general messages (a few) and warnings.
+     *  Generally, do not log events unless you want every user to see them every time.
+     *  Libraries and embedded systems should be seen and not heard.
+     *  @see #errlog 
+     */
+    
+    /** General system log */
+    public static final Logger syslog = LoggerFactory.getLogger("System") ;
+    /** Send warnings and error */
+    public static final Logger errlog = LoggerFactory.getLogger("System") ;
+    
+    /** Size, in bytes, of a Java long */
+    public static final int SizeOfLong              = Long.BYTES ; // Long.SIZE/Byte.SIZE ;
+    
+    /** Size, in bytes, of a Java int */
+    public static final int SizeOfInt               = Integer.BYTES ; //Integer.SIZE/Byte.SIZE ;
+    
+    public static final boolean is64bitSystem = determineIf64Bit() ;
+    
+    public static final ByteOrder NetworkOrder      = ByteOrder.BIG_ENDIAN ;
+
+    // To make the class initialize
+    static public void init() {}
+
+    public static void panic(Class<? > clazz, String string) {
+        Log.error(clazz, string) ;
+        throw new DBOpEnvException(string) ;
+    }
+    public static final boolean isWindows = determineIfWindows() ;	// Memory mapped files behave differently.
+
+    //Or look in File.listRoots.
+    //Alternative method:
+    //  http://stackoverflow.com/questions/1293533/name-of-the-operating-system-in-java-not-os-name
+    
+    private static boolean determineIfWindows() {
+    	String s = System.getProperty("os.name") ;
+    	if ( s == null )
+    		return false ;
+    	return s.startsWith("Windows ") ;
+	}
+    
+    /** A general thread pool */
+    public static Executor executor = Executors.newCachedThreadPool() ;
+
+    private static boolean determineIf64Bit() {
+        String s = System.getProperty("sun.arch.data.model") ;
+        if ( s != null ) {
+            boolean b = s.equals("64") ;
+            syslog.debug("System architecture: " + (b ? "64 bit" : "32 bit")) ;
+            return b ;
+        }
+        // Not a SUN VM
+        s = System.getProperty("java.vm.info") ;
+        if ( s == null ) {
+            log.warn("Can't determine the data model") ;
+            return false ;
+        }
+        log.debug("Can't determine the data model from 'sun.arch.data.model' - using java.vm.info") ;
+        boolean b = s.contains("64") ;
+        syslog.debug("System architecture: (from java.vm.info) " + (b ? "64 bit" : "32 bit")) ;
+        return b ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemFile.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemFile.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemFile.java
new file mode 100644
index 0000000..c0e9f59
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemFile.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.sys;
+
+public class SystemFile {
+    public static final int ObjectFileWriteBufferSize = 8*1024 ;
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemIndex.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemIndex.java
new file mode 100644
index 0000000..59076a4
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/sys/SystemIndex.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.sys;
+
+import org.apache.jena.dboe.DBOpEnvException;
+import org.apache.jena.dboe.base.block.FileMode;
+
+public class SystemIndex
+{
+    /** Size, in bytes, of a pointer between blocks */
+    public static final int SizeOfPointer           = Sys.SizeOfInt ;
+    
+    public static final boolean is64bitSystem       = Sys.is64bitSystem ;
+
+    // To make the class initialize
+    static public void init() {}
+    
+    /** Size, in bytes, of a block */
+    public static final int BlockSize               = 8*1024 ; // intValue("BlockSize", 8*1024) ;
+
+    /** Size, in bytes, of a block for testing */
+    public static final int BlockSizeTest           = 1024 ; // intValue("BlockSizeTest", 1024) ;
+
+    /** Size, in bytes, of a block for testing */
+    public static final int BlockSizeTestMem         = 500 ;
+
+//    /** Size, in bytes, of a memory block */
+//    public static final int BlockSizeMem            = 32*8 ; //intValue("BlockSizeMem", 32*8 ) ;
+
+    /** Order of an in-memory BTree or B+Tree */
+    public static final int OrderMem                = 5 ; // intValue("OrderMem", 5) ;
+    
+    /** Size, in bytes, of a segment (used for memory mapped files) */
+    public static final int SegmentSize             = 8*1024*1024 ; // intValue("SegmentSize", 8*1024*1024) ;
+    
+    // ---- Cache sizes (within the JVM)
+
+    /** Size of Node to NodeId cache.
+     *  Used to map from Node to NodeId spaces.
+     *  Used for loading and for query preparation.
+     */
+    public static final int Node2NodeIdCacheSize    = intValue("Node2NodeIdCacheSize", ( is64bitSystem ? 100*1000 : 50*1000 )) ;
+
+    /** Size of NodeId to Node cache.
+     *  Used to map from NodeId to Node spaces.
+     *  Used for retriveing results.
+     */
+    public static final int NodeId2NodeCacheSize    = intValue("NodeId2NodeCacheSize", ( is64bitSystem ? 500*1000 : 50*1000 ) ) ;
+    
+    /** Size of Node lookup miss cache. */
+    public static final int NodeMissCacheSize       = 100 ;
+    
+    /** Size of the delayed-write block cache (32 bit systems only) (per file) */
+    public static final int BlockWriteCacheSize     = intValue("BlockWriteCacheSize", 2*1000) ;
+
+    /** Size of read block cache (32 bit systems only).  Increase JVM size as necessary. Per file. */
+    public static final int BlockReadCacheSize      = intValue("BlockReadCacheSize", 10*1000) ;
+    
+    private static int intValue(String name, int dft) { return dft ; }
+    
+    
+    public static void setNullOut(boolean nullOut)
+    { NullOut = nullOut ; }
+
+    /** Are we nulling out unused space in bytebuffers (records, points etc) */ 
+    public static boolean getNullOut()
+    { return NullOut ; }
+
+    /** null out (with the FillByte) freed up space in buffers */
+    public static boolean NullOut = false ;
+    
+    /** FillByte value for NullOut */
+    public static final byte FillByte = (byte)0xFF ;
+
+    public static boolean Checking = false ;       // This isn't used enough!
+    
+    // ---- File mode
+    
+    private static FileMode fileMode = null ;
+    public static FileMode fileMode()
+    { 
+        if ( fileMode == null )
+            fileMode = determineFileMode() ;
+        return fileMode ;
+    }
+
+    public static void setFileMode(FileMode newFileMode)
+    {
+        if ( fileMode != null )
+        {
+            Sys.log.warn("System file mode already determined - setting it has no effect") ;
+            return ;
+        }
+        fileMode = newFileMode ;
+    }
+    
+    // So the test suite can setup thing up ... very carefully.
+    /*package*/ static void internalSetFileMode(FileMode newFileMode)
+    {
+        fileMode = newFileMode ;
+    }
+    
+    private static FileMode determineFileMode()
+    {
+        // Be careful that this is not called very, very early, before --set might be seen.
+        // Hence delayed access above in fileMode().
+        
+        //String x = ARQ.getContext().getAsString(SystemTDB.symFileMode, "default") ;
+        String x = "default" ;
+        
+        if ( x.equalsIgnoreCase("direct") )
+        {
+            Sys.syslog.info("File mode: direct (forced)") ;
+            return FileMode.direct ;
+        }
+        if ( x.equalsIgnoreCase("mapped") )
+        {
+            Sys.syslog.info("File mode: mapped (forced)") ;
+            return FileMode.mapped ;
+        }
+        
+        if ( x.equalsIgnoreCase("default") )
+        {
+            if ( is64bitSystem )
+            {
+                Sys.syslog.debug("File mode: Mapped") ;
+                return FileMode.mapped ;
+            }
+            Sys.syslog.debug("File mode: Direct") ;
+            return FileMode.direct ;
+        }
+        throw new DBOpEnvException("Unrecognized file mode (not one of 'default', 'direct' or 'mapped': "+x) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/BufferTestLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/BufferTestLib.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/BufferTestLib.java
new file mode 100644
index 0000000..9c0b5b6
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/BufferTestLib.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.test;
+
+import java.nio.ByteBuffer ;
+
+import org.apache.jena.dboe.base.block.Block;
+
+public class BufferTestLib
+{
+    public static boolean sameValue(Block block1, Block block2)
+    {
+        if ( block1.getId() != block2.getId()) return false ;
+        ByteBuffer bb1 = block1.getByteBuffer() ; 
+        ByteBuffer bb2 = block2.getByteBuffer() ;
+        
+        if ( bb1.capacity() != bb2.capacity() ) return false ;
+        
+        for ( int i = 0 ; i < bb1.capacity() ; i++ )
+            if ( bb1.get(i) != bb2.get(i) ) return false ;
+        return true ;
+    }
+    
+    public static boolean sameValue(ByteBuffer bb1, ByteBuffer bb2)
+    {
+        if ( bb1.capacity() != bb2.capacity() ) return false ;
+        
+        int posn1 = bb1.position();
+        int limit1 = bb1.limit();
+        int posn2 = bb2.position();
+        int limit2 = bb2.limit();
+        
+        bb1.clear() ;
+        bb2.clear() ;
+        
+        try {
+            for ( int i = 0 ; i < bb1.capacity() ; i++ )
+                if ( bb1.get(i) != bb2.get(i) ) return false ;
+            return true ;
+        } finally {
+            bb1.position(posn1) ;
+            bb1.limit(limit1) ;
+            bb2.position(posn2) ;
+            bb2.limit(limit2) ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/RecordLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/RecordLib.java b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/RecordLib.java
new file mode 100644
index 0000000..e29a193
--- /dev/null
+++ b/jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/test/RecordLib.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.test;
+
+
+import java.util.ArrayList ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.lib.Bytes ;
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.base.record.RecordFactory;
+
+/** Record support operations (mainly for testing using ints) */
+
+public class RecordLib
+{
+    // Size of a record when testing (one integer)
+    public final static int TestRecordLength = 4 ;
+    
+    public final static RecordFactory recordFactory    = new RecordFactory(TestRecordLength, 0) ; 
+    
+    public static Record intToRecord(int v) { return intToRecord(v, recordFactory) ; }
+    public static Record intToRecord(int v, int recLen) { return intToRecord(v, new RecordFactory(recLen, 0)) ; }
+    
+    public static Record intToRecord(int v, RecordFactory factory)
+    {
+        byte[] vb = Bytes.packInt(v) ;
+
+        int recLen = factory.recordLength() ;
+        byte[] bb = new byte[recLen] ;
+        int x = 0 ; // Start point in bb.
+        if ( recLen > 4 )
+            x = recLen-4 ;
+        
+        int len = Math.min(4, recLen) ;
+        int z = 4-len ; // Start point in vb
+    
+        // Furthest right bytes.
+        for ( int i = len-1 ; i >= 0 ; i-- ) 
+           bb[x+i] = vb[z+i] ; 
+        
+        return factory.create(bb) ;
+    }
+
+    public static List<Record> intToRecord(int[] v) { return intToRecord(v, recordFactory) ; }
+
+    public static List<Record> intToRecord(int[] v, int recLen)
+    { return intToRecord(v, new RecordFactory(recLen, 0)) ; }
+    
+    static List<Record> intToRecord(int[] v, RecordFactory factory)
+    {
+        List<Record> x = new ArrayList<>() ;
+        for ( int i : v )
+            x.add(intToRecord(i, factory)) ;
+        return x ;
+    }
+
+    public static int recordToInt(Record key)
+    {
+        return Bytes.getInt(key.getKey()) ;
+    }
+
+    public static List<Integer> toIntList(Iterator<Record> iter)
+    {
+        return Iter.toList(Iter.map(iter, item->recordToInt(item))) ;
+    }
+    
+    public static Record r(int v)
+    {
+        return RecordLib.intToRecord(v, RecordLib.TestRecordLength) ; 
+    }
+
+    public static int r(Record rec)
+    {
+        return RecordLib.recordToInt(rec) ; 
+    }
+
+    public static List<Integer> toIntList(int... vals)
+    {
+        List<Integer> x = new ArrayList<>() ;
+        for ( int i : vals )
+            x.add(i) ;
+        return x ;
+    }
+
+    public static List<Integer> r(Iterator<Record> iter)
+    {
+        return RecordLib.toIntList(iter) ;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/DBOpEnvException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/DBOpEnvException.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/DBOpEnvException.java
deleted file mode 100644
index eeac779..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/DBOpEnvException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe;
-
-import org.apache.jena.shared.JenaException;
-
-public class DBOpEnvException extends JenaException
-{
-    public DBOpEnvException()                          { super() ; }
-    public DBOpEnvException(String msg)                { super(msg) ; }
-    public DBOpEnvException(Throwable th)              { super(th) ; }
-    public DBOpEnvException(String msg, Throwable th)  { super(msg, th) ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/StorageException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/StorageException.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/StorageException.java
deleted file mode 100644
index 5f2d3b2..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/StorageException.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base;
-
-public class StorageException extends RuntimeException
-{
-    public StorageException()                          { super() ; }
-    public StorageException(String msg)                { super(msg) ; }
-    public StorageException(Throwable th)              { super(th) ; }
-    public StorageException(String msg, Throwable th)  { super(msg, th) ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/Block.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/Block.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/Block.java
deleted file mode 100644
index a5ad514..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/Block.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block;
-
-import java.io.ByteArrayOutputStream ;
-import java.io.PrintStream ;
-import java.nio.ByteBuffer ;
-import org.apache.jena.atlas.lib.ByteBufferLib ;
-
-public final class Block
-{
-    // XXX Note development code added to enforce read-only use. Marked [RO]
-    
-    // While the general mechanisms support long block id,
-    // some uses make restrictions.
-    // BlockMgrs:
-    //   Blocks for indexes (B+Trees) are addressed by int - one int is 2G of 8K units = 16T
-    // Blocks for objects are addressed by long - this is file offset so 2G is not enough. 
-    
-    private final Long id ;          // Keep as object.  It's the cache key.
-    //private BlockRef blockRef ;
-    
-
-    // These are information carrying flags -- not enforced
-    // although .write checks the readOnly flags.
-    private boolean readOnly = false ;
-    private boolean modified = false ;
-    
-    private /*[[Dev-RO]] final*/ ByteBuffer byteBuffer ;
-    // If the byteBuffer is, say, a slice of another one,
-    // this can be used to carry a ref to the real ByteBuffer.  
-    private ByteBuffer underlyingByteBuffer ;
-
-    public Block(long id, ByteBuffer byteBuffer) {
-        this(Long.valueOf(id), byteBuffer) ;
-    }
-
-    public Block(Long id, ByteBuffer byteBuffer) {
-        // ByteBuffer is whole disk space from byte 0 for this disk unit.
-        this.id = id ;
-        this.byteBuffer = byteBuffer ;
-        // this.blockRef = null ;
-        // Default - writeable, unmodified block.
-        this.readOnly = false ;
-        this.modified = false ;
-        this.underlyingByteBuffer = null ;
-    }
-
-    public final Long getId() {
-        return id ;
-    }
-
-    public final ByteBuffer getByteBuffer() {
-        return byteBuffer ;
-    }
-
-    public boolean isReadOnly() {
-        return readOnly ;
-    }
-
-    public void setReadOnly(boolean readonly) {
-        if ( readonly && modified )
-            throw new BlockException("Attempt to mark a modified block as read-only") ;
-        // Hard to force a read-only byte buffer because higher levels
-        // may slice this and have their own byte buffers or even 
-        // intBuffers etc.
-        this.readOnly = readonly ;
-    }
-
-    public boolean isModified() {
-        return modified ;
-    }
-
-    public void setModified(boolean modified) {
-        if ( readOnly && modified )
-            throw new BlockException("Attempt to mark a readonly block as modified") ;
-        this.modified = modified ;
-    }
-
-    public ByteBuffer getUnderlyingByteBuffer()
-    { return underlyingByteBuffer ; }
-
-    public void setUnderlyingByteBuffer(ByteBuffer underlyingByteBuffer)
-    { this.underlyingByteBuffer = underlyingByteBuffer ; }
-    
-    @Override
-    public String toString() {
-        ByteBuffer bb = getByteBuffer() ;
-        if ( true )
-            // Short form.
-            return String.format("Block: %d (posn=%d, limit=%d, cap=%d)", id, bb.position(), bb.limit(), bb.capacity()) ;
-        // Long form - with some bytes from the ByteBuffer.
-        ByteArrayOutputStream out = new ByteArrayOutputStream() ;
-        PrintStream x = new PrintStream(out) ;
-        ByteBufferLib.print(x, bb) ;
-        x.flush() ;
-        String str = out.toString() ;
-        return String.format("Block: %d %s", id, str) ;
-    }
-
-    /** Deep copy, including ByteBuffer contents into a HeapByteBuffer. */
-    public Block replicate() {
-        ByteBuffer dstBuffer = ByteBuffer.allocate(getByteBuffer().capacity()) ;
-        return replicate(dstBuffer) ;
-    }
-    
-    /**
-     * Deep copy, including ByteBuffer contents, using the supplied ByteBuffer
-     * to hold the contents and to be used when constructing the new Block. The
-     * capacity of the supplied ByteBuffer must be equal to or greater than this
-     * block's capacity.
-     */
-    private Block replicate(ByteBuffer dstBuffer) {
-        replicateByteBuffer(getByteBuffer(), dstBuffer) ;
-        Block b = new Block(getId(), dstBuffer) ;
-        b.setModified(modified) ;
-        b.setReadOnly(readOnly) ;
-        // b.blockRef = null ;
-        return b ;
-    }
-
-    public static void replicate(Block srcBlock, Block dstBlock) {
-        if ( !srcBlock.getId().equals(dstBlock.getId()) )
-            throw new BlockException("FileAccessMem: Attempt to copy across blocks: " + srcBlock.getId() + " => " + dstBlock.getId()) ;
-        replicate(srcBlock.getByteBuffer(), dstBlock.getByteBuffer()) ;
-    }
-
-    private static ByteBuffer replicateByteBuffer(ByteBuffer srcBlk, ByteBuffer dstBlk) {
-        int x = srcBlk.position() ;
-        int y = srcBlk.limit() ;
-        srcBlk.clear() ;
-
-        if ( srcBlk.hasArray() && dstBlk.hasArray() )
-            System.arraycopy(srcBlk.array(), 0, dstBlk.array(), 0, srcBlk.capacity()) ;
-        else
-            dstBlk.put(srcBlk) ;
-
-        srcBlk.position(x) ;
-        dstBlk.position(x) ;
-        srcBlk.limit(y) ;
-        dstBlk.limit(y) ;
-        return dstBlk ;
-    }
-
-    private static void replicate(ByteBuffer srcBlk, ByteBuffer dstBlk) {
-        srcBlk.position(0) ;
-        dstBlk.position(0) ;
-        dstBlk.put(srcBlk) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockException.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockException.java
deleted file mode 100644
index 8a950af..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block;
-
-import org.seaborne.dboe.base.file.FileException ;
-
-public class BlockException extends FileException
-{
-    public BlockException()                          { super() ; }
-    public BlockException(String msg)                { super(msg) ; }
-    public BlockException(Throwable th)              { super(th) ; }
-    public BlockException(String msg, Throwable th)  { super(msg, th) ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgr.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgr.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgr.java
deleted file mode 100644
index 641dc58..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgr.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block;
-
-import org.apache.jena.atlas.lib.Closeable ;
-import org.apache.jena.atlas.lib.Sync ;
-
-
-public interface BlockMgr extends Sync, Closeable /*UnitMgr<Block>*/
-{
-    /** Allocate an uninitialized block - writable - call only inside a update sequence. 
-     *  If blockSize is -1, means "default/fixed size" for this BlockMgr
-     */
-    public Block allocate(int blockSize) ;
-    
-    /** Answer whether there are any blocks in the collection being managed */
-    public boolean isEmpty() ; 
-    
-    /** The fixed allocated blocks are in the range [0,allocLimit).
-     * Allocation units need not be +1 increments */ 
-    public long allocLimit() ; 
-
-    /** Reset the allocation limit, should be a number previously obtained from allocLimit */
-    public void resetAlloc(long boundary) ;
-
-    /** Fetch a block, use for read only */
-    public Block getRead(long id);
-    
-    /** Fetch a block, use for write and read - only inside "update" */
-    public Block getWrite(long id);
-
-    /** Release a block, unmodified or already written. */
-    public void release(Block block) ;
-
-    /** Promote to writeable : it's OK to promote an already writeable block */ 
-    public Block promote(Block block);
-
-    // Bad name?  "endWrite", "put" -- for a mapped block, the changes are made directly, not on the write() */   
-    /** Write a block back - it still needs releasing. */ 
-    public void write(Block block) ;
-    
-    /** Replace the contents of a block slot with new contents. Block does not need releasing.
-     * The write() operation may not do real work if the block is mapped - this operation
-     * really does replace the contents with the new contents.  
-     */ 
-    public void overwrite(Block blk) ;
-    
-   /** Announce a block is no longer in use (i.e it's now freed) */ 
-    public void free(Block block);
-  
-    /** Is this a valid block id? (may be a free block)*/
-    public boolean valid(int id) ;
-    
-    /** Close the block manager */
-    @Override
-    public void close() ;
-    
-    /** Is this block manager still usable?  Closed block managers can not perform any operations except this one. */  
-    public boolean isClosed() ; 
-    
-    /** Sync the block manager */
-    @Override
-    public void sync() ;
-    
-    /** Sync the block manager : system operation to ensure sync() is passed down */
-    public void syncForce() ;
-
-    // begin/end markers.
-
-    /** Start of update */
-    public void beginUpdate() ;
-    
-    /** Completion of update */
-    public void endUpdate() ;
-
-    /** Start of read */
-    public void beginRead() ;
-
-    /** Completion of read */
-    public void endRead() ;
-
-    /* Label for helping trace which BlockMgr is which */
-    public String getLabel() ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBase.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBase.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBase.java
deleted file mode 100644
index 5e2581b..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBase.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block;
-
-import org.slf4j.Logger ;
-
-public abstract class BlockMgrBase implements BlockMgr
-{
-    protected final int blockSize ;
-    private String label ;
-    protected abstract Logger log() ;
-
-    // Fixed size, fixed block type.
-    protected BlockMgrBase(String label, int blockSize)
-    {
-        this.label = label ;
-        this.blockSize = blockSize ;
-    }
-
-    @Override
-    public final Block allocate(int blkSize)
-    {
-        if ( blkSize > 0 && blkSize != this.blockSize )
-            throw new BlockException("Fixed blocksize BlockMgr: request= "+blkSize+"  fixed size="+this.blockSize) ;
-        return allocate() ;
-    }
-    
-    protected abstract Block allocate() ;
-    
-    @Override final public String getLabel() { return label ; } 
-
-    @Override public void endUpdate()       {}
-    @Override public void beginUpdate()     {}
-    @Override public void beginRead()       {}
-    @Override public void endRead()         {}
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilder.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilder.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilder.java
deleted file mode 100644
index 1c5ede7..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block;
-
-import org.seaborne.dboe.base.file.FileSet ;
-
-public interface BlockMgrBuilder {
-    BlockMgr buildBlockMgr(FileSet fileSet, String ext, BlockParams indexParams) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilderStd.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilderStd.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilderStd.java
deleted file mode 100644
index 47bb37e..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrBuilderStd.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block;
-
-import org.seaborne.dboe.base.file.FileSet ;
-
-public class BlockMgrBuilderStd implements BlockMgrBuilder {
-    @Override
-    public BlockMgr buildBlockMgr(FileSet fileSet, String ext, BlockParams indexParams) {
-        return BlockMgrFactory.create(fileSet, ext, indexParams) ;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrCache.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrCache.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrCache.java
deleted file mode 100644
index 1f0e7c1..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrCache.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block ;
-
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.lib.Cache ;
-import org.apache.jena.atlas.lib.CacheFactory ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/** Caching block manager - this is an LRU cache */
-public class BlockMgrCache extends BlockMgrSync {
-    // Actually, this is two cache one on the read blocks and one on the write
-    // blocks.
-    // The overridden public operations are sync'ed.
-    // As sync is on "this", it also covers all the other operations via
-    // BlockMgrSync
-
-    private static Logger            log            = LoggerFactory.getLogger(BlockMgrCache.class) ;
-    // Read cache : always present.
-    private final Cache<Long, Block> readCache ;
-
-    // Delayed dirty writes. May be present, may not.
-    private final Cache<Long, Block> writeCache ;
-
-    // Also enable the logging level.
-    public static boolean            globalLogging  = false ;    
-    private boolean                  logging        = false ;
-    // ---- stats
-    long                             cacheReadHits  = 0 ;
-    long                             cacheMisses    = 0 ;
-    long                             cacheWriteHits = 0 ;
-
-    static BlockMgr create(int readSlots, int writeSlots, final BlockMgr blockMgr) {
-        if ( readSlots < 0 && writeSlots < 0 )
-            return blockMgr ;
-        return new BlockMgrCache(readSlots, writeSlots, blockMgr) ;
-    }
-
-    private BlockMgrCache(int readSlots, int writeSlots, final BlockMgr blockMgr) {
-        super(blockMgr) ;
-        // Caches are related so we can't use a Getter for cache management.
-        if ( readSlots < -1 )
-            readCache = CacheFactory.createNullCache() ;
-        else
-            readCache = CacheFactory.createCache(readSlots) ;
-        if ( writeSlots <= 0 )
-            writeCache = null ;
-        else {
-            writeCache = CacheFactory.createCache(writeSlots) ;
-            writeCache.setDropHandler((id, block) -> { 
-                // We're inside a synchronized operation at this point.
-                log("Cache spill: write block: %d", id) ;
-                if ( block == null ) {
-                    log.warn("Write cache: " + id + " dropping an entry that isn't there") ;
-                    return ;
-                }
-                // Force the block to be writtern
-                // by sending it to the wrapped BlockMgr
-                BlockMgrCache.super.write(block) ;
-            }) ;
-        }
-    }
-
-    @Override
-    synchronized public void resetAlloc(long boundary) {
-        // On abort, need to clear the caches of inaccesible blocks.
-        // An abort is rare (?). We do very carefully. 
-        // Could (probably) delete in the loop or use Iteator.remove on keys().
-        // (Check the Cache contract)
-        List<Long> removals = new ArrayList<>() ;
-        readCache.keys().forEachRemaining((x)->{
-            if ( x >= boundary )
-                removals.add(x) ; 
-        }) ;
-        removals.forEach(readCache::remove) ;
-        removals.clear() ;
-        writeCache.keys().forEachRemaining((x)->{
-            if ( x >= boundary )
-                removals.add(x) ; 
-        }) ;
-        removals.forEach(writeCache::remove) ;
-        super.resetAlloc(boundary); 
-    }
-    
-    @Override
-    synchronized public Block getRead(long id) {
-        // A Block may be in the read cache or the write cache.
-        // It can be just in the write cache because the read cache is finite.
-        Block blk = readCache.getIfPresent(id) ;
-        if ( blk != null ) {
-            cacheReadHits++ ;
-            log("Hit(r->r) : %d", id) ;
-            return blk ;
-        }
-
-        // A requested block may be in the other cache.
-        // Writable blocks are readable.
-        // readable blocks are not writeable (see below).
-        if ( writeCache != null )
-            // Might still be in the dirty blocks.
-            // Leave in write cache
-            blk = writeCache.getIfPresent(id) ;
-        if ( blk != null ) {
-            cacheWriteHits++ ;
-            log("Hit(r->w) : %d", id) ;
-            return blk ;
-        }
-
-        cacheMisses++ ;
-        log("Miss/r: %d", id) ;
-        blk = super.getRead(id) ;
-        readCache.put(id, blk) ;
-        return blk ;
-    }
-
-    @Override
-    synchronized public Block getWrite(long _id) {
-        Long id = _id ;
-        Block blk = null ;
-        if ( writeCache != null )
-            blk = writeCache.getIfPresent(id) ;
-        if ( blk != null ) {
-            cacheWriteHits++ ;
-            log("Hit(w->w) : %d", id) ;
-            return blk ;
-        }
-
-        // blk is null.
-        // A requested block may be in the other cache. Promote it.
-
-        if ( readCache.containsKey(id) ) {
-            blk = readCache.getIfPresent(id) ;
-            cacheReadHits++ ;
-            log("Hit(w->r) : %d", id) ;
-            blk = promote(blk) ;
-            return blk ;
-        }
-
-        // Did not find.
-        cacheMisses++ ;
-        log("Miss/w: %d", id) ;
-        // Pass operation to wrapper.
-        blk = super.getWrite(id) ;
-        if ( writeCache != null )
-            writeCache.put(id, blk) ;
-        return blk ;
-    }
-
-    @Override
-    synchronized public Block promote(Block block) {
-        Long id = block.getId() ;
-        readCache.remove(id) ;
-        Block block2 = super.promote(block) ;
-        if ( writeCache != null )
-            writeCache.put(id, block2) ;
-        return block ;
-    }
-
-    @Override
-    synchronized public void write(Block block) {
-        writeCache(block) ;
-        super.write(block) ;
-    }
-
-    @Override
-    synchronized public void overwrite(Block block) {
-        Long id = block.getId() ;
-        // It can be a read block (by the transaction), now being written for
-        // real (enacting a transaction).
-        super.overwrite(block) ;
-        // Keep read cache up-to-date.
-        // Must at least expel the read block (which is not the overwrite
-        // block).
-        readCache.put(id, block) ;
-    }
-
-    private void writeCache(Block block) {
-        Long id = block.getId() ;
-        log("WriteCache : %d", id) ;
-        // Should not be in the read cache due to a getWrite earlier.
-        if ( readCache.containsKey(id) )
-            log.warn("write: Block in the read cache") ;
-        if ( writeCache != null ) {
-            writeCache.put(id, block) ;
-            return ;
-        }
-    }
-
-    @Override
-    synchronized public void free(Block block) {
-        Long id = block.getId() ;
-        log("Free  : %d", id) ;
-        if ( readCache.containsKey(id) ) {
-            log.warn("Freeing block from read cache") ;
-            readCache.remove(id) ;
-        }
-        if ( writeCache != null )
-            writeCache.remove(id) ;
-        super.free(block) ;
-    }
-
-    @Override
-    synchronized public void sync() {
-        _sync(false) ;
-    }
-
-    @Override
-    synchronized public void syncForce() {
-        _sync(true) ;
-    }
-
-    @Override
-    synchronized public void close() {
-        if ( writeCache != null )
-            log("close (" + writeCache.size() + " blocks)") ;
-        syncFlush() ;
-        super.close() ;
-    }
-
-    @Override
-    public String toString() {
-        return "Cache:" + super.blockMgr.toString() ;
-    }
-
-    private void log(String fmt, Object... args) {
-        if ( !logging && !globalLogging )
-            return ;
-        String msg = String.format(fmt, args) ;
-        if ( getLabel() != null )
-            msg = getLabel() + " : " + msg ;
-        log.debug(msg) ;
-    }
-
-    private void _sync(boolean force) {
-        if ( true ) {
-            String x = "" ;
-            if ( getLabel() != null )
-                x = getLabel() + " : " ;
-            log("%sH=%d, M=%d, W=%d", x, cacheReadHits, cacheMisses, cacheWriteHits) ;
-        }
-
-        if ( writeCache != null )
-            log("sync (%d blocks)", writeCache.size()) ;
-        else
-            log("sync") ;
-        boolean somethingWritten = syncFlush() ;
-
-        if ( force ) {
-            log("syncForce underlying BlockMgr") ;
-            super.syncForce() ;
-        } else if ( somethingWritten ) {
-            log("sync underlying BlockMgr") ;
-            super.sync() ;
-        } else
-            log("Empty sync") ;
-    }
-
-    private boolean syncFlush() {
-        if ( writeCache == null )
-            return false ;
-
-        boolean didSync = false ;
-
-        log("Flush (write cache)") ;
-
-        long N = writeCache.size() ;
-        Long[] ids = new Long[(int)N] ;
-
-        // Single writer (sync is a write operation MRSW)
-        // Iterating is safe.
-
-        Iterator<Long> iter = writeCache.keys() ;
-        if ( iter.hasNext() )
-            didSync = true ;
-
-        // Need to get all then delete else concurrent modification exception.
-        for ( int i = 0 ; iter.hasNext() ; i++ )
-            ids[i] = iter.next() ;
-
-        for ( int i = 0 ; i < N ; i++ ) {
-            Long id = ids[i] ;
-            expelEntry(id) ;
-        }
-        if ( didSync )
-            super.sync() ;
-        return didSync ;
-    }
-
-    // Write out when flushed.
-    // Do not call from drop handler.
-    private void expelEntry(Long id) {
-        Block block = writeCache.getIfPresent(id) ;
-        if ( block == null ) {
-            log.warn("Write cache: " + id + " expelling entry that isn't there") ;
-            return ;
-        }
-        log("Expel (write cache): %d", id) ;
-        // This pushes the block to the BlockMgr being cached.
-        super.write(block) ;
-        writeCache.remove(id) ;
-
-        // Move it into the readCache because it's often read after writing
-        // and the read cache is often larger.
-        readCache.put(id, block) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFactory.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFactory.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFactory.java
deleted file mode 100644
index 8515cbe..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFactory.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block ;
-
-import org.apache.jena.atlas.logging.Log ;
-import org.seaborne.dboe.DBOpEnvException ;
-import org.seaborne.dboe.base.file.* ;
-import org.seaborne.dboe.sys.SystemIndex ;
-
-public class BlockMgrFactory {
-    // This isn't always helpful so be careful if setting the default to "true".
-    // Sometimes the tracking is too strict
-    // e.g. transactions keep blocks and not release them down the layers.
-    public/* final */static boolean AddTracker = false ;
-
-    public static BlockMgr tracker(BlockMgr blockMgr) {
-        if ( blockMgr instanceof BlockMgrTracker )
-            return blockMgr ;
-        return BlockMgrTracker.track(blockMgr) ;
-    }
-
-    /** Add a tracker if the system default is to do so */
-    private static BlockMgr track(BlockMgr blockMgr) {
-        if ( !AddTracker )
-            return blockMgr ;
-        return tracker(blockMgr) ;
-    }
-
-    public static BlockMgr create(FileSet fileSet, String ext, BlockParams params) {
-        return create(fileSet, ext,
-                      params.getFileMode(),
-                      params.getBlockSize(),
-                      params.getBlockReadCacheSize(),
-                      params.getBlockWriteCacheSize()) ;
-    }
-    
-    public static BlockMgr create(FileSet fileSet, String ext, int blockSize, int readBlockCacheSize, int writeBlockCacheSize) {
-        return create(fileSet, ext, null, blockSize, readBlockCacheSize, writeBlockCacheSize) ;
-    }
-
-    // XXX Deprecate?
-    public static BlockMgr create(FileSet fileSet, String ext, FileMode fileMode, int blockSize, int readBlockCacheSize, int writeBlockCacheSize) {
-        if ( fileSet.isMem() )
-            return createMem(fileSet.filename(ext), blockSize) ;
-        else
-            return createFile(fileSet.filename(ext), fileMode, blockSize, readBlockCacheSize, writeBlockCacheSize) ;
-    }
-
-    /** Create an in-memory block manager */
-    public static BlockMgr createMem(String indexName, int blockSize) {
-        BlockAccess file = new BlockAccessMem(indexName, blockSize) ;
-        BlockMgr blockMgr = new BlockMgrFileAccess(file, blockSize) ;
-        blockMgr = new BlockMgrFreeChain(blockMgr) ;
-        // Small cache - testing.
-        blockMgr = BlockMgrCache.create(3, 3, blockMgr) ;
-        return track(blockMgr) ;
-    }
-
-    /** Create a BlockMgr backed by a real file */
-    public static BlockMgr createFile(String filename, BlockParams params) {
-        return createFile(filename, 
-                          params.getFileMode(), params.getBlockSize(),
-                          params.getBlockReadCacheSize(), params.getBlockWriteCacheSize()) ;
-    }
-
-        /** Create a BlockMgr backed by a real file */
-    public static BlockMgr createFile(String filename, FileMode fileMode, int blockSize, int readBlockCacheSize, int writeBlockCacheSize) {
-        if ( fileMode == null )
-            fileMode = SystemIndex.fileMode() ;
-        switch (fileMode) {
-            case mapped :
-                return createMMapFile(filename, blockSize) ;
-            case direct :
-                return createStdFile(filename, blockSize, readBlockCacheSize, writeBlockCacheSize) ;
-        }
-        throw new DBOpEnvException("Unknown file mode: " + fileMode) ;
-    }
-
-    /** Create a NIO Block Manager */
-    public static BlockMgr createMMapFile(String filename, int blockSize) {
-        BlockAccess file = new BlockAccessMapped(filename, blockSize) ;
-        BlockMgr blockMgr = wrapFileAccess(file, blockSize) ;
-        return track(blockMgr) ;
-    }
-
-    /** Create a Block Manager using direct access (and a cache) */
-    public static BlockMgr createStdFile(String filename, int blockSize, int readBlockCacheSize, int writeBlockCacheSize) {
-        BlockAccess file = new BlockAccessDirect(filename, blockSize) ;
-        BlockMgr blockMgr = wrapFileAccess(file, blockSize) ;
-        blockMgr = addCache(blockMgr, readBlockCacheSize, writeBlockCacheSize) ;
-        return track(blockMgr) ;
-    }
-
-    /** Create a Block Manager using direct access, no caching, no nothing. */
-    public static BlockMgr createStdFileNoCache(String filename, int blockSize) {
-        BlockAccess blockAccess = new BlockAccessDirect(filename, blockSize) ;
-        BlockMgr blockMgr = new BlockMgrFileAccess(blockAccess, blockSize) ;
-        return blockMgr ;
-    }
-
-    /**
-     * Add a caching layer to a BlockMgr.
-     * <p>
-     * This does not make sense for memory BlockMgr or for memory mapper files.
-     * This function always add the cache.
-     * 
-     * @see #addCache(BlockMgr, FileSet, FileMode, int, int)
-     */
-    public static BlockMgr addCache(BlockMgr blockMgr, int readBlockCacheSize, int writeBlockCacheSize) {
-        if ( blockMgr instanceof BlockMgrCache )
-            Log.warn(BlockMgrFactory.class, "BlockMgr already has a cache: " + blockMgr.getLabel()) ;
-        return BlockMgrCache.create(readBlockCacheSize, writeBlockCacheSize, blockMgr) ;
-    }
-
-    /**
-     * Add a caching layer to a BlockMgr if appropriate. This does not make
-     * sense for memory BlockMgr or for memory mapper files. These are skipped.
-     */
-    public static BlockMgr addCache(BlockMgr blockMgr, FileSet fileSet, FileMode fileMode, int readBlockCacheSize, int writeBlockCacheSize) {
-        if ( fileSet.isMem() )
-            return blockMgr ;
-        if ( fileMode == null )
-            fileMode = SystemIndex.fileMode() ;
-        if ( fileMode == FileMode.mapped )
-            return blockMgr ;
-        return addCache(blockMgr, readBlockCacheSize, writeBlockCacheSize) ;
-    }
-
-    private static BlockMgr wrapFileAccess(BlockAccess blockAccess, int blockSize) {
-        BlockMgr blockMgr = new BlockMgrFileAccess(blockAccess, blockSize) ;
-        // This is a temporary fix to the problem
-        blockMgr = new BlockMgrFreeChain(blockMgr) ;
-        return blockMgr ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFileAccess.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFileAccess.java b/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFileAccess.java
deleted file mode 100644
index 796c634..0000000
--- a/jena-db/jena-dboe-base/src/main/java/org/seaborne/dboe/base/block/BlockMgrFileAccess.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.base.block ;
-
-import static java.lang.String.format ;
-
-import org.apache.jena.atlas.lib.InternalErrorException ;
-import org.apache.jena.atlas.lib.Lib ;
-import org.seaborne.dboe.base.file.BlockAccess ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/**
- * Block manager that maps from the FileAccess layer to a BlockMgr. Add free
- * block management (but we should layer with BlockMgrFreeChain)
- */
-
-final public class BlockMgrFileAccess extends BlockMgrBase {
-    private static Logger     log        = LoggerFactory.getLogger(BlockMgrFileAccess.class) ;
-
-    private final BlockAccess file ;
-    private boolean           closed     = false ;
-    // Set on any write operations.
-    private boolean           syncNeeded = false ;
-
-    // Create via the BlockMgrFactory.
-    /* package */BlockMgrFileAccess(BlockAccess blockAccess, int blockSize) {
-        super(blockAccess.getLabel(), blockSize) ;
-        file = blockAccess ;
-    }
-
-    @Override
-    protected Block allocate() {
-        syncNeeded = true ;
-        return file.allocate(blockSize) ;
-    }
-
-    @Override
-    public Block promote(Block block) {
-        return block ;
-    }
-
-    @Override
-    public Block getRead(long id) {
-        return getBlock(id, true) ;
-    }
-
-    @Override
-    public Block getWrite(long id) {
-        return getBlock(id, false) ;
-    }
-
-    private Block getBlock(long id, boolean readOnly) {
-        checkNotClosed() ;
-        Block block = file.read(id) ;
-        block.setReadOnly(readOnly) ;
-        return block ;
-    }
-
-    private void checkNotClosed() {
-        if ( closed )
-            throw new InternalErrorException(Lib.className(this)+" : already closed") ;
-    }
-
-    @Override
-    public void release(Block block) {
-        checkNotClosed() ;
-    }
-
-    @Override
-    public void write(Block block) {
-        checkNotClosed() ;
-        if ( block.isReadOnly() )
-            throw new BlockException("Attempt to write a read-only block ("+block.getId()+")" ) ;
-        syncNeeded = true ;
-        file.write(block) ;
-    }
-
-    @Override
-    public void overwrite(Block block) {
-        checkNotClosed() ;
-        syncNeeded = true ;
-        file.overwrite(block) ;
-    }
-
-    @Override
-    public void free(Block block) {
-        checkNotClosed() ;
-        // syncNeeded = true ;
-        // We do nothing about free blocks currently.
-    }
-
-    @Override
-    public boolean valid(int id) {
-        checkNotClosed() ;
-        return file.valid(id) ;
-    }
-
-    @Override
-    public void sync() {
-        checkNotClosed() ;
-        if ( syncNeeded )
-            file.sync() ;
-        else
-            syncNeeded = true ;
-        syncNeeded = false ;
-    }
-
-    @Override
-    public void syncForce() {
-        checkNotClosed() ;
-        file.sync() ;
-    }
-
-    @Override
-    public boolean isClosed() {
-        return closed ;
-    }
-
-    @Override
-    public void close() {
-        closed = true ;
-        file.close() ;
-    }
-
-    @Override
-    public boolean isEmpty() {
-        checkNotClosed() ;
-        return file.isEmpty() ;
-    }
-    
-    @Override
-    public long allocLimit() {
-        checkNotClosed() ;
-        return file.allocBoundary() ;
-    }
-    
-    @Override
-    public void resetAlloc(long boundary) {
-        checkNotClosed() ;
-        file.resetAllocBoundary(boundary);
-    }
-
-    @Override
-    public String toString() {
-        return format("BlockMgrFileAccess[%d bytes]:%s", blockSize, file) ;
-    }
-
-    @Override
-    protected Logger log() {
-        return log ;
-    }
-}


Mime
View raw message