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 2015/09/18 11:21:22 UTC

[1/8] jena git commit: Make Turtle legal.

Repository: jena
Updated Branches:
  refs/heads/Jena-1029_subsystem [created] 68a769098


Make Turtle legal.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8389829d
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8389829d
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8389829d

Branch: refs/heads/Jena-1029_subsystem
Commit: 8389829d6ae15ad0a2a0214b72035283d110d69e
Parents: 53ceeaf
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Sep 17 16:06:53 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Sep 17 16:06:53 2015 +0100

----------------------------------------------------------------------
 .../resources/org/apache/jena/permissions/SecuredAssemblerTest.ttl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/8389829d/jena-permissions/src/test/resources/org/apache/jena/permissions/SecuredAssemblerTest.ttl
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/resources/org/apache/jena/permissions/SecuredAssemblerTest.ttl b/jena-permissions/src/test/resources/org/apache/jena/permissions/SecuredAssemblerTest.ttl
index b1313e6..8e31231 100644
--- a/jena-permissions/src/test/resources/org/apache/jena/permissions/SecuredAssemblerTest.ttl
+++ b/jena-permissions/src/test/resources/org/apache/jena/permissions/SecuredAssemblerTest.ttl
@@ -5,7 +5,7 @@
 @prefix ja:         <http://jena.hpl.hp.com/2005/11/Assembler#> .
 @prefix sec:		<http://apache.org/jena/permissions/Assembler#> .
 @prefix my:         <http://apache.org/jena/permissions/test#> .
-@prefix xsd:        <http://www.w3.org/2001/XMLSchema#>
+@prefix xsd:        <http://www.w3.org/2001/XMLSchema#> .
 
 <>	ja:loadClass	"org.apache.jena.permissions.SecuredAssembler" .
 


[2/8] jena git commit: Add clear()

Posted by an...@apache.org.
Add clear()

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/df1f1f4d
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/df1f1f4d
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/df1f1f4d

Branch: refs/heads/Jena-1029_subsystem
Commit: df1f1f4dc69c89006247a313838b77ad2129d3e3
Parents: 8389829
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Sep 17 16:56:17 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Sep 17 16:56:17 2015 +0100

----------------------------------------------------------------------
 jena-base/src/main/java/org/apache/jena/atlas/lib/Registry.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/df1f1f4d/jena-base/src/main/java/org/apache/jena/atlas/lib/Registry.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/Registry.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/Registry.java
index b04d9d9..5288844 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/lib/Registry.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/Registry.java
@@ -37,6 +37,7 @@ public class Registry<K,T>
     //public Iterator<String> keys()      { return registry.keySet().iterator() ; }
     public int size()                   { return registry.size() ; }
     public boolean isEmpty()            { return registry.isEmpty() ; }
+    public void clear()                 { registry.clear() ; }
     public void forEach(BiConsumer<K, T> action) {
         registry.forEach(action); 
     }


[6/8] jena git commit: JENA-1029: Remove unnecessary .init() calls

Posted by an...@apache.org.
JENA-1029: Remove unnecessary .init() calls


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/15ced7e8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/15ced7e8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/15ced7e8

Branch: refs/heads/Jena-1029_subsystem
Commit: 15ced7e893926d5d71481e27701c37fb2f1c5870
Parents: 55a8eab
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Sep 18 08:35:15 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Sep 18 08:35:15 2015 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/jena/query/ARQ.java  |  1 -
 .../jena/system/JenaSubsystemLifecycle.java       |  3 +++
 .../java/org/apache/jena/fuseki/FusekiCmd.java    | 13 +++++--------
 .../apache/jena/fuseki/server/FusekiConfig.java   |  5 +----
 .../main/java/org/apache/jena/fuseki/Fuseki.java  |  9 ---------
 .../jena/permissions/graph/TDBGraphTest.java      |  1 -
 .../main/java/examples/JenaSpatialExample1.java   |  2 --
 .../src/main/java/jena/spatialindexdump.java      |  8 +++-----
 .../src/main/java/jena/spatialindexer.java        |  8 +++-----
 .../jena/query/spatial/SpatialDatasetFactory.java |  3 ++-
 .../jena/query/spatial/SpatialSearchUtil.java     |  3 ---
 .../src/main/java/org/apache/jena/tdb/TDB.java    |  4 ++--
 .../jena/tdb/assembler/TDBGraphAssembler.java     | 18 +++++++++---------
 .../src/main/java/examples/JenaTextExample1.java  |  2 --
 jena-text/src/main/java/jena/textindexdump.java   |  1 -
 jena-text/src/main/java/jena/textindexer.java     |  1 -
 .../jena/query/text/TextDatasetFactory.java       |  3 ++-
 .../jena/query/text/TestBuildTextDataset.java     |  7 -------
 .../TestDatasetWithEmbeddedSolrTextIndex.java     |  1 -
 19 files changed, 30 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
index dfef428..adbf742 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
@@ -530,7 +530,6 @@ public class ARQ
 
     /** Ensure things have started - applications do not need call this.
      * The method is public so any part of ARQ can call it.
-     * Note the final static initializer call 
      */
     
     static { JenaSystem.init(); }

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
index daf6b2a..a3cd771 100644
--- a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
@@ -20,10 +20,13 @@ package org.apache.jena.system;
 
 /** Lifecycle interface for jena modules and subsystems. */ 
 public interface JenaSubsystemLifecycle {
+    
     /** start - a module should be ready to oeprate when this returns */  
     public void start() ;
+    
     /** stop - a module should have preformed any shutdown operations by the time this returns */   
     public void stop() ;
+    
     /** Provide a marker as to the level to order initialization, 10,20,30,... 
      * See {@link JenaSystem} for details.
      */

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-fuseki1/src/main/java/org/apache/jena/fuseki/FusekiCmd.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/FusekiCmd.java b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/FusekiCmd.java
index 6baf5d9..5598073 100644
--- a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/FusekiCmd.java
+++ b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/FusekiCmd.java
@@ -25,6 +25,10 @@ import java.io.InputStream ;
 import java.util.List ;
 import java.util.Objects;
 
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModDatasetAssembler ;
+import jena.cmd.ArgDecl ;
+import jena.cmd.CmdException ;
 import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.atlas.lib.FileOps ;
 import org.apache.jena.atlas.lib.StrUtils ;
@@ -48,11 +52,6 @@ import org.apache.jena.tdb.transaction.TransactionManager ;
 import org.eclipse.jetty.server.Server ;
 import org.slf4j.Logger ;
 
-import jena.cmd.ArgDecl ;
-import jena.cmd.CmdException ;
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModDatasetAssembler ;
-
 public class FusekiCmd extends CmdARQ
 {
     private static String log4Jsetup = StrUtils.strjoinNL(
@@ -157,9 +156,7 @@ public class FusekiCmd extends CmdARQ
 
     static public void main(String...argv)
     {
-        // Just to make sure ...
-        ARQ.init() ;
-        TDB.init() ;
+        // Just to make sure ...s
         Fuseki.init() ;
         new FusekiCmd(argv).mainRun() ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/FusekiConfig.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/FusekiConfig.java b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/FusekiConfig.java
index 18efa5d..0eb7b5d 100644
--- a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/FusekiConfig.java
+++ b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/FusekiConfig.java
@@ -37,7 +37,6 @@ import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.DatasetGraphFactory ;
 import org.apache.jena.sparql.core.DatasetGraphReadOnly ;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
-import org.apache.jena.tdb.TDB ;
 import org.apache.jena.util.FileManager ;
 import org.apache.jena.vocabulary.RDF ;
 import org.apache.jena.vocabulary.RDFS ;
@@ -103,9 +102,7 @@ public class FusekiConfig
     public static ServerConfig configure(String filename)
     {
         // Be absolutely sure everything has initialized.
-        // Some initialization registers assemblers and sets abbreviation vocabulary. 
-        ARQ.init();
-        TDB.init() ;
+        // Some initialization registers assemblers and sets abbreviation vocabulary.
         Fuseki.init() ;
         Model m = FileManager.get().loadModel(filename) ;
 

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
index 991c673..8472422 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
@@ -220,15 +220,6 @@ public class Fuseki {
         FusekiLogging.setLogging() ;
         SystemInfo sysInfo = new SystemInfo(FusekiIRI, PATH, VERSION, BUILD_DATE) ;
         SystemARQ.registerSubSystem(sysInfo) ;
-        TDB.init() ;
-        // Initialize anyway (e.g. not to rely on assembler magic).
-        try { 
-            TextQuery.init() ;
-            SpatialQuery.init() ;
-        } catch ( Exception ex ) {
-            // In case jars are missing.
-        }
-        
         MappingRegistry.addPrefixMapping("fuseki", FusekiSymbolIRI) ;
 
         TDB.setOptimizerWarningFlag(false) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-permissions/src/test/java/org/apache/jena/permissions/graph/TDBGraphTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/graph/TDBGraphTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/graph/TDBGraphTest.java
index 09488b9..49326a3 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/graph/TDBGraphTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/graph/TDBGraphTest.java
@@ -36,7 +36,6 @@ public class TDBGraphTest extends MemGraphTest {
 
 	@Override
 	protected Graph createGraph() throws IOException {
-		TDB.init();
 		dsGraph = TDBFactory.createDataset().asDatasetGraph();
 		return dsGraph.getDefaultGraph();
 	}

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-spatial/src/main/java/examples/JenaSpatialExample1.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/examples/JenaSpatialExample1.java b/jena-spatial/src/main/java/examples/JenaSpatialExample1.java
index 1bdabee..5adc33d 100644
--- a/jena-spatial/src/main/java/examples/JenaSpatialExample1.java
+++ b/jena-spatial/src/main/java/examples/JenaSpatialExample1.java
@@ -95,14 +95,12 @@ public class JenaSpatialExample1 {
     }
     
     private static Dataset initInMemoryDatasetWithLuceneSpatitalIndex(File indexDir) throws IOException{
-		SpatialQuery.init();
 		deleteOldFiles(indexDir);
 		indexDir.mkdirs();
 		return createDatasetByCode(indexDir);
     }
     
     private static Dataset initTDBDatasetWithLuceneSpatitalIndex(File indexDir, File TDBDir) throws IOException{
-		SpatialQuery.init();
 		deleteOldFiles(indexDir);
 		deleteOldFiles(TDBDir);
 		indexDir.mkdirs();

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-spatial/src/main/java/jena/spatialindexdump.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/jena/spatialindexdump.java b/jena-spatial/src/main/java/jena/spatialindexdump.java
index 65b51bc..904637c 100644
--- a/jena-spatial/src/main/java/jena/spatialindexdump.java
+++ b/jena-spatial/src/main/java/jena/spatialindexdump.java
@@ -18,11 +18,13 @@
 
 package jena ;
 
+import arq.cmdline.CmdARQ ;
+import jena.cmd.ArgDecl ;
+import jena.cmd.CmdException ;
 import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.query.spatial.SpatialIndex ;
 import org.apache.jena.query.spatial.SpatialIndexException ;
 import org.apache.jena.query.spatial.SpatialIndexLucene ;
-import org.apache.jena.query.spatial.SpatialQuery ;
 import org.apache.jena.query.spatial.assembler.SpatialVocab ;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
 import org.apache.lucene.analysis.Analyzer ;
@@ -37,9 +39,6 @@ import org.apache.lucene.search.ScoreDoc ;
 import org.apache.lucene.store.Directory ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
-import jena.cmd.ArgDecl ;
-import jena.cmd.CmdException ;
-import arq.cmdline.CmdARQ ;
 
 /**
  * Text index development tool - dump the index.
@@ -52,7 +51,6 @@ public class spatialindexdump extends CmdARQ {
     protected SpatialIndex        spatialIndex    = null ;
 
     static public void main(String... argv) {
-        SpatialQuery.init() ;
         new spatialindexdump(argv).mainRun() ;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-spatial/src/main/java/jena/spatialindexer.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/jena/spatialindexer.java b/jena-spatial/src/main/java/jena/spatialindexer.java
index d9a55bd..af8ed56 100644
--- a/jena-spatial/src/main/java/jena/spatialindexer.java
+++ b/jena-spatial/src/main/java/jena/spatialindexer.java
@@ -20,19 +20,18 @@ package jena;
 
 import java.util.Iterator;
 
+import arq.cmdline.CmdARQ;
+import jena.cmd.ArgDecl ;
+import jena.cmd.CmdException ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.query.spatial.DatasetGraphSpatial;
 import org.apache.jena.query.spatial.SpatialDatasetFactory;
 import org.apache.jena.query.spatial.SpatialIndex;
 import org.apache.jena.query.spatial.SpatialIndexContext;
-import org.apache.jena.query.spatial.SpatialQuery;
 import org.apache.jena.sparql.core.Quad ;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import jena.cmd.ArgDecl ;
-import jena.cmd.CmdException ;
-import arq.cmdline.CmdARQ;
 
 /**
  * Spatial indexer application that will read a dataset and index its triples in
@@ -51,7 +50,6 @@ public class spatialindexer extends CmdARQ {
 	protected ProgressMonitor progressMonitor;
 		
 	static public void main(String... argv) {
-		SpatialQuery.init();
 		new spatialindexer(argv).mainRun();
 	}
 

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
index beb0cf9..890a4f4 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialDatasetFactory.java
@@ -24,12 +24,13 @@ import org.apache.jena.query.spatial.assembler.SpatialVocab;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
 import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.lucene.store.Directory;
 import org.apache.solr.client.solrj.SolrServer;
 
 public class SpatialDatasetFactory
 {
-    static { SpatialQuery.init(); }
+    static { JenaSystem.init(); }
     
     /** Use an assembler file to build a dataset with spatial search capabilities */ 
     public static Dataset create(String assemblerFile)

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java b/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
index 6c4fba7..493ad11 100644
--- a/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
+++ b/jena-spatial/src/test/java/org/apache/jena/query/spatial/SpatialSearchUtil.java
@@ -76,7 +76,6 @@ public class SpatialSearchUtil {
     public static Dataset initInMemoryDatasetWithSolrSpatitalIndex() {
 	    SpatialSearchUtil.deleteOldFiles(SOLR_DATA_DIR  );
 	    SOLR_INDEX_DIR.mkdirs();
-	    SpatialQuery.init() ;
 	    SpatialSearchUtil.createEmptyIndex(SOLR_INDEX_DIR);
 	    return SpatialDatasetFactory.create(SOLR_TEST_ASSEM) ;
     }
@@ -86,14 +85,12 @@ public class SpatialSearchUtil {
     }
     
     public static Dataset initInMemoryDatasetWithLuceneSpatitalIndex(File indexDir) throws IOException{
-		SpatialQuery.init();
 		deleteOldFiles(indexDir);
 		indexDir.mkdirs();
 		return createDatasetByCode(indexDir);
     }
     
     public static Dataset initTDBDatasetWithLuceneSpatitalIndex(File indexDir, File TDBDir) throws IOException{
-		SpatialQuery.init();
 		deleteOldFiles(indexDir);
 		deleteOldFiles(TDBDir);
 		indexDir.mkdirs();

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
index 1c08724..cbb497f 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
@@ -205,7 +205,7 @@ public class TDB {
 
     /**
      * TDB System initialization - normally, this is not explicitly called
-     * because all routes to use TDB will cause initialization to occur.
+     * because Jena system wide initialization occurs automatically.
      * However, calling it repeatedly is safe and low cost.
      */
     public static void init() {
@@ -223,7 +223,7 @@ public class TDB {
             initialized = true ;
             if ( JenaSystem.DEBUG_INIT )
                 System.err.println("TDB.init - start") ;
-            ARQ.init() ;
+            // ARQ.init() ; // Init level settings mean this is already done. 
             SystemTDB.init() ;
             LangRDFXML.RiotUniformCompatibility = true ;
             EnvTDB.processGlobalSystemProperties() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-tdb/src/main/java/org/apache/jena/tdb/assembler/TDBGraphAssembler.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/assembler/TDBGraphAssembler.java b/jena-tdb/src/main/java/org/apache/jena/tdb/assembler/TDBGraphAssembler.java
index ad3dc53..9dffe04 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/assembler/TDBGraphAssembler.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/assembler/TDBGraphAssembler.java
@@ -18,8 +18,15 @@
 
 package org.apache.jena.tdb.assembler;
 
-import static org.apache.jena.sparql.util.graph.GraphUtils.* ;
-import static org.apache.jena.tdb.assembler.VocabTDB.* ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getAsStringValue ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getResourceValue ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getStringValue ;
+import static org.apache.jena.tdb.assembler.VocabTDB.pDataset ;
+import static org.apache.jena.tdb.assembler.VocabTDB.pGraphName1 ;
+import static org.apache.jena.tdb.assembler.VocabTDB.pGraphName2 ;
+import static org.apache.jena.tdb.assembler.VocabTDB.pIndex ;
+import static org.apache.jena.tdb.assembler.VocabTDB.pLocation ;
+
 import org.apache.jena.assembler.Assembler ;
 import org.apache.jena.assembler.Mode ;
 import org.apache.jena.assembler.assemblers.AssemblerBase ;
@@ -28,10 +35,8 @@ import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.rdf.model.* ;
 import org.apache.jena.riot.out.NodeFmtLib ;
-import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.TDBException ;
 import org.apache.jena.tdb.TDBFactory ;
-import org.apache.jena.tdb.assembler.IndexAssembler ;
 import org.apache.jena.tdb.base.file.Location ;
 
 public class TDBGraphAssembler extends AssemblerBase implements Assembler
@@ -41,11 +46,6 @@ public class TDBGraphAssembler extends AssemblerBase implements Assembler
     @Override
     public Model open(Assembler a, Resource root, Mode mode)
     {
-        // In case we go via explicit index construction,
-        // although given we got here, the assembler is wired in
-        // and that probably means TDB.init
-        TDB.init() ;
-        
         // Make a model - the default model of the TDB dataset
         // [] rdf:type tdb:GraphTDB ;
         //    tdb:location "dir" ;

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-text/src/main/java/examples/JenaTextExample1.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/examples/JenaTextExample1.java b/jena-text/src/main/java/examples/JenaTextExample1.java
index c273540..a4a75f5 100644
--- a/jena-text/src/main/java/examples/JenaTextExample1.java
+++ b/jena-text/src/main/java/examples/JenaTextExample1.java
@@ -24,7 +24,6 @@ import org.apache.jena.query.* ;
 import org.apache.jena.query.text.EntityDefinition ;
 import org.apache.jena.query.text.TextDatasetFactory ;
 import org.apache.jena.query.text.TextIndexConfig;
-import org.apache.jena.query.text.TextQuery ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.sparql.util.QueryExecUtils ;
@@ -42,7 +41,6 @@ public class JenaTextExample1
     
     public static void main(String ... argv)
     {
-        TextQuery.init();
         Dataset ds = createCode() ;
         //Dataset ds = createAssembler() ;
         loadData(ds , "data.ttl") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-text/src/main/java/jena/textindexdump.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/jena/textindexdump.java b/jena-text/src/main/java/jena/textindexdump.java
index 930a0fc..0226094 100644
--- a/jena-text/src/main/java/jena/textindexdump.java
+++ b/jena-text/src/main/java/jena/textindexdump.java
@@ -49,7 +49,6 @@ public class textindexdump extends CmdARQ {
     protected TextIndex        textIndex    = null ;
 
     static public void main(String... argv) {
-        TextQuery.init() ;
         new textindexdump(argv).mainRun() ;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-text/src/main/java/jena/textindexer.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/jena/textindexer.java b/jena-text/src/main/java/jena/textindexer.java
index c4111e4..6d2edb6 100644
--- a/jena-text/src/main/java/jena/textindexer.java
+++ b/jena-text/src/main/java/jena/textindexer.java
@@ -48,7 +48,6 @@ public class textindexer extends CmdARQ {
     protected ProgressMonitor  progressMonitor ;
 
     static public void main(String... argv) {
-        TextQuery.init() ;
         new textindexer(argv).mainRun() ;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-text/src/main/java/org/apache/jena/query/text/TextDatasetFactory.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextDatasetFactory.java b/jena-text/src/main/java/org/apache/jena/query/text/TextDatasetFactory.java
index 7b7b0d1..71bc1fa 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextDatasetFactory.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextDatasetFactory.java
@@ -24,13 +24,14 @@ import org.apache.jena.query.text.assembler.TextVocab ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
 import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.store.Directory ;
 import org.apache.solr.client.solrj.SolrServer ;
 
 public class TextDatasetFactory
 {
-    static { TextQuery.init(); }
+    static { JenaSystem.init(); }
     
     /** Use an assembler file to build a dataset with text search capabilities */ 
     public static Dataset create(String assemblerFile)

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-text/src/test/java/org/apache/jena/query/text/TestBuildTextDataset.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestBuildTextDataset.java b/jena-text/src/test/java/org/apache/jena/query/text/TestBuildTextDataset.java
index 2335e40..ce50907 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TestBuildTextDataset.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestBuildTextDataset.java
@@ -27,7 +27,6 @@ import org.apache.jena.tdb.TDB ;
 import org.apache.jena.vocabulary.RDFS ;
 import org.apache.lucene.store.Directory ;
 import org.apache.lucene.store.RAMDirectory ;
-import org.junit.BeforeClass ;
 import org.junit.Test ;
 
 /** Test the examples of building a test dataset */
@@ -35,12 +34,6 @@ public class TestBuildTextDataset extends BaseTest
 {
     static final String DIR = "testing/TextQuery" ;
 
-    // Ensure assembler initialized.
-    @BeforeClass
-    public static void setupClass() {
-        TextQuery.init() ;
-    }
-
     @Test
     public void buildText_01() {
         createAssembler("text-config.ttl") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/15ced7e8/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithEmbeddedSolrTextIndex.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithEmbeddedSolrTextIndex.java b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithEmbeddedSolrTextIndex.java
index a462e0a..b33b200 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithEmbeddedSolrTextIndex.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithEmbeddedSolrTextIndex.java
@@ -35,7 +35,6 @@ public class TestDatasetWithEmbeddedSolrTextIndex extends AbstractTestDatasetWit
     public void before() {
         //deleteOldFiles();
         INDEX_DIR.mkdirs();
-        TextQuery.init() ;
         TextSearchUtil.createEmptyIndex(INDEX_DIR);
         dataset = TextDatasetFactory.create(TEST_ASSEM) ;
     }


[7/8] jena git commit: JENA-1029: Comment JenaSystem.

Posted by an...@apache.org.
JENA-1029: Comment JenaSystem.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3e96caec
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3e96caec
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3e96caec

Branch: refs/heads/Jena-1029_subsystem
Commit: 3e96caec0f2264bcce09a2cadd9d2629a289aa0a
Parents: 15ced7e
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Sep 18 08:47:46 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Sep 18 08:47:46 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/system/JenaSystem.java | 68 ++++++++++----------
 1 file changed, 35 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3e96caec/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
index 48603f4..8360f3b 100644
--- a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
@@ -33,7 +33,7 @@ import org.apache.log4j.Logger ;
  * This is achieved by "levels": levels less than 100 are considered "jena system levels" 
  * and are reserved. 
  * 
- * <li>0 - here
+ * <li>0 - reserved
  * <li>10 - jena-core
  * <li>20 - RIOT
  * <li>30 - ARQ
@@ -41,7 +41,11 @@ import org.apache.log4j.Logger ;
  * <li>9999 - other
  */
 public class JenaSystem {
-    
+
+    /** Development support - flag to enable output during
+     * initialization. Output to {@code System.err}, not a logger
+     * to avoid the risk of recursive initialization.   
+     */
     public static final boolean DEBUG_INIT = false ;
     
     // A correct way to manage without synchonized using the double checked locking pattern.
@@ -50,10 +54,12 @@ public class JenaSystem {
     private static volatile boolean initialized = false ;
     private static Object initLock = new Object() ;
     
-    /** Initialize.
+    /** Initialize Jena.
+     * <p>
      * This function is cheap to call when already initialized so can be called to be sure.
      * By default, initialization happens by using {@code ServiceLoader.load} to find
      * {@link JenaSubsystemLifecycle} objects.
+     * See {@link #set} to intercept that choice.
      */
     public static void init() {
         if ( initialized )
@@ -73,6 +79,7 @@ public class JenaSystem {
                 set(new JenaSubsystemRegistryBasic()) ;
             
             get().load() ;
+            get().add(new JenaInitLevel0());
             
             JenaSystem.forEach( module -> {
                 if ( DEBUG_INIT )
@@ -94,11 +101,13 @@ public class JenaSystem {
         }
     }
     
-    private static class JenaInitLogger implements JenaSubsystemLifecycle {
+    /** The level 0 subsystem - inserted without using 
+     * should be only one such level 0 handler. */
+    private static class JenaInitLevel0 implements JenaSubsystemLifecycle {
         private static Logger log = Logger.getLogger("Jena") ; 
         @Override
         public void start() {
-            log.info/*debug*/("Jena intialization");
+            log.debug("Jena initialization");
         }
 
         @Override
@@ -114,50 +123,43 @@ public class JenaSystem {
     
     private static JenaSubsystemRegistry singleton = null;
 
+    /**
+     * Set the {@link JenaSubsystemRegistry}.
+     * To have any effect, this function
+     * must be called before any other Jena code,
+     * and especially before calling {@code JenaSystem.init()}.
+     */
     public static void set(JenaSubsystemRegistry thing) {
         singleton = thing;
     }
 
+    /** The current JenaSubsystemRegistry */
     public static JenaSubsystemRegistry get() {
         return singleton;
     }
-    
+
+    // Order by level (increasing)
     private static Comparator<JenaSubsystemLifecycle> comparator = (obj1, obj2) -> Integer.compare(obj1.level(), obj2.level()) ;
+    // Order by level (decreasing)
     private static Comparator<JenaSubsystemLifecycle> reverseComparator = (obj1, obj2) -> -1 * Integer.compare(obj1.level(), obj2.level()) ;
     
-    public static void add(JenaSubsystemLifecycle module) {
-       get().add(module) ;
-    }
-
-    public static boolean isRegistered(JenaSubsystemLifecycle module) {
-        return get().isRegistered(module);
-    }
-
-    public static void remove(JenaSubsystemLifecycle module) {
-        get().remove(module);
-    }
-
-    public static int size() {
-        return get().size();
-    }
-
-    public static boolean isEmpty() {
-        return get().isEmpty();
-    }
-
-    /** Call an action on each item in the registry.
-     * Calls are made sequentially and in level order.
-     * The exact order within a level is not specified; it is not registration order. 
+    /**
+     * Call an action on each item in the registry. Calls are made sequentially
+     * and in increasing level order. The exact order within a level is not
+     * specified; it is not registration order.
+     * 
      * @param action
      */
     public static void forEach(Consumer<JenaSubsystemLifecycle> action) {
         forEach(action, comparator);
     }
 
-    /** Call an action on each item in the registry but in the reverse enumeration order.
-     * The exact order is not specified but call are made sequentially.
-     * The "reverse" is opposite order to {@link #forEach}, which may not be stable.
-     * It is not related to registration order.
+    /**
+     * Call an action on each item in the registry but in the reverse
+     * enumeration order. Calls are made sequentially and in decreasing level
+     * order. The "reverse" is opposite order to {@link #forEach}, which may not
+     * be stable within a level. It is not related to registration order.
+     * 
      * @param action
      */
     public static void forEachReverse(Consumer<JenaSubsystemLifecycle> action) {


[4/8] jena git commit: JENA-1029: Subsystem initialization (default, ServiceLoader)

Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-csv/src/main/java/org/apache/jena/propertytable/impl/InitJenaCSV.java
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/java/org/apache/jena/propertytable/impl/InitJenaCSV.java b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/InitJenaCSV.java
new file mode 100644
index 0000000..14111f5
--- /dev/null
+++ b/jena-csv/src/main/java/org/apache/jena/propertytable/impl/InitJenaCSV.java
@@ -0,0 +1,34 @@
+/**
+ * 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.propertytable.impl;
+
+import org.apache.jena.propertytable.lang.CSV2RDF ;
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+
+public class InitJenaCSV implements JenaSubsystemLifecycle {
+
+    @Override
+    public void start() {
+        CSV2RDF.init() ;
+    }
+
+    @Override
+    public void stop() {
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-csv/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-csv/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-csv/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..0399e1f
--- /dev/null
+++ b/jena-csv/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1 @@
+org.apache.jena.propertytable.impl.InitJenaCSV

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki1/src/main/java/org/apache/jena/fuseki/Fuseki.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/Fuseki.java b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/Fuseki.java
index 45e6415..b015f83 100644
--- a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/Fuseki.java
+++ b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/Fuseki.java
@@ -20,7 +20,6 @@ package org.apache.jena.fuseki;
 
 import org.apache.jena.fuseki.server.SPARQLServer ;
 import org.apache.jena.query.ARQ ;
-import org.apache.jena.riot.RIOT ;
 import org.apache.jena.riot.system.stream.LocatorFTP ;
 import org.apache.jena.riot.system.stream.LocatorHTTP ;
 import org.apache.jena.riot.system.stream.StreamManager ;
@@ -29,6 +28,7 @@ import org.apache.jena.sparql.lib.Metadata ;
 import org.apache.jena.sparql.mgt.SystemInfo ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.MappingRegistry ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.transaction.TransactionManager ;
 import org.slf4j.Logger ;
@@ -137,11 +137,9 @@ public class Fuseki
         if ( initialized )
             return ;
         initialized = true ;
-        ARQ.init() ;
+        JenaSystem.init();
         SystemInfo sysInfo = new SystemInfo(FusekiIRI, PATH, VERSION, BUILD_DATE) ;
         SystemARQ.registerSubSystem(sysInfo) ;
-        RIOT.init() ;
-        TDB.init() ;
         MappingRegistry.addPrefixMapping("fuseki", FusekiSymbolIRI) ;
         
         TDB.setOptimizerWarningFlag(false) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki1/src/main/java/org/apache/jena/fuseki/migrate/Registry.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/migrate/Registry.java b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/migrate/Registry.java
deleted file mode 100644
index ca30be1..0000000
--- a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/migrate/Registry.java
+++ /dev/null
@@ -1,42 +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.apache.jena.fuseki.migrate;
-
-import java.util.Collection ;
-import java.util.HashMap ;
-import java.util.Map ;
-
-public class Registry<T>
-{
-    protected Map<String, T> registry = new HashMap<String, T>() ;
-    
-    public Registry() {}
-    
-    public void put(String key, T value) { registry.put(key, value) ; }
-    
-    public T get(String key) { return registry.get(key) ; }
-    
-    public boolean isRegistered(String key) { return registry.containsKey(key) ; }
-    public void remove(String key) { registry.remove(key) ; } 
-    public Collection<String> keys() { return registry.keySet() ; }
-    //public Iterator<String> keys() { return registry.keySet().iterator() ; }
-    
-    public int size() { return registry.size() ; }
-    public boolean isEmpty() { return registry.isEmpty() ; }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/DatasetRegistry.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/DatasetRegistry.java b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/DatasetRegistry.java
index 152e8cd..60d15a8 100644
--- a/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/DatasetRegistry.java
+++ b/jena-fuseki1/src/main/java/org/apache/jena/fuseki/server/DatasetRegistry.java
@@ -18,9 +18,9 @@
 
 package org.apache.jena.fuseki.server;
 
-import org.apache.jena.fuseki.migrate.Registry ;
+import org.apache.jena.atlas.lib.Registry ;
 
-public class DatasetRegistry extends Registry<DatasetRef>
+public class DatasetRegistry extends Registry<String, DatasetRef>
 {
     private static DatasetRegistry singleton = new DatasetRegistry() ;
 

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
index 9659da0..37b803e 100644
--- a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
+++ b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.jena.fuseki;
 
+import org.apache.jena.fuseki.server.DatasetRegistry ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.NodeFactory ;
@@ -98,6 +99,7 @@ public class ServerTest
     }
     
     protected static void teardownServer() {
+        DatasetRegistry.get().clear() ;
         if ( server != null )
             server.stop() ;
         server = null ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
index a6cfbdc..991c673 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/Fuseki.java
@@ -26,7 +26,6 @@ import org.apache.jena.atlas.lib.DateTimeUtils ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.spatial.SpatialQuery ;
 import org.apache.jena.query.text.TextQuery ;
-import org.apache.jena.riot.RIOT ;
 import org.apache.jena.riot.system.stream.LocatorFTP ;
 import org.apache.jena.riot.system.stream.LocatorHTTP ;
 import org.apache.jena.riot.system.stream.StreamManager ;
@@ -35,6 +34,7 @@ import org.apache.jena.sparql.lib.Metadata ;
 import org.apache.jena.sparql.mgt.SystemInfo ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.MappingRegistry ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.transaction.TransactionManager ;
 import org.slf4j.Logger ;
@@ -215,13 +215,11 @@ public class Fuseki {
         if ( initialized )
             return ;
         initialized = true ;
-        // FusekiEnv.setEnvironment() ;
+        JenaSystem.init() ;
+        // Do explicitly so it happens after subsystem initialization. 
         FusekiLogging.setLogging() ;
-        ARQ.init() ;
         SystemInfo sysInfo = new SystemInfo(FusekiIRI, PATH, VERSION, BUILD_DATE) ;
         SystemARQ.registerSubSystem(sysInfo) ;
-        RIOT.init() ;
-        
         TDB.init() ;
         // Initialize anyway (e.g. not to rely on assembler magic).
         try { 

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
index 9970af7..931c6e0 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
@@ -35,6 +35,7 @@ import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.riot.RDFLanguages ;
 import org.apache.jena.sparql.core.DatasetGraphFactory ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.sys.Names ;
 import org.apache.jena.tdb.transaction.TransactionManager ;
@@ -89,9 +90,8 @@ public class FusekiCmd {
         // fuseki [--mem|--desc assembler.ttl] [--port PORT] **** /datasetURI
 
         static public void innerMain(String... argv) {
-            // Just to make sure ...
-            ARQ.init() ;
-            TDB.init() ;
+            JenaSystem.init() ;
+            // Do explicitly so it happens after subsystem initialization. 
             Fuseki.init() ;
             new FusekiCmdInner(argv).mainRun() ;
         }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerEnvironmentInit.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerEnvironmentInit.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerEnvironmentInit.java
index 356dc82..3142238 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerEnvironmentInit.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerEnvironmentInit.java
@@ -22,6 +22,7 @@ import javax.servlet.ServletContextEvent ;
 import javax.servlet.ServletContextListener ;
 
 import org.apache.jena.fuseki.FusekiLogging ;
+import org.apache.jena.system.JenaSystem ;
 
 /** Setup the enviroment and logging.
  *  Runs before the ShiroEnvironmentLoader.
@@ -32,8 +33,9 @@ public class FusekiServerEnvironmentInit implements ServletContextListener {
     
     @Override
     public void contextInitialized(ServletContextEvent sce) {
-        FusekiEnv.setEnvironment();
-        FusekiLogging.setLogging();
+        JenaSystem.init() ;
+        FusekiEnv.setEnvironment() ;
+        FusekiLogging.setLogging() ;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-parent/pom.xml
----------------------------------------------------------------------
diff --git a/jena-parent/pom.xml b/jena-parent/pom.xml
index dcbd614..240eee4 100644
--- a/jena-parent/pom.xml
+++ b/jena-parent/pom.xml
@@ -425,7 +425,8 @@
         </executions>
         <configuration>
            <excludeSubProjects>true</excludeSubProjects>
-             <excludes>
+ 	     <excludes>
+	       <exclude>**/META-INF/services/*</exclude>
                <!--
                jena-core exclusions
                -->

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/main/java/org/apache/jena/sdb/SDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/SDB.java b/jena-sdb/src/main/java/org/apache/jena/sdb/SDB.java
index 0fb5204..544bbe6 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/SDB.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/SDB.java
@@ -18,7 +18,6 @@
 
 package org.apache.jena.sdb;
 
-import org.apache.jena.assembler.assemblers.AssemblerGroup ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sdb.assembler.AssemblerVocab ;
@@ -30,17 +29,16 @@ import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.shared.impl.PrefixMappingImpl ;
 import org.apache.jena.sparql.ARQInternalErrorException ;
 import org.apache.jena.sparql.SystemARQ ;
-import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
 import org.apache.jena.sparql.lib.Metadata ;
 import org.apache.jena.sparql.mgt.SystemInfo ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.MappingRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.vocabulary.OWL ;
 import org.apache.jena.vocabulary.RDF ;
 import org.apache.jena.vocabulary.RDFS ;
 
-
 public class SDB
 {
     /** IRI for SDB */  
@@ -71,49 +69,58 @@ public class SDB
     // Global context is the ARQ context.
     public static Context getContext() { return ARQ.getContext() ; }
     
-    static { initWorker() ; }
-    public static void init() { }
-    
-    /** Used by Jena assemblers for registration */ 
-    public static void whenRequiredByAssembler( AssemblerGroup g )
-    {
-        AssemblerUtils.init() ;         // ARQ 
-        AssemblerVocab.register(g) ;    // SDB
+    static { 
+        JenaSystem.init(); 
     }
     
-    private static boolean initialized = false ;
-    private static synchronized void initWorker()
-    {
-        // Called from 
-        // + StoreFactory
-        // + DatasetStore
-        // Commands call AssemblerVocab.init() ;
-
-        if ( initialized )
+//    /** Used by Jena assemblers for registration */ 
+//    public static void whenRequiredByAssembler( AssemblerGroup g )
+//    {
+//        AssemblerUtils.init() ;         // ARQ 
+//        AssemblerVocab.register(g) ;    // SDB
+//    }
+    
+    private static volatile boolean initialized = false ;
+    private static Object initLock = new Object() ;
+    
+    public static void init() {
+        if ( initialized ) 
             return ;
-        
-        // Set this immediately in case code below causes init() to be called.
-        // (It's better if there are no dependences but ...)
-        initialized = true ;
-        
-        // Better not to break up BGPs too much.
-        ARQ.getContext().set(ARQ.optFilterPlacement, false) ;
-        MappingRegistry.addPrefixMapping(SDB.symbolPrefix, SDB.symbolSpace) ;
+        synchronized(initLock) {
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("SDB.init - skip") ;
+                return ;
+            }
+            initialized = true ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("SDB.init - start") ;
+            // Set this immediately in case code below causes init() to be called.
+            // (It's better if there are no dependences but ...)
+            initialized = true ;
+
+            // Better not to break up BGPs too much.
+            ARQ.getContext().set(ARQ.optFilterPlacement, false) ;
+            MappingRegistry.addPrefixMapping(SDB.symbolPrefix, SDB.symbolSpace) ;
+
+            // Default is 1000 4Kpages.
+            DerbyUtils.setDerbyPageCacheSize(10000) ;
 
-        // Default is 1000 4Kpages.
-        DerbyUtils.setDerbyPageCacheSize(10000) ;
+            // Wire in the SDB query engine
+            QueryEngineSDB.register() ;
+            // Wire in the SDB update engine
+            UpdateEngineSDB.register() ;
 
-        // Wire in the SDB query engine
-        QueryEngineSDB.register() ;
-        // Wire in the SDB update engine
-        UpdateEngineSDB.register() ;
-        
-        SDB.getContext().setIfUndef(useQuadRewrite,        false) ;
-        SDB.getContext().setIfUndef(streamGraphAPI,        false) ;
-        SDB.getContext().setIfUndef(jdbcStream,            true) ;
-        //SDB.getContext().setIfUndef(jdbcFetchSize,         ???) ;
-        SDB.getContext().setIfUndef(annotateGeneratedSQL,  true) ;
-        //SDB.getContext().setIfUndef(unionDefaultGraph,     false) ;
+            SDB.getContext().setIfUndef(useQuadRewrite,        false) ;
+            SDB.getContext().setIfUndef(streamGraphAPI,        false) ;
+            SDB.getContext().setIfUndef(jdbcStream,            true) ;
+            //SDB.getContext().setIfUndef(jdbcFetchSize,         ???) ;
+            SDB.getContext().setIfUndef(annotateGeneratedSQL,  true) ;
+            //SDB.getContext().setIfUndef(unionDefaultGraph,     false) ;
+            AssemblerVocab.init(); 
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("SDB.init - finish") ;
+        }
     }
     
     /** RDF namespace prefix */

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/main/java/org/apache/jena/sdb/SDBFactory.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/SDBFactory.java b/jena-sdb/src/main/java/org/apache/jena/sdb/SDBFactory.java
index ce61c90..62b7288 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/SDBFactory.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/SDBFactory.java
@@ -35,6 +35,7 @@ import org.apache.jena.sdb.store.DatasetStore ;
 import org.apache.jena.sdb.store.StoreFactory ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.modify.GraphStoreBasic ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.update.GraphStore ;
 
 /** Various operations to create or connect objects to do with SDB:
@@ -45,6 +46,7 @@ import org.apache.jena.update.GraphStore ;
 @SuppressWarnings("deprecation")
 public class SDBFactory
 {
+    static { JenaSystem.init() ; }
     // ---- Connections
     /**
      * Create a connection to a database.

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/main/java/org/apache/jena/sdb/assembler/StoreDescAssembler.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/assembler/StoreDescAssembler.java b/jena-sdb/src/main/java/org/apache/jena/sdb/assembler/StoreDescAssembler.java
index de8d9f5..6e5c140 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/assembler/StoreDescAssembler.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/assembler/StoreDescAssembler.java
@@ -24,7 +24,6 @@ import org.apache.jena.assembler.Assembler ;
 import org.apache.jena.assembler.Mode ;
 import org.apache.jena.assembler.assemblers.AssemblerBase ;
 import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.sdb.SDB ;
 import org.apache.jena.sdb.SDBException ;
 import org.apache.jena.sdb.StoreDesc ;
 import org.apache.jena.sdb.sql.MySQLEngineType ;
@@ -38,8 +37,6 @@ import org.slf4j.LoggerFactory;
 
 public class StoreDescAssembler extends AssemblerBase implements Assembler
 {
-    static { SDB.init() ; }
-    
     private static Logger log = LoggerFactory.getLogger(StoreDescAssembler.class) ;
     
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/main/java/org/apache/jena/sdb/core/InitSDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/core/InitSDB.java b/jena-sdb/src/main/java/org/apache/jena/sdb/core/InitSDB.java
new file mode 100644
index 0000000..3461f15
--- /dev/null
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/core/InitSDB.java
@@ -0,0 +1,39 @@
+/**
+ * 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.sdb.core;
+
+import org.apache.jena.sdb.SDB ;
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+
+/** Jena subsystem initialization */
+public class InitSDB implements JenaSubsystemLifecycle {
+    @Override
+    public void start() {
+        SDB.init() ;
+    }
+
+    @Override
+    public void stop() {
+    }
+    
+    @Override
+    public int level() {
+        return 9 ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java b/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
index 5431ac5..0b039aa 100644
--- a/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
+++ b/jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java
@@ -49,7 +49,6 @@ public abstract class CmdArgsDB extends CmdARQ
         addModule(modStore) ;
         addModule(modLogSQL) ;
         addModule(modTime) ;
-        ARQ.init() ;
         modVersion.addClass(Jena.class) ;
         modVersion.addClass(ARQ.class) ;
         modVersion.addClass(SDB.class) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-sdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..6c8c9b0
--- /dev/null
+++ b/jena-sdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1 @@
+org.apache.jena.sdb.core.InitSDB

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-sdb/src/test/java/org/apache/jena/sdb/test/SDBQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/test/java/org/apache/jena/sdb/test/SDBQueryTestSuite.java b/jena-sdb/src/test/java/org/apache/jena/sdb/test/SDBQueryTestSuite.java
index c2f6d7d..f451a07 100644
--- a/jena-sdb/src/test/java/org/apache/jena/sdb/test/SDBQueryTestSuite.java
+++ b/jena-sdb/src/test/java/org/apache/jena/sdb/test/SDBQueryTestSuite.java
@@ -22,6 +22,7 @@ import junit.framework.TestSuite;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sdb.SDB ;
 import org.apache.jena.sdb.test.junit.QueryTestSDBFactory ;
+import org.apache.jena.system.JenaSystem ;
 import org.junit.runner.RunWith;
 import org.junit.runners.AllTests;
 
@@ -40,14 +41,14 @@ public class SDBQueryTestSuite extends TestSuite
     
     private SDBQueryTestSuite()
     {
-        super("SDB") ;
-        
+        super("SDB Query") ;
+        SDB.init();
         if ( true )
             // PostgreSQL gets upset with comments in comments??
             ARQ.getContext().setFalse(SDB.annotateGeneratedSQL) ;
 
         QueryTestSDBFactory.make(this, SDBTestSetup.storeList, SDBTestSetup.manifestMain) ;
-        QueryTestSDBFactory.make(this, SDBTestSetup.storeListSimple, SDBTestSetup.manifestSimple) ;
+        //QueryTestSDBFactory.make(this, SDBTestSetup.storeListSimple, SDBTestSetup.manifestSimple) ;
     }
     
  

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-spatial/src/main/java/org/apache/jena/query/spatial/InitJenaSpatial.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/InitJenaSpatial.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/InitJenaSpatial.java
new file mode 100644
index 0000000..f6f5d33
--- /dev/null
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/InitJenaSpatial.java
@@ -0,0 +1,32 @@
+/**
+ * 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.query.spatial;
+
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+
+public class InitJenaSpatial implements JenaSubsystemLifecycle {
+    @Override
+    public void start() {
+        SpatialQuery.init() ;
+    }
+
+    @Override
+    public void stop() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialQuery.java
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialQuery.java b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialQuery.java
index 630ec69..6788033 100644
--- a/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialQuery.java
+++ b/jena-spatial/src/main/java/org/apache/jena/query/spatial/SpatialQuery.java
@@ -18,6 +18,8 @@
 
 package org.apache.jena.query.spatial;
 
+import com.spatial4j.core.context.SpatialContext ;
+
 import org.apache.jena.query.spatial.assembler.SpatialAssembler ;
 import org.apache.jena.query.spatial.pfunction.library.* ;
 import org.apache.jena.sparql.SystemARQ ;
@@ -27,14 +29,13 @@ import org.apache.jena.sparql.pfunction.PropertyFunction ;
 import org.apache.jena.sparql.pfunction.PropertyFunctionFactory ;
 import org.apache.jena.sparql.pfunction.PropertyFunctionRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
-import org.apache.jena.tdb.TDB ;
-
-import com.spatial4j.core.context.SpatialContext ;
+import org.apache.jena.system.JenaSystem ;
 
 public class SpatialQuery
 {
-    private static boolean initialized = false ;
+    private static volatile boolean initialized = false ;
     private static Object lock = new Object() ;
+
     public static String NS = "http://jena.apache.org/spatial#" ;
     public static String IRI = "http://jena.apache.org/#spatial" ;
     public static final Symbol spatialIndex = Symbol.create(NS+"index") ;
@@ -52,16 +53,23 @@ public class SpatialQuery
     // an optional feature for WKT literals, loaded when necessary, but not required
     public static final String JTS_SPATIAL_CONTEXT_FACTORY_CLASS = "com.spatial4j.core.context.jts.JtsSpatialContextFactory"; 
     
-    static { init() ; }
+    static { JenaSystem.init(); }
     
     public static void init() 
     {
-        if ( initialized ) return ;
+        if ( initialized ) 
+            return ;
         synchronized(lock)
         {
-            if ( initialized ) return ;
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("SpatialQuery.init - skip") ;
+                return ; 
+            }
             initialized = true ;
-            TDB.init() ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("SpatialQuery.init - start") ;
+
             SpatialAssembler.init() ;
             
             SystemInfo sysInfo = new SystemInfo(IRI, PATH, VERSION, BUILD_DATE) ;
@@ -122,6 +130,10 @@ public class SpatialQuery
                     return new WestPF() ;
                 }
             });
+            
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("SpatialQuery.init - finish") ;
+
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-spatial/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-spatial/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-spatial/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..c04f1fc
--- /dev/null
+++ b/jena-spatial/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1 @@
+org.apache.jena.query.spatial.InitJenaSpatial

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
index 786ded9..1c08724 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/TDB.java
@@ -30,7 +30,6 @@ import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.reasoner.InfGraph ;
-import org.apache.jena.riot.RIOT ;
 import org.apache.jena.riot.lang.LangRDFXML ;
 import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.core.DatasetGraph ;
@@ -42,6 +41,7 @@ import org.apache.jena.sparql.mgt.SystemInfo ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.MappingRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.tdb.assembler.AssemblerTDB ;
 import org.apache.jena.tdb.modify.UpdateEngineTDB ;
 import org.apache.jena.tdb.setup.DatasetBuilderStd ;
@@ -102,15 +102,6 @@ public class TDB {
         return ARQ.getContext() ;
     }
 
-    // Called on assembler loading.
-    // Real initializtion happnes due to class static blocks.
-    /**
-     * TDB System initialization - normally, this is not explicitly called
-     * because all routes to use TDB will cause initialization to occur.
-     * However, calling it repeatedly is safe and low cost.
-     */
-    public static void init() {}
-
     /**
      * Release any and all system resources held by TDB. This does NOT close or
      * release datasets or graphs held by client code.
@@ -208,39 +199,52 @@ public class TDB {
             ((Sync)object).sync() ;
     }
 
-    private static boolean initialized = false ;
-    static {
-        initialization1() ;
-    }
+    private static final Object initLock = new Object() ;
+    private static volatile boolean initialized = false ;
+    static { JenaSystem.init(); }
 
-    private static synchronized void initialization1() {
+    /**
+     * TDB System initialization - normally, this is not explicitly called
+     * because all routes to use TDB will cause initialization to occur.
+     * However, calling it repeatedly is safe and low cost.
+     */
+    public static void init() {
         // Called at start.
-        if ( initialized )
+        if ( initialized ) {
             return ;
-        initialized = true ;
-
-        RIOT.init() ;
-        SystemTDB.init() ;
-        ARQ.init() ;
-        LangRDFXML.RiotUniformCompatibility = true ;
-        EnvTDB.processGlobalSystemProperties() ;
-
-        MappingRegistry.addPrefixMapping(SystemTDB.tdbSymbolPrefix, SystemTDB.symbolNamespace) ;
-        AssemblerUtils.init() ;
-        AssemblerTDB.init() ;
-        QueryEngineTDB.register() ;
-        UpdateEngineTDB.register() ;
-        MappingRegistry.addPrefixMapping(TDB.tdbSymbolPrefix, TDB.tdbParamNS) ;
-
-        wireIntoExecution() ;
-
-        if ( log.isDebugEnabled() )
-            log.debug("\n" + ARQ.getContext()) ;
+        }
+        
+        synchronized(initLock) {
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("TDB.init - return") ;
+                return ;
+            }
+            initialized = true ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("TDB.init - start") ;
+            ARQ.init() ;
+            SystemTDB.init() ;
+            LangRDFXML.RiotUniformCompatibility = true ;
+            EnvTDB.processGlobalSystemProperties() ;
+
+            MappingRegistry.addPrefixMapping(SystemTDB.tdbSymbolPrefix, SystemTDB.symbolNamespace) ;
+            AssemblerUtils.init() ;
+            AssemblerTDB.init() ;
+            QueryEngineTDB.register() ;
+            UpdateEngineTDB.register() ;
+            MappingRegistry.addPrefixMapping(TDB.tdbSymbolPrefix, TDB.tdbParamNS) ;
+
+            wireIntoExecution() ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("TDB.init - finish") ;
+        }
     }
 
     private static void wireIntoExecution() {
         // Globally change the stage generator to intercept BGP on TDB
-        StageGenerator orig = (StageGenerator)ARQ.getContext().get(ARQ.stageGenerator) ;
+        Context cxt = ARQ.getContext() ;
+        StageGenerator orig = StageBuilder.chooseStageGenerator(cxt) ; 
 
         // Wire in the TDB stage generator which will make TDB work whether
         // or not the TDB executor is used. This means that datasets of mixed

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java b/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
index 26ea8c1..8b5021b 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
@@ -25,6 +25,7 @@ import org.apache.jena.query.Dataset ;
 import org.apache.jena.query.DatasetFactory ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.tdb.assembler.VocabTDB ;
 import org.apache.jena.tdb.base.file.Location ;
 import org.apache.jena.tdb.setup.StoreParams ;
@@ -36,6 +37,8 @@ import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
 /** Public factory for creating objects datasets backed by TDB storage */
 public class TDBFactory
 {
+    static { JenaSystem.init(); }
+    
     private TDBFactory() {} 
     
     /** Read the file and assembler a dataset */

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
index be2d8b8..012b206 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
@@ -92,9 +92,9 @@ public class GraphTDB extends GraphView implements Closeable, Sync {
     @Override
     final public void close() {
         sync() ;
-        // Ignore - graphs are projectsion of the overlying database.
+        // Ignore - graphs are projections of the overlying database.
         // "Close graph" is messy in this projection world. 
-        //super.close() ;
+        super.close() ;
     }
 
     protected static ExtendedIterator<Triple> graphBaseFindDft(DatasetGraphTDB dataset, Triple triple) {

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-tdb/src/main/java/org/apache/jena/tdb/sys/InitTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/InitTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/InitTDB.java
new file mode 100644
index 0000000..4b3f50d
--- /dev/null
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/InitTDB.java
@@ -0,0 +1,42 @@
+/**
+ * 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.tdb.sys;
+
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+import org.apache.jena.tdb.TDB ;
+
+/** Jena subsystem initialization */
+public class InitTDB implements JenaSubsystemLifecycle {
+
+    @Override
+    public void start() {
+        TDB.init() ;
+    }
+
+    @Override
+    public void stop() {
+        // This is savage and does not take account of in-flight transactions.
+        TDB.closedown() ; 
+    }
+    
+    @Override
+    public int level() {
+        return 40 ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-tdb/src/main/java/org/apache/jena/tdb/sys/SystemTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/SystemTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/SystemTDB.java
index fc278fa..d7c0e84 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/SystemTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/SystemTDB.java
@@ -30,6 +30,7 @@ import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
 import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
 import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.TDBException ;
 import org.apache.jena.tdb.base.block.FileMode ;
@@ -40,6 +41,8 @@ import org.slf4j.LoggerFactory ;
 
 public class SystemTDB
 {
+    static { JenaSystem.init(); }
+    
     // NB Same logger as the TDB class because this class is the system info but kept out of TDB javadoc.
     // It's visibility is TDB, not really public. 
     private static final Logger log = LoggerFactory.getLogger(TDB.class) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-tdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-tdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..a31e570
--- /dev/null
+++ b/jena-tdb/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1 @@
+org.apache.jena.tdb.sys.InitTDB

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-text/src/main/java/org/apache/jena/query/text/InitJenaText.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/InitJenaText.java b/jena-text/src/main/java/org/apache/jena/query/text/InitJenaText.java
new file mode 100644
index 0000000..2aae38e
--- /dev/null
+++ b/jena-text/src/main/java/org/apache/jena/query/text/InitJenaText.java
@@ -0,0 +1,33 @@
+/**
+ * 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.query.text;
+
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+
+public class InitJenaText implements JenaSubsystemLifecycle {
+    @Override
+    public void start() {
+        TextQuery.init() ;
+    }
+
+    @Override
+    public void stop() {
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java b/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java
index 7fc01e9..5e57341 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java
@@ -26,11 +26,11 @@ import org.apache.jena.sparql.pfunction.PropertyFunction ;
 import org.apache.jena.sparql.pfunction.PropertyFunctionFactory ;
 import org.apache.jena.sparql.pfunction.PropertyFunctionRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
-import org.apache.jena.tdb.TDB ;
+import org.apache.jena.system.JenaSystem ;
 
 public class TextQuery
 {
-    private static boolean initialized = false ;
+    private static volatile boolean initialized = false ;
     private static Object lock = new Object() ;
     public static String NS = "http://jena.apache.org/text#" ;
     public static String IRI = "http://jena.apache.org/#text" ;
@@ -44,16 +44,22 @@ public class TextQuery
     public static final String VERSION      = metadata.get(PATH+".version", "unknown") ;
     public static final String BUILD_DATE   = metadata.get(PATH+".build.datetime", "unset") ;
     
-    static { init() ; }
+    static { JenaSystem.init(); }
     
     public static void init() 
     {
-        if ( initialized ) return ;
-        synchronized(lock)
-        {
-            if ( initialized ) return ;
+        if ( initialized ) 
+            return ;
+        synchronized(lock) {
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("TextQuery.init - skip") ;
+                return ; 
+            }
+            initialized = true ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("TextQuery.init - start") ;
             initialized = true ;
-            TDB.init() ;
             TextAssembler.init() ;
             
             SystemInfo sysInfo = new SystemInfo(IRI, PATH, VERSION, BUILD_DATE) ;
@@ -65,6 +71,8 @@ public class TextQuery
                     return new TextQueryPF() ;
                 }
             });
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("TextQuery.init - finish") ;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-text/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-text/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-text/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..bef1d0b
--- /dev/null
+++ b/jena-text/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1 @@
+org.apache.jena.query.text.InitJenaText


[5/8] jena git commit: JENA-1029: Subsystem initialization (default, ServiceLoader)

Posted by an...@apache.org.
JENA-1029: Subsystem initialization (default, ServiceLoader)


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/55a8eab3
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/55a8eab3
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/55a8eab3

Branch: refs/heads/Jena-1029_subsystem
Commit: 55a8eab39657e5d5beba8ffe6a2a6af15949a0c7
Parents: 0da50bf
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Sep 18 00:25:07 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Sep 18 00:25:07 2015 +0100

----------------------------------------------------------------------
 jena-arq/pom.xml                                |   2 +-
 jena-arq/src/main/java/arq/cmdline/CmdARQ.java  |   3 +-
 .../src/main/java/arq/cmdline/ModSymbol.java    |   6 +-
 .../main/java/org/apache/jena/query/ARQ.java    | 137 ++++++++-------
 .../main/java/org/apache/jena/query/Query.java  |   3 +-
 .../java/org/apache/jena/riot/RDFDataMgr.java   |   6 +-
 .../main/java/org/apache/jena/riot/RIOT.java    |  12 +-
 .../org/apache/jena/riot/system/InitRIOT.java   |  39 +++++
 .../org/apache/jena/sparql/ARQConstants.java    |  34 ++--
 .../java/org/apache/jena/sparql/SystemARQ.java  |  17 ++
 .../jena/sparql/algebra/optimize/Optimize.java  |   3 +-
 .../sparql/algebra/optimize/TransformTopN.java  |   4 +-
 .../sparql/core/assembler/AssemblerUtils.java   |   3 +-
 .../apache/jena/sparql/engine/http/Service.java |  16 +-
 .../engine/join/AbstractIterHashJoin.java       |   5 +-
 .../jena/sparql/engine/main/StageBuilder.java   |  18 +-
 .../engine/optimizer/reorder/ReorderFixed.java  |   1 +
 .../apache/jena/sparql/lang/ParserSPARQL11.java |   1 +
 .../java/org/apache/jena/sparql/sse/SSE.java    |   3 +
 .../org/apache/jena/sparql/system/InitARQ.java  |  39 +++++
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   2 +
 jena-arq/src/test/java/arq/qtest.java           |   7 +-
 .../org/apache/jena/sparql/ARQTestSuite.java    |   6 +-
 jena-core/src/main/java/jena/rdfcat.java        |  14 +-
 .../org/apache/jena/assembler/Assembler.java    |   1 +
 .../assembler/assemblers/AssemblerBase.java     |   4 +-
 .../org/apache/jena/rdf/model/ModelFactory.java |   2 +
 .../org/apache/jena/rdf/model/impl/IO_Ctl.java  |  71 --------
 .../apache/jena/rdf/model/impl/ModelCom.java    |   3 +-
 .../org/apache/jena/system/InitJenaCore.java    |  67 +++++++
 .../jena/system/JenaSubsystemLifecycle.java     |  32 ++++
 .../jena/system/JenaSubsystemRegistry.java      |  56 ++++++
 .../jena/system/JenaSubsystemRegistryBasic.java |  89 ++++++++++
 .../java/org/apache/jena/system/JenaSystem.java | 175 +++++++++++++++++++
 .../java/org/apache/jena/util/FileManager.java  |   8 +-
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   2 +
 .../jena/propertytable/impl/InitJenaCSV.java    |  34 ++++
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   1 +
 .../java/org/apache/jena/fuseki/Fuseki.java     |   6 +-
 .../apache/jena/fuseki/migrate/Registry.java    |  42 -----
 .../jena/fuseki/server/DatasetRegistry.java     |   4 +-
 .../java/org/apache/jena/fuseki/ServerTest.java |   2 +
 .../java/org/apache/jena/fuseki/Fuseki.java     |   8 +-
 .../org/apache/jena/fuseki/cmd/FusekiCmd.java   |   6 +-
 .../server/FusekiServerEnvironmentInit.java     |   6 +-
 jena-parent/pom.xml                             |   3 +-
 .../src/main/java/org/apache/jena/sdb/SDB.java  |  89 +++++-----
 .../java/org/apache/jena/sdb/SDBFactory.java    |   2 +
 .../jena/sdb/assembler/StoreDescAssembler.java  |   3 -
 .../java/org/apache/jena/sdb/core/InitSDB.java  |  39 +++++
 jena-sdb/src/main/java/sdb/cmd/CmdArgsDB.java   |   1 -
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   1 +
 .../apache/jena/sdb/test/SDBQueryTestSuite.java |   7 +-
 .../jena/query/spatial/InitJenaSpatial.java     |  32 ++++
 .../apache/jena/query/spatial/SpatialQuery.java |  28 ++-
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   1 +
 .../src/main/java/org/apache/jena/tdb/TDB.java  |  76 ++++----
 .../java/org/apache/jena/tdb/TDBFactory.java    |   3 +
 .../org/apache/jena/tdb/store/GraphTDB.java     |   4 +-
 .../java/org/apache/jena/tdb/sys/InitTDB.java   |  42 +++++
 .../java/org/apache/jena/tdb/sys/SystemTDB.java |   3 +
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   1 +
 .../apache/jena/query/text/InitJenaText.java    |  33 ++++
 .../org/apache/jena/query/text/TextQuery.java   |  24 ++-
 ...rg.apache.jena.system.JenaSubsystemLifecycle |   1 +
 65 files changed, 1011 insertions(+), 382 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/pom.xml
----------------------------------------------------------------------
diff --git a/jena-arq/pom.xml b/jena-arq/pom.xml
index 854c3ec..fbcbd68 100644
--- a/jena-arq/pom.xml
+++ b/jena-arq/pom.xml
@@ -153,7 +153,7 @@
           <includes>
             <!-- 
 	      The test collections TC_General, TC_Riot, TC_Atlas 
-	      are development support that collect the relavent 
+	      are development support that collect the relevant 
 	      tests for partial testing during development. 
 	    -->
             <include>**/TS_*.java</include>

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/CmdARQ.java b/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
index ac18c00..2d82d98 100644
--- a/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
+++ b/jena-arq/src/main/java/arq/cmdline/CmdARQ.java
@@ -25,10 +25,11 @@ import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.riot.RIOT ;
 import org.apache.jena.sparql.engine.iterator.QueryIteratorBase ;
+import org.apache.jena.system.JenaSystem ;
 
 public abstract class CmdARQ extends CmdGeneral
 {
-	static { ARQ.init() ; }
+	static { JenaSystem.init() ; }
 
     protected ModSymbol modSymbol = new ModSymbol() ;
     ArgDecl  strictDecl = new ArgDecl(ArgDecl.NoValue, "strict") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/arq/cmdline/ModSymbol.java b/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
index 3bac01f..689dafe 100644
--- a/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
+++ b/jena-arq/src/main/java/arq/cmdline/ModSymbol.java
@@ -30,11 +30,14 @@ import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.MappingRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
 
 public class ModSymbol extends ModBase
 {
+    static { JenaSystem.init(); }
+
     protected final ArgDecl setDecl = new ArgDecl(ArgDecl.HasValue, "set", "define", "defn", "def") ;
-    Context context = new Context() ;
+private Context context = new Context() ;
 
     @Override
     public void registerWith(CmdGeneral cmdLine)
@@ -49,7 +52,6 @@ public class ModSymbol extends ModBase
     @Override
     public void processArgs(CmdArgModule cmdLine)
     {
-        ARQ.init();
         
         if ( cmdLine.getValues(setDecl) == null || cmdLine.getValues(setDecl).size() == 0 )
             return ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
index 5ba3074..dfef428 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
@@ -19,19 +19,18 @@
 package org.apache.jena.query;
 
 import org.apache.jena.riot.RIOT ;
-import org.apache.jena.sparql.ARQConstants ;
 import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.algebra.optimize.TransformOrderByDistinctApplication ;
 import org.apache.jena.sparql.engine.http.Service ;
-import org.apache.jena.sparql.engine.main.StageBuilder ;
 import org.apache.jena.sparql.lib.Metadata ;
 import org.apache.jena.sparql.mgt.ARQMgt ;
 import org.apache.jena.sparql.mgt.Explain ;
-import org.apache.jena.sparql.mgt.SystemInfo ;
 import org.apache.jena.sparql.mgt.Explain.InfoLevel ;
+import org.apache.jena.sparql.mgt.SystemInfo ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.MappingRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
@@ -39,6 +38,19 @@ import org.slf4j.LoggerFactory ;
 
 public class ARQ
 {
+    private static volatile boolean initialized = false ;
+    // Must be initialized early for reentrant initialization.
+    private static final Object initLock = new Object() ;
+    
+    // Initialization notes:
+    //    No use of ARQConstants before the initialization block. (Can be afterwards.)
+    // Risk is 
+    //   ARQConstants -> OWL -> ModelFactory -> jena initialization  
+    //     -> ARQ.init while initializing -> StageBuilder.init -> NodeConst -> rdf.type -> OWL 
+    // recursing initialization, hits NPE via OWL.
+    
+    // And stageGenerator must be set before call ARQ.init.
+
     /** Name of the execution logger */
     public static final String logExecName = "com.hp.hpl.jena.arq.exec" ;
     
@@ -67,7 +79,7 @@ public class ARQ
      * e.g. log4j.properties -- log4j.logger.com.hp.hpl.jena.sparql.exec=INFO
      * See the <a href="http://jena.apache.org/documentation/query/logging.html">ARQ Logging Documentation</a>.
      */
-    public static final Symbol symLogExec           = ARQConstants.allocSymbol("logExec") ;
+    public static final Symbol symLogExec           = SystemARQ.allocSymbol("logExec") ;
     
     /** Get the currently global execution logging setting */  
     public static Explain.InfoLevel getExecutionLogging() { return (Explain.InfoLevel)ARQ.getContext().get(ARQ.symLogExec) ; }
@@ -100,7 +112,7 @@ public class ARQ
     /** Stick exactly to the spec.
      */
     public static final Symbol strictSPARQL =
-        ARQConstants.allocSymbol("strictSPARQL") ;
+        SystemARQ.allocSymbol("strictSPARQL") ;
     
     /** Controls bNode labels as &lt;_:...&gt; or not -
      * that is a pseudo URIs.
@@ -108,7 +120,7 @@ public class ARQ
      */
 
     public static final Symbol constantBNodeLabels =
-        ARQConstants.allocSymbol("constantBNodeLabels") ;
+        SystemARQ.allocSymbol("constantBNodeLabels") ;
     
     /** Enable built-in property functions - also called "magic properties".
      * These are properties in triple patterns that need
@@ -117,27 +129,27 @@ public class ARQ
      */
 
     public static final Symbol enablePropertyFunctions =
-        ARQConstants.allocSymbol("enablePropertyFunctions") ;
+        SystemARQ.allocSymbol("enablePropertyFunctions") ;
 
     /** Enable logging of execution timing. 
      */
 
     public static final Symbol enableExecutionTimeLogging =
-        ARQConstants.allocSymbol("enableExecutionTimeLogging") ;
+        SystemARQ.allocSymbol("enableExecutionTimeLogging") ;
 
     /** If true, XML result sets written will contain the graph bNode label
      *  See also inputGraphBNodeLabels
      */
     
     public static final Symbol outputGraphBNodeLabels =  
-        ARQConstants.allocSymbol("outputGraphBNodeLabels") ;
+        SystemARQ.allocSymbol("outputGraphBNodeLabels") ;
 
     /** If true, XML result sets will use the bNode label in the result set itself.
      *  See also outputGraphBNodeLabels
      */
     
     public static final Symbol inputGraphBNodeLabels =  
-        ARQConstants.allocSymbol("inputGraphBNodeLabels") ;
+        SystemARQ.allocSymbol("inputGraphBNodeLabels") ;
 
     /** Turn on processing of blank node labels in queries */  
     public static void enableBlankNodeResultLabels() { enableBlankNodeResultLabels(true) ; }
@@ -150,7 +162,6 @@ public class ARQ
         globalContext.set(outputGraphBNodeLabels, b) ;
     }
 
-
     /**
      * Set timeout.  The value of this symbol gives thevalue of the timeout in milliseconds
      * <ul>
@@ -161,7 +172,7 @@ public class ARQ
      * @see QueryExecution#setTimeout(long)
      * @see QueryExecution#setTimeout(long,long)
      */
-    public static final Symbol queryTimeout = ARQConstants.allocSymbol("queryTimeout") ;
+    public static final Symbol queryTimeout = SystemARQ.allocSymbol("queryTimeout") ;
     
     // This can't be a context constant because NodeValues don't look in the context.
 //    /**
@@ -172,19 +183,19 @@ public class ARQ
     /**
      * Context key for StageBuilder used in BGP compilation 
      */
-    public static final Symbol stageGenerator = ARQConstants.allocSymbol("stageGenerator") ;
+    public static final Symbol stageGenerator = SystemARQ.allocSymbol("stageGenerator") ;
 
     /**
      * Context key to control hiding non-distinuished variables 
      */
-    public static final Symbol hideNonDistiguishedVariables = ARQConstants.allocSymbol("hideNonDistiguishedVariables") ;
+    public static final Symbol hideNonDistiguishedVariables = SystemARQ.allocSymbol("hideNonDistiguishedVariables") ;
 
     /**
      * Use the SAX parser for XML result sets.  The default is to use StAX for
      * full streaming of XML results.  The SAX parser takes a copy of the result set
      * before giving the ResultSet to the calling application.
      */
-    public static final Symbol useSAX = ARQConstants.allocSymbol("useSAX") ;
+    public static final Symbol useSAX = SystemARQ.allocSymbol("useSAX") ;
     
     /** 
      * Indicate whether duplicate select and groupby variables are allowed. 
@@ -200,13 +211,13 @@ public class ARQ
      *   xercesRegex : use the internal XPath regex engine (more compliant)  
      */
     
-    public static final Symbol regexImpl =  ARQConstants.allocSymbol("regexImpl") ;
+    public static final Symbol regexImpl =  SystemARQ.allocSymbol("regexImpl") ;
     
         
     /** Symbol to name java.util.regex regular expression engine */ 
-    public static final Symbol javaRegex =  ARQConstants.allocSymbol("javaRegex") ;
+    public static final Symbol javaRegex =  SystemARQ.allocSymbol("javaRegex") ;
     /** Symbol to name the Xerces-J regular expression engine */ 
-    public static final Symbol xercesRegex =  ARQConstants.allocSymbol("xercesRegex") ;
+    public static final Symbol xercesRegex =  SystemARQ.allocSymbol("xercesRegex") ;
 
     /** 
      * Use this Symbol to allow passing additional query parameters to a 
@@ -218,7 +229,7 @@ public class ARQ
      * 
      * @see org.apache.jena.sparql.engine.http.Service
      */
-    public static final Symbol serviceParams = ARQConstants.allocSymbol("serviceParams") ;
+    public static final Symbol serviceParams = SystemARQ.allocSymbol("serviceParams") ;
     
     /**
      * Control whether SERVICE processing is allowed.
@@ -250,7 +261,7 @@ public class ARQ
     // Some possible additions to the list:
     // Sort: DISTINCT, merge joins<br>
     // Hash table: GROUP BY, MINUS, SERVICE, VALUES, and hash joins <br>
-    public static final Symbol spillToDiskThreshold = ARQConstants.allocSymbol("spillToDiskThreshold") ;
+    public static final Symbol spillToDiskThreshold = SystemARQ.allocSymbol("spillToDiskThreshold") ;
     
     // Optimizer controls.
     
@@ -279,27 +290,27 @@ public class ARQ
      *  Context key controlling whether the main query engine applies the
      *  default optimization transformations.
      */  
-    public static final Symbol optimization = ARQConstants.allocSymbol("optimization") ;
+    public static final Symbol optimization = SystemARQ.allocSymbol("optimization") ;
     
     /** 
      *  Context key controlling whether the main query engine flattens simple paths
      *  (e.g. <tt>?x :p/:q ?z => ?x :p ?.0 . ?.0 ?q ?z</tt>)   
      *  <p>Default is "true"
      */  
-    public static final Symbol optPathFlatten = ARQConstants.allocSymbol("optPathFlatten") ;
+    public static final Symbol optPathFlatten = SystemARQ.allocSymbol("optPathFlatten") ;
     
     /** 
      *  Context key controlling whether the main query engine moves filters to the "best" place.
      *  Default is "true" - filter placement is done.
      */  
-    public static final Symbol optFilterPlacement = ARQConstants.allocSymbol("optFilterPlacement") ;
+    public static final Symbol optFilterPlacement = SystemARQ.allocSymbol("optFilterPlacement") ;
 
     /** 
      *  Context key controlling whether to do filter placement within BGP and quad blocks.
      *  Modies the effect of optFilterPlacement. 
      *  Default is "true" - filter placement is pushed into BGPs.
      */  
-    public static final Symbol optFilterPlacementBGP = ARQConstants.allocSymbol("optFilterPlacementBGP") ;
+    public static final Symbol optFilterPlacementBGP = SystemARQ.allocSymbol("optFilterPlacementBGP") ;
     
     /** 
      *  Context key controlling whether the main query engine moves filters to the "best" place using 
@@ -308,19 +319,19 @@ public class ARQ
      *  Filter placement, via {@link #optFilterPlacement} must also be active (which it is by default).
      * @see #optFilterPlacement
      */ 
-    public static final Symbol optFilterPlacementConservative = ARQConstants.allocSymbol("optFilterPlacementConservative") ;
+    public static final Symbol optFilterPlacementConservative = SystemARQ.allocSymbol("optFilterPlacementConservative") ;
 
     /** 
      *  Context key controlling whether an ORDER BY-LIMIT query is done avoiding total sort using an heap.
      *  Default is "true" - total sort if avoided by default when ORDER BY is used with LIMIT.
      */  
-    public static final Symbol optTopNSorting = ARQConstants.allocSymbol("optTopNSorting") ;
+    public static final Symbol optTopNSorting = SystemARQ.allocSymbol("optTopNSorting") ;
     
     /** 
      *  Context key controlling whether a DISTINCT-ORDER BY query is done by replacing the distinct with a reduced.
      *  Default is "true" - the reduced operator does not need to keep a data structure with all previously seen bindings.
      */  
-    public static final Symbol optDistinctToReduced = ARQConstants.allocSymbol("optDistinctToReduced") ;
+    public static final Symbol optDistinctToReduced = SystemARQ.allocSymbol("optDistinctToReduced") ;
     
     /**
      * Context key controlling whether a DISTINCT-ORDER BY query is done by applying the ORDER BY after the DISTINCT
@@ -330,7 +341,7 @@ public class ARQ
      * See {@link TransformOrderByDistinctApplication} for more discussion on exactly when this may apply
      * </p>
      */
-    public static final Symbol optOrderByDistinctApplication = ARQConstants.allocSymbol("optOrderByDistinctApplication");
+    public static final Symbol optOrderByDistinctApplication = SystemARQ.allocSymbol("optOrderByDistinctApplication");
 
     /** 
      *  Context key controlling whether the standard optimizer applies
@@ -338,7 +349,7 @@ public class ARQ
      *  This optimization is conservative - it does not take place if
      *  there is a potential risk of changing query semantics. 
      */  
-    public static final Symbol optFilterEquality = ARQConstants.allocSymbol("optFilterEquality") ;
+    public static final Symbol optFilterEquality = SystemARQ.allocSymbol("optFilterEquality") ;
     
     /**
      * Context key controlling whether the standard optimizer applies 
@@ -346,103 +357,102 @@ public class ARQ
      * This optimization is conservative - it does not take place if
      * there is a potential risk of changing query semantics
      */
-    public static final Symbol optFilterInequality = ARQConstants.allocSymbol("optFilterInequality") ;
+    public static final Symbol optFilterInequality = SystemARQ.allocSymbol("optFilterInequality") ;
     
     /**
      * Context key controlling whether the standard optimizer applies optimizations to implicit joins in FILTERs.
      * This optimization is conservative - it does not take place if there is a potential risk of changing query semantics.
      */
-    public static final Symbol optFilterImplicitJoin = ARQConstants.allocSymbol("optFilterImplicitJoin");
+    public static final Symbol optFilterImplicitJoin = SystemARQ.allocSymbol("optFilterImplicitJoin");
     
     /**
      * Context key controlling whether the standard optimizer applies optimizations to implicit left joins.
      * This optimization is conservative - it does not take place if there is a potential risk of changing query semantics.
      */
-    public static final Symbol optImplicitLeftJoin = ARQConstants.allocSymbol("optImplicitLeftJoin");
+    public static final Symbol optImplicitLeftJoin = SystemARQ.allocSymbol("optImplicitLeftJoin");
 
     /** 
      *  Context key for a declaration that xsd:strings and simple literals are
      *  different in the storage.  They are the same value in a memory store.
      *  When in doubt, xsd:strings are assumed to be the same value as simple literals   
      */  
-    public static final Symbol optTermStrings = ARQConstants.allocSymbol("optTermStrings") ;
+    public static final Symbol optTermStrings = SystemARQ.allocSymbol("optTermStrings") ;
     
     /**
      * Context key controlling whether the standard optimizer applies constant folding to expressions
      */
-    public static final Symbol optExprConstantFolding = ARQConstants.allocSymbol("optExprConstantFolding");
+    public static final Symbol optExprConstantFolding = SystemARQ.allocSymbol("optExprConstantFolding");
 
     /** 
      *  Context key controlling whether the standard optimizer applies
      *  optimizations to conjunctions (&&) in filters.
      */  
-    public static final Symbol optFilterConjunction = ARQConstants.allocSymbol("optFilterConjunction") ;
+    public static final Symbol optFilterConjunction = SystemARQ.allocSymbol("optFilterConjunction") ;
 
     /** 
      *  Context key controlling whether the standard optimizer applies
      *  optimizations to IN and NOT IN.
      */  
-    public static final Symbol optFilterExpandOneOf = ARQConstants.allocSymbol("optFilterExpandOneOf") ;
+    public static final Symbol optFilterExpandOneOf = SystemARQ.allocSymbol("optFilterExpandOneOf") ;
 
     /** 
      *  Context key controlling whether the standard optimizer applies
      *  optimizations to disjunctions (||) in filters.
      */  
-    public static final Symbol optFilterDisjunction = ARQConstants.allocSymbol("optFilterDisjunction") ;
+    public static final Symbol optFilterDisjunction = SystemARQ.allocSymbol("optFilterDisjunction") ;
     
     /**
      * Context key controlling whether the standard optimizer applies table empty promotion
      */
-    public static final Symbol optPromoteTableEmpty = ARQConstants.allocSymbol("optPromoteTableEmpty") ;
+    public static final Symbol optPromoteTableEmpty = SystemARQ.allocSymbol("optPromoteTableEmpty") ;
     
     /**
      * Context key controlling whether the standard optimizer applies optimizations to the evaluation
      * of joins to favour index joins wherever possible
      */
-    public static final Symbol optIndexJoinStrategy = ARQConstants.allocSymbol("optIndexJoinStrategy");
+    public static final Symbol optIndexJoinStrategy = SystemARQ.allocSymbol("optIndexJoinStrategy");
     
     /**
      * Context key controlling whether the standard optimizer applies optimizations where by some
      * assignments may be eliminated/inlined into the operators where their values are used only once
      */
-    public static final Symbol optInlineAssignments = ARQConstants.allocSymbol("optInlineAssignments");
+    public static final Symbol optInlineAssignments = SystemARQ.allocSymbol("optInlineAssignments");
     
     /**
      * Context key controlling whether the standard optimizer aggressively inlines assignments whose
      * values are used only once into operators where those expressions may be evaluated multiple times e.g. order
      */
-    public static final Symbol optInlineAssignmentsAggressive = ARQConstants.allocSymbol("optInlineAssignmentsAggressive");
+    public static final Symbol optInlineAssignmentsAggressive = SystemARQ.allocSymbol("optInlineAssignmentsAggressive");
     
     /**
      * Context key controlling whether the standard optimizater applies optimizations to joined BGPs to
      * merge them into single BGPs.
      * By default, this transformation is applied.
      */
-    public static final Symbol optMergeBGPs = ARQConstants.allocSymbol("optMergeBGPs");
+    public static final Symbol optMergeBGPs = SystemARQ.allocSymbol("optMergeBGPs");
     
     /**
      * Context key controlling whether the standard optimizater applies the optimization
      * to combine stacks of (extend) into one compound operation.  Ditto (assign). 
      * By default, this transformation is applied.
      */
-    public static final Symbol optMergeExtends = ARQConstants.allocSymbol("optMergeExtends");
+    public static final Symbol optMergeExtends = SystemARQ.allocSymbol("optMergeExtends");
 
     /** 
      *  Context key controlling whether the main query engine processes property functions.
-     *  
      */  
-    public static final Symbol propertyFunctions = ARQConstants.allocSymbol("propertyFunctions") ;
+    public static final Symbol propertyFunctions = SystemARQ.allocSymbol("propertyFunctions") ;
     
     /**
      * Expression evaluation without extension types (e.g. xsd:date, language tags)
      */
-    public static final Symbol extensionValueTypes = ARQConstants.allocSymbol("extensionValueTypesExpr") ;
+    public static final Symbol extensionValueTypes = SystemARQ.allocSymbol("extensionValueTypesExpr") ;
 
     /**
      * Generate the ToList operation in the algebra (as ARQ is stream based, ToList is a non-op).
      * Default is not to do so.  Strict mode will also enable this.
      */
-    public static final Symbol generateToList = ARQConstants.allocSymbol("generateToList") ;
+    public static final Symbol generateToList = SystemARQ.allocSymbol("generateToList") ;
 
     /** Set strict mode, including expression evaluation */
     public static void setStrictMode() { setStrictMode(ARQ.getContext()) ; }
@@ -514,13 +524,8 @@ public class ARQ
    
     /** The date and time at which this release was built */   
     public static final String BUILD_DATE   = metadata.get(PATH+".build.datetime", "unset") ;
-    
-    // A correct way to manage without synchonized using the double checked locking pattern.
-    //   http://en.wikipedia.org/wiki/Double-checked_locking
-    //   http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html 
-    private static volatile boolean initialized = false ;
-    private static final Object initLock = new Object() ;
 
+    // Initialize now in case other initialization uses getContext(). 
     private static Context globalContext = null ;
 
     /** Ensure things have started - applications do not need call this.
@@ -528,19 +533,24 @@ public class ARQ
      * Note the final static initializer call 
      */
     
-    public static void init()
-    { 
-        if ( initialized )
+    static { JenaSystem.init(); }
+    
+    public static void init() { 
+        if ( initialized ) {
             return ;
+        }
         synchronized(initLock)
         {
-            if ( initialized )
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("ARQ.init - skip") ;
                 return ;
+            }
+             
             initialized = true ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("ARQ.init - start") ;
             globalContext = defaultSettings() ;
-            
-            RIOT.init() ;
-            StageBuilder.init() ;
             ARQMgt.init() ;         // After context and after PATH/NAME/VERSION/BUILD_DATE are set
             MappingRegistry.addPrefixMapping(ARQ.arqSymbolPrefix, ARQ.arqParamNS) ;
             
@@ -551,15 +561,15 @@ public class ARQ
             // Register RIOT details here, not earlier, to avoid
             // initialization loops with RIOT.init() called directly.
             RIOT.register() ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("ARQ.init - finish") ;
         }
     }
     
-    // Force a call
-    static { init() ; }
-    
     /* Side effects */
     private static Context defaultSettings()
     {
+        // This must be exeutable before initialization 
         SystemARQ.StrictDateTimeFO      = false ;
         SystemARQ.ValueExtensions       = true ;
         SystemARQ.EnableRomanNumerals   = false ; 
@@ -577,7 +587,6 @@ public class ARQ
 
     public static Context getContext()
     { 
-        //ARQ.init() ;
         return globalContext ;
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/query/Query.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/Query.java b/jena-arq/src/main/java/org/apache/jena/query/Query.java
index 6d6289a..3ff5b3f 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/Query.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/Query.java
@@ -40,6 +40,7 @@ import org.apache.jena.sparql.syntax.Element ;
 import org.apache.jena.sparql.syntax.PatternVars ;
 import org.apache.jena.sparql.syntax.Template ;
 import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.system.JenaSystem ;
 
 /** The data structure for a query as presented externally.
  *  There are two ways of creating a query - use the parser to turn
@@ -54,7 +55,7 @@ import org.apache.jena.sparql.util.FmtUtils ;
 
 public class Query extends Prologue implements Cloneable, Printable
 {
-    static { ARQ.init() ; /* Ensure everything has started properly */ }
+    static { JenaSystem.init() ; /* Ensure everything has started properly */ }
     
     public static final int QueryTypeUnknown    = -123 ;
     public static final int QueryTypeSelect     = 111 ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java b/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
index b5cf428..d48fb0c 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
@@ -49,6 +49,7 @@ import org.apache.jena.sparql.core.Quad ;
 import org.apache.jena.sparql.graph.GraphFactory ;
 import org.apache.jena.sparql.util.Context ;
 import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
@@ -78,10 +79,7 @@ import org.slf4j.LoggerFactory ;
 
 public class RDFDataMgr
 {
-    static { RIOT.init() ; }
-    /* Maybe:
-     * static for global (singleton) and locally tailored. 
-     */
+    static { JenaSystem.init() ; }
     
     static Logger log = LoggerFactory.getLogger(RDFDataMgr.class) ;
     private static String riotBase = "http://jena.apache.org/riot/" ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
index 9f766d6..8c45c68 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RIOT.java
@@ -21,6 +21,7 @@ package org.apache.jena.riot ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.mgt.SystemInfo ;
+import org.apache.jena.system.JenaSystem ;
 
 public class RIOT {
     /** IRI for RIOT */
@@ -52,10 +53,15 @@ public class RIOT {
         if ( initialized )
             return ;
         synchronized (initLock) {
-            if ( initialized )
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("RIOT.init - skip") ;
                 return ;
+            }
             initialized = true ;
-            // Becareful with what this touches - don't touch ARQ.*
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("RIOT.init - start") ;
+            // Be careful with what this touches - don't touch ARQ.*
             // because that depends on Jena core and we may be
             // initializing because IO_Ctl (ie. Jena core)
             // called RIOT.init.
@@ -68,6 +74,8 @@ public class RIOT {
             // Don't register JMX info with ARQ as it may not be initialized
             // itself and we can get into a circularity.
             // This is done in ARQ.init at the proper moment.
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("RIOT.init - finish") ;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/riot/system/InitRIOT.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/InitRIOT.java b/jena-arq/src/main/java/org/apache/jena/riot/system/InitRIOT.java
new file mode 100644
index 0000000..18b514b
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/InitRIOT.java
@@ -0,0 +1,39 @@
+/**
+ * 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.riot.system;
+
+import org.apache.jena.riot.RIOT ;
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+
+/** RIOT initialization. Used by {@code JenaSystem} */
+public class InitRIOT implements JenaSubsystemLifecycle {
+
+    @Override
+    public void start() {
+        RIOT.init();
+    }
+
+    @Override
+    public void stop() {}
+    
+    @Override
+    public int level() {
+        return 20 ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java b/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
index cf66c4d..ffa319e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
@@ -19,7 +19,6 @@
 package org.apache.jena.sparql;
 
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.query.ARQ ;
 import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.shared.impl.PrefixMappingImpl ;
 import org.apache.jena.sparql.util.Symbol ;
@@ -28,7 +27,8 @@ import org.apache.jena.vocabulary.RDF ;
 import org.apache.jena.vocabulary.RDFS ;
 
 /**
- * Internal constants - configuration is in class ARQ */
+ * Internal constants - configuration is in class ARQ
+ */
 public class ARQConstants
 {
     /** The prefix of XQuery/Xpath functions and operator */
@@ -104,20 +104,6 @@ public class ARQConstants
     }
     public static PrefixMapping getGlobalPrefixMap() { return globalPrefixMap ; }
     
-    public static Symbol allocSymbol(String shortName)
-    { 
-        if ( shortName.startsWith(ARQ.arqSymbolPrefix)) 
-            throw new ARQInternalErrorException("Symbol short name begins with the ARQ namespace prefix: "+shortName) ;
-        if ( shortName.startsWith("http:")) 
-            throw new ARQInternalErrorException("Symbol short name begins with http: "+shortName) ;
-        return allocSymbol(ARQ.arqParamNS, shortName) ;
-    }
-    
-    public static Symbol allocSymbol(String base, String shortName)
-    {
-        return Symbol.create(base+shortName) ;
-    }
-
     /* Variable names and allocated variables.
      * NB Must agree with the variable parsing rules in SSE 
      * Allocated variables use names that are not legal in SPARQL.
@@ -247,33 +233,33 @@ public class ARQConstants
     public static final Symbol sysVarAllocAnon          = Symbol.create(systemVarNS+"namedVarAnon") ;
     
     /** Graphs forming the default graph (List&lt;String&gt;) (Dynamic dataset) */
-    public static final Symbol symDatasetDefaultGraphs     = allocSymbol("datasetDefaultGraphs") ;
+    public static final Symbol symDatasetDefaultGraphs     = SystemARQ.allocSymbol("datasetDefaultGraphs") ;
     
     /** Graphs forming the named graphs (List&lt;String&gt;) (Dynamic dataset) */
-    public static final Symbol symDatasetNamedGraphs       = allocSymbol("datasetNamedGraphs") ;
+    public static final Symbol symDatasetNamedGraphs       = SystemARQ.allocSymbol("datasetNamedGraphs") ;
     
     /** Context key for making all SELECT queries have DISTINCT applied, whether stated ot not */
-    public static final Symbol autoDistinct             = ARQConstants.allocSymbol("autoDistinct") ;
+    public static final Symbol autoDistinct             = SystemARQ.allocSymbol("autoDistinct") ;
     
     // Context keys : some here, some in ARQ - sort out
     
     /** The property function registry key */
     public static final Symbol registryPropertyFunctions =
-        ARQConstants.allocSymbol("registryPropertyFunctions") ;
+        SystemARQ.allocSymbol("registryPropertyFunctions") ;
     
     /** The describe handler registry key */
     public static final Symbol registryDescribeHandlers =
-        ARQConstants.allocSymbol("registryDescribeHandlers") ;
+        SystemARQ.allocSymbol("registryDescribeHandlers") ;
 
     /** The function library registry key */
     public static final Symbol registryFunctions =
-        ARQConstants.allocSymbol("registryFunctions") ;
+        SystemARQ.allocSymbol("registryFunctions") ;
     
     /** The function library registry key */
     public static final Symbol registryProcedures =
-        ARQConstants.allocSymbol("registryProcedures") ;
+        SystemARQ.allocSymbol("registryProcedures") ;
     
     /** The extension library registry key */
     public static final Symbol registryExtensions =
-        ARQConstants.allocSymbol("registryExtensions") ;
+        SystemARQ.allocSymbol("registryExtensions") ;
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java b/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
index 2cdbeb4..41a2f95 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
@@ -27,6 +27,7 @@ import org.apache.jena.atlas.lib.Sync ;
 import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.compose.Polyadic ;
+import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.reasoner.InfGraph ;
@@ -34,10 +35,12 @@ import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.graph.GraphWrapper ;
 import org.apache.jena.sparql.mgt.ARQMgt ;
 import org.apache.jena.sparql.mgt.SystemInfo ;
+import org.apache.jena.sparql.util.Symbol ;
 
 public class SystemARQ
 {
     // Various system wide settings, "constants" that might change e.g. test setups
+    // ** This can be loaded before the rest of ARQ is initialized **
 
     // NodeValues work without the context so somethings only have global settings.
     
@@ -156,4 +159,18 @@ public class SystemARQ
         return versions.iterator() ;
     }
 
+    public static Symbol allocSymbol(String shortName)
+    { 
+        if ( shortName.startsWith(ARQ.arqSymbolPrefix)) 
+            throw new ARQInternalErrorException("Symbol short name begins with the ARQ namespace prefix: "+shortName) ;
+        if ( shortName.startsWith("http:")) 
+            throw new ARQInternalErrorException("Symbol short name begins with http: "+shortName) ;
+        return SystemARQ.allocSymbol(ARQ.arqParamNS, shortName) ;
+    }
+
+    public static Symbol allocSymbol(String base, String shortName)
+    {
+        return Symbol.create(base+shortName) ;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/Optimize.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/Optimize.java b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/Optimize.java
index 8c2347a..75e9d14 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/Optimize.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/Optimize.java
@@ -20,6 +20,7 @@ package org.apache.jena.sparql.algebra.optimize;
 
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.ARQConstants ;
+import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.algebra.* ;
 import org.apache.jena.sparql.algebra.op.OpLabel ;
 import org.apache.jena.sparql.engine.ExecutionContext ;
@@ -116,7 +117,7 @@ public class Optimize implements Rewrite
     }
 
     /** Alternative name for compatibility only */
-    public static final Symbol filterPlacementOldName = ARQConstants.allocSymbol("filterPlacement") ;
+    public static final Symbol filterPlacementOldName = SystemARQ.allocSymbol("filterPlacement") ;
     
     @Override
     public Op rewrite(Op op)

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
index 2c49133..26bef8e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/TransformTopN.java
@@ -24,7 +24,7 @@ import java.util.Set ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.Query ;
 import org.apache.jena.query.SortCondition ;
-import org.apache.jena.sparql.ARQConstants ;
+import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.algebra.Op ;
 import org.apache.jena.sparql.algebra.TransformCopy ;
 import org.apache.jena.sparql.algebra.op.* ;
@@ -43,7 +43,7 @@ public class TransformTopN extends TransformCopy {
     // This must be less than ARQ.spillToDiskThreshold.
     // Otherwise DISTINCT ends up reordering. 
 	private static final int defaultTopNSortingThreshold = 1000;
-	public static final Symbol externalSortBufferSize = ARQConstants.allocSymbol("topNSortingThreshold") ;
+	public static final Symbol externalSortBufferSize = SystemARQ.allocSymbol("topNSortingThreshold") ;
 
 	/* For reference: from the algebra generation of a query, the order of operations is: 
 	 *  Limit/Offset

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
index eb4fde5..c2e6295 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
@@ -33,6 +33,7 @@ import org.apache.jena.sparql.util.MappingRegistry ;
 import org.apache.jena.sparql.util.Symbol ;
 import org.apache.jena.sparql.util.TypeNotUniqueException ;
 import org.apache.jena.sparql.util.graph.GraphUtils ;
+import org.apache.jena.system.JenaSystem ;
 
 public class AssemblerUtils
 {
@@ -45,7 +46,7 @@ public class AssemblerUtils
     
     private static boolean initialized = false ; 
     
-    static { ARQ.init(); init() ; } 
+    static { JenaSystem.init() ; init() ; } 
     
     static public void init()
     {

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/Service.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/Service.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/Service.java
index 730f272..162aa0d 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/Service.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/Service.java
@@ -28,7 +28,7 @@ import org.apache.jena.query.Query ;
 import org.apache.jena.query.QueryExecException ;
 import org.apache.jena.query.ResultSet ;
 import org.apache.jena.query.ResultSetFactory ;
-import org.apache.jena.sparql.ARQConstants ;
+import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.algebra.Op ;
 import org.apache.jena.sparql.algebra.OpAsQuery ;
 import org.apache.jena.sparql.algebra.OpVars ;
@@ -51,22 +51,22 @@ public class Service {
     /**
      * Use to set the HttpQuery.allowDeflate flag.
      */
-    public static final Symbol queryDeflate = ARQConstants.allocSymbol(base, "queryDeflate");
+    public static final Symbol queryDeflate = SystemARQ.allocSymbol(base, "queryDeflate");
 
     /**
      * Use to set the HttpQuery.allowGZip flag.
      */
-    public static final Symbol queryGzip = ARQConstants.allocSymbol(base, "queryGzip");
+    public static final Symbol queryGzip = SystemARQ.allocSymbol(base, "queryGzip");
 
     /**
      * Use to set the user id for basic auth.
      */
-    public static final Symbol queryAuthUser = ARQConstants.allocSymbol(base, "queryAuthUser");
+    public static final Symbol queryAuthUser = SystemARQ.allocSymbol(base, "queryAuthUser");
 
     /**
      * Use to set the user password for basic auth.
      */
-    public static final Symbol queryAuthPwd = ARQConstants.allocSymbol(base, "queryAuthPwd");
+    public static final Symbol queryAuthPwd = SystemARQ.allocSymbol(base, "queryAuthPwd");
 
     /**
      * Use this Symbol to allow passing additional service context variables
@@ -77,7 +77,7 @@ public class Service {
      * 
      * @see org.apache.jena.sparql.engine.http.Service
      */
-    public static final Symbol serviceContext = ARQConstants.allocSymbol(base, "serviceContext");
+    public static final Symbol serviceContext = SystemARQ.allocSymbol(base, "serviceContext");
 
     /**
      * Control whether SERVICE processing is allowed.
@@ -85,7 +85,7 @@ public class Service {
      * then SERVICE is not allowed.
      */
     
-    public static final Symbol serviceAllowed = ARQConstants.allocSymbol(base, "serviceAllowed");
+    public static final Symbol serviceAllowed = SystemARQ.allocSymbol(base, "serviceAllowed");
     
     /**
      * Set timeout. The value of this symbol gives the value of the timeout in
@@ -99,7 +99,7 @@ public class Service {
      * The first value is passed to HttpQuery.setConnectTimeout() the second, if
      * it exists, is passed to HttpQuery.setReadTimeout()
      */
-    public static final Symbol queryTimeout = ARQConstants.allocSymbol(base, "queryTimeout");
+    public static final Symbol queryTimeout = SystemARQ.allocSymbol(base, "queryTimeout");
 
     /**
      * Executes a service operator

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/AbstractIterHashJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/AbstractIterHashJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/AbstractIterHashJoin.java
index 7d31354..11701e1 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/AbstractIterHashJoin.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/AbstractIterHashJoin.java
@@ -47,7 +47,7 @@ public abstract class AbstractIterHashJoin extends QueryIter2 {
     protected final JoinKey               joinKey ;
     protected final HashProbeTable        hashTable ;
 
-    private Iterator<Binding>           iterStream ;
+    private QueryIterator               iterStream ;
     private Binding                     rowStream       = null ;
     private Iterator<Binding>           iterCurrent ;
     private boolean                     yielded ;       // Flag to note when current probe causes a result. 
@@ -227,11 +227,14 @@ public abstract class AbstractIterHashJoin extends QueryIter2 {
                          hashTable.s_countScanMiss, hashTable.s_maxBucketSize, hashTable.s_noKeyBucketSize) ;
             System.out.println(x) ;
         }
+        // In case it's a peek iterator.
+        iterStream.close() ;
         hashTable.clear(); 
     }
 
     @Override
     protected void requestSubCancel() {
+        iterStream.close() ;
         hashTable.clear(); 
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/StageBuilder.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/StageBuilder.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/StageBuilder.java
index f4ce821..1a1ec45 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/StageBuilder.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/StageBuilder.java
@@ -18,6 +18,7 @@
 
 package org.apache.jena.sparql.engine.main;
 
+import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.sparql.core.BasicPattern ;
 import org.apache.jena.sparql.engine.ExecutionContext ;
@@ -66,28 +67,23 @@ public class StageBuilder
     
     // -------- Initialize
     
-    public static void init()
-    {
-        StageGenerator gen = getGenerator(ARQ.getContext()) ;
-        if ( gen == null )
-        {
-            gen = standardGenerator() ;
-            setGenerator(ARQ.getContext(), gen) ;
-        }
-    }
+    private static StageGenerator defaultStageGenerator = new StageGeneratorGeneric() ; 
     
     /** The plain StageGenerator, no reordering */
     public static StageGenerator executeInline = new StageGenerator() {
         @Override
         public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt)
         {
-                return QueryIterBlockTriples.create(input, pattern, execCxt) ;
+            return QueryIterBlockTriples.create(input, pattern, execCxt) ;
         }} ;
         
     // -------- Manage StageGenerator registration
     
     public static void setGenerator(Context context, StageGenerator builder)
     {
+        if ( ARQ.stageGenerator == null )
+            // Indicator of initialization problems
+            Log.warn(StageBuilder.class, "ARQ.stageGenerator = null") ;
         context.set(ARQ.stageGenerator, builder) ;
     }
     
@@ -105,7 +101,7 @@ public class StageBuilder
     
     public static StageGenerator standardGenerator()
     {
-        return new StageGeneratorGeneric() ;
+        return defaultStageGenerator ; 
     }
     
     public static StageGenerator chooseStageGenerator(Context context)

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/engine/optimizer/reorder/ReorderFixed.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/optimizer/reorder/ReorderFixed.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/optimizer/reorder/ReorderFixed.java
index 4afbd43..4fddc7d 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/optimizer/reorder/ReorderFixed.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/optimizer/reorder/ReorderFixed.java
@@ -69,6 +69,7 @@ public class ReorderFixed extends ReorderTransformationSubstitution {
     static { init() ; }
     
     private static void init() {
+        //ype = Item.createNode(NodeConst.nodeRDFType) ;
         // rdf:type can be a bad choice e.g rdf:type rdf:Resource
         // with inference enabled.
         // Weight use of rdf:type worse then the general pattern

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/lang/ParserSPARQL11.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/lang/ParserSPARQL11.java b/jena-arq/src/main/java/org/apache/jena/sparql/lang/ParserSPARQL11.java
index a459d32..6c13d62 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/lang/ParserSPARQL11.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/lang/ParserSPARQL11.java
@@ -113,6 +113,7 @@ public class ParserSPARQL11 extends SPARQLParser
         catch (JenaException ex)  { throw new QueryException(ex.getMessage(), ex) ; }
         catch (Error err)
         {
+            System.err.println(err.getMessage()) ;
             // The token stream can throw errors.
             throw new QueryParseException(err.getMessage(), err, -1, -1) ;
         }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/sse/SSE.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/sse/SSE.java b/jena-arq/src/main/java/org/apache/jena/sparql/sse/SSE.java
index a9d67b4..f50425c 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/sse/SSE.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/sse/SSE.java
@@ -53,10 +53,13 @@ import org.apache.jena.sparql.sse.writers.WriterGraph ;
 import org.apache.jena.sparql.sse.writers.WriterNode ;
 import org.apache.jena.sparql.sse.writers.WriterOp ;
 import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.util.FileUtils ;
 
 public class SSE
 {
+    static { JenaSystem.init(); }
+    
     private SSE() {}
     
     // Short prefix map for convenience (used in parsing, not in writing).

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/java/org/apache/jena/sparql/system/InitARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/system/InitARQ.java b/jena-arq/src/main/java/org/apache/jena/sparql/system/InitARQ.java
new file mode 100644
index 0000000..d88d989
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/system/InitARQ.java
@@ -0,0 +1,39 @@
+/**
+ * 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.sparql.system;
+
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.system.JenaSubsystemLifecycle ;
+
+/** ARQ initialization. Used by {@code JenaSystem} */
+public class InitARQ implements JenaSubsystemLifecycle {
+    
+    @Override
+    public void start() {
+        ARQ.init();
+    }
+
+    @Override
+    public void stop() {}
+
+    @Override
+    public int level() {
+        return 30 ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-arq/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..62d3fcd
--- /dev/null
+++ b/jena-arq/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1,2 @@
+org.apache.jena.riot.system.InitRIOT
+org.apache.jena.sparql.system.InitARQ
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/test/java/arq/qtest.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/arq/qtest.java b/jena-arq/src/test/java/arq/qtest.java
index e26487f..87a9d32 100644
--- a/jena-arq/src/test/java/arq/qtest.java
+++ b/jena-arq/src/test/java/arq/qtest.java
@@ -20,11 +20,12 @@ package arq;
 
 import java.io.File ;
 
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModEngine ;
 import jena.cmd.ArgDecl;
 import jena.cmd.CmdException;
 import jena.cmd.TerminationException;
 import junit.framework.TestSuite ;
-
 import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.ARQ ;
@@ -46,9 +47,6 @@ import org.apache.jena.vocabulary.DCTerms ;
 import org.apache.jena.vocabulary.RDF ;
 import org.apache.jena.vocabulary.XSD ;
 
-import arq.cmdline.CmdARQ ;
-import arq.cmdline.ModEngine ;
-
 
 /** A program to execute query test suites
  * 
@@ -80,7 +78,6 @@ public class qtest extends CmdARQ
     
     public static void main (String... argv)
     {
-        ARQ.init();
         try {
             new qtest(argv).mainRun() ;
         }

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java b/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
index 5807000..c3c2639 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/ARQTestSuite.java
@@ -18,19 +18,19 @@
 
 package org.apache.jena.sparql;
 
+import arq.TS_Cmd ;
 import junit.framework.JUnit4TestAdapter ;
 import junit.framework.TestSuite ;
 import org.apache.jena.atlas.legacy.BaseTest2 ;
 import org.apache.jena.atlas.legacy.TC_Atlas_ARQ ;
 import org.apache.jena.common.TC_Common ;
-import org.apache.jena.query.ARQ ;
 import org.apache.jena.riot.TC_Riot ;
 import org.apache.jena.sparql.engine.main.QueryEngineMain ;
 import org.apache.jena.sparql.engine.ref.QueryEngineRef ;
 import org.apache.jena.sparql.expr.E_Function ;
 import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.web.TS_Web ;
-import arq.TS_Cmd ;
 
 /**
  * All the ARQ tests 
@@ -82,7 +82,7 @@ public class ARQTestSuite extends TestSuite
 	private ARQTestSuite()
 	{
         super("All ARQ tests");
-        ARQ.init() ;
+        JenaSystem.init();
         // Tests should be silent.
         NodeValue.VerboseWarnings = false ;
         E_Function.WarnOnUnknownFunction = false ;

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/jena/rdfcat.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/jena/rdfcat.java b/jena-core/src/main/java/jena/rdfcat.java
index f05517a..c292d45 100644
--- a/jena-core/src/main/java/jena/rdfcat.java
+++ b/jena-core/src/main/java/jena/rdfcat.java
@@ -31,9 +31,9 @@ import java.util.* ;
 import java.util.function.BiConsumer;
 
 import org.apache.jena.rdf.model.* ;
-import org.apache.jena.rdf.model.impl.IO_Ctl ;
 import org.apache.jena.rdf.model.impl.RDFWriterFImpl ;
 import org.apache.jena.shared.NoWriterForLangException ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.util.FileManager ;
 import org.apache.jena.util.FileUtils ;
 import org.apache.jena.vocabulary.OWL ;
@@ -211,7 +211,7 @@ public class rdfcat
 
     /* main loop */
     protected void go( String[] args ) {
-    	
+    	JenaSystem.init();
         if ( ! suppressDeprecationBanner ) {
             System.err.println("------------------------------------------------------------------");
     		System.err.println("   DEPRECATED: Please use 'riot' instead.");
@@ -220,9 +220,6 @@ public class rdfcat
     		System.err.println() ;
         }
     	
-        // ensure we use the new RIOT parser subsystem
-        enableRIOTParser();
-
         m_cmdLine.process( args );
 
         // process any stored items
@@ -399,13 +396,6 @@ public class rdfcat
         return n.isLiteral() ? ((Literal) n).getLexicalForm() : ((Resource) n).getURI();
     }
 
-    /**
-     * Enable the new RIOT parser subsystem if it is available
-     */
-    private void enableRIOTParser() {
-        IO_Ctl.init(); 
-    }
-
     //==============================================================================
     // Inner class definitions
     //==============================================================================

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/assembler/Assembler.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/assembler/Assembler.java b/jena-core/src/main/java/org/apache/jena/assembler/Assembler.java
index 78e4810..33d1d33 100644
--- a/jena-core/src/main/java/org/apache/jena/assembler/Assembler.java
+++ b/jena-core/src/main/java/org/apache/jena/assembler/Assembler.java
@@ -28,6 +28,7 @@ import org.apache.jena.rdf.model.* ;
 */
 public interface Assembler
     {
+    
     /**
         The core operation: answer a new object constructed according to the
         object description hanging from <code>root</code>, using the assembler

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/assembler/assemblers/AssemblerBase.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/assembler/assemblers/AssemblerBase.java b/jena-core/src/main/java/org/apache/jena/assembler/assemblers/AssemblerBase.java
index 560eada..e1f9bc7 100644
--- a/jena-core/src/main/java/org/apache/jena/assembler/assemblers/AssemblerBase.java
+++ b/jena-core/src/main/java/org/apache/jena/assembler/assemblers/AssemblerBase.java
@@ -23,10 +23,12 @@ import org.apache.jena.assembler.* ;
 import org.apache.jena.assembler.exceptions.* ;
 import org.apache.jena.rdf.model.* ;
 import org.apache.jena.shared.JenaException ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.vocabulary.RDF ;
 
 public abstract class AssemblerBase implements Assembler
-    {
+{
+    static { JenaSystem.init(); }
 
     @Override
     public final Object open( Resource root )

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java b/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java
index 55bbda8..b1243dc 100644
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java
+++ b/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java
@@ -37,6 +37,7 @@ import org.apache.jena.reasoner.InfGraph ;
 import org.apache.jena.reasoner.Reasoner ;
 import org.apache.jena.reasoner.ReasonerRegistry ;
 import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.system.JenaSystem ;
 
 /**
     ModelFactory provides methods for creating standard kinds of Model.
@@ -45,6 +46,7 @@ import org.apache.jena.shared.PrefixMapping ;
 
 public class ModelFactory extends ModelFactoryBase
 {
+    static { JenaSystem.init(); }
     /**
         No-one can make instances of this.
     */

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/rdf/model/impl/IO_Ctl.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/IO_Ctl.java b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/IO_Ctl.java
deleted file mode 100644
index cc73734..0000000
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/IO_Ctl.java
+++ /dev/null
@@ -1,71 +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.apache.jena.rdf.model.impl;
-
-import java.lang.reflect.Method ;
-
-
-public class IO_Ctl
-{
-    private static volatile boolean initialized = false ;
-    private static final Object initLock = new Object() ;
-    public static void init()
-    {
-        if ( initialized )
-            return ;
-        synchronized(initLock)
-        {
-            try {
-                initialized = true ;
-                callByRefection("org.apache.jena.riot.RIOT", "init") ;
-            } catch (ExceptionInInitializerError e)
-            {
-                e.printStackTrace(System.err) ;
-                if ( e.getCause() != null )
-                {
-                    System.err.println("****") ;
-                    e.getCause().printStackTrace(System.err) ;
-                }
-                System.exit(99) ;
-            }
-        }
-    }
-
-    // Call a static of no arguments by reflection.
-    private static void callByRefection(String className, String staticMethod)
-    {
-        Class<? > cls = null ;
-        try { cls = Class.forName(className) ; }
-        catch (ClassNotFoundException ex) {
-            // System.err.println(className+" not on the classpath") ;
-            return ;
-        }
-        
-        Method m = null ;
-        try
-        {
-            m = cls.getMethod(staticMethod ) ;
-            m.invoke(null, (Object[])null) ;
-        } catch (Exception e) 
-        {
-            e.printStackTrace();
-        }        //System.err.println("INIT 2") ;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
index 96ab379..ff93f69 100644
--- a/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
+++ b/jena-core/src/main/java/org/apache/jena/rdf/model/impl/ModelCom.java
@@ -35,6 +35,7 @@ import org.apache.jena.graph.impl.LiteralLabelFactory ;
 import org.apache.jena.rdf.model.* ;
 import org.apache.jena.shared.* ;
 import org.apache.jena.shared.impl.PrefixMappingImpl ;
+import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.util.CollectionFactory ;
 import org.apache.jena.util.iterator.* ;
 import org.apache.jena.vocabulary.RDF ;
@@ -59,7 +60,7 @@ implements Model, PrefixMapping, Lock
         // This forces RIOT (in ARQ) to initialize but after Jena readers/writers
         // have cleanly initialized from the calls of  RDFReaderFImpl and RDFWriterFImpl
         // above.  RIOT initialization happens before model.read can be called.
-        IO_Ctl.init();
+        JenaSystem.init() ;
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/system/InitJenaCore.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/InitJenaCore.java b/jena-core/src/main/java/org/apache/jena/system/InitJenaCore.java
new file mode 100644
index 0000000..83b9151
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/system/InitJenaCore.java
@@ -0,0 +1,67 @@
+/**
+ * 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.system;
+
+import org.apache.jena.vocabulary.OWL ;
+import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.vocabulary.RDFS ;
+
+public class InitJenaCore  implements JenaSubsystemLifecycle {
+
+    @Override
+    public void start() {
+        init() ;
+    }
+
+    @Override
+    public void stop() {}
+    
+    @Override
+    public int level() {
+        return 10 ;
+    }
+    
+    private static volatile boolean initialized = false ;
+    private static Object           initLock    = new Object() ;
+
+    public static void init() {
+        if ( initialized )
+            return ;
+        synchronized (initLock) {
+            if ( initialized ) {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("JenaCore.init - skip") ;
+                return ;
+            }
+            initialized = true ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("JenaCore.init - start") ;
+
+            // Initialization
+            // Touch classes with constants.  
+            // This isn't necessary but it makes it more deterministic.
+            // These constants are resused in various places.  
+            RDF.getURI() ;
+            RDFS.getURI() ;
+            OWL.getURI() ;
+            if ( JenaSystem.DEBUG_INIT )
+                System.err.println("JenaCore.init - finish") ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
new file mode 100644
index 0000000..daf6b2a
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemLifecycle.java
@@ -0,0 +1,32 @@
+/**
+ * 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.system;
+
+/** Lifecycle interface for jena modules and subsystems. */ 
+public interface JenaSubsystemLifecycle {
+    /** start - a module should be ready to oeprate when this returns */  
+    public void start() ;
+    /** stop - a module should have preformed any shutdown operations by the time this returns */   
+    public void stop() ;
+    /** Provide a marker as to the level to order initialization, 10,20,30,... 
+     * See {@link JenaSystem} for details.
+     */
+    default public int level() { return 9999 ; }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistry.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistry.java b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistry.java
new file mode 100644
index 0000000..3e7a2cb
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistry.java
@@ -0,0 +1,56 @@
+/**
+ * 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.system;
+
+import java.util.List ;
+
+/**
+ * A {@code JenaSubsystemCollector} is a set of objects implementing {@link JenaSubsystemLifecycle}.
+ * <p>
+ * It is a set - at most one entry.
+ * <p>Discovered in some way.
+ */
+public interface JenaSubsystemRegistry {
+    
+    /** Load - peform some kinds of search for {@link JenaSubsystemLifecycle} implementations.
+     * This is called once only.
+     */
+    public void load();
+    
+    /** Add to the colection. */
+    public void add(JenaSubsystemLifecycle module);
+
+    /** check whether registered */
+    public boolean isRegistered(JenaSubsystemLifecycle module);
+
+    /** Remove from the colection. */
+    public void remove(JenaSubsystemLifecycle module);
+
+    public int size();
+
+    public boolean isEmpty();
+
+    /**
+     * Return the registered items a copied list.
+     * The list is detached from the
+     * registry and the caller can mutate it.
+     */
+    public List<JenaSubsystemLifecycle> snapshot();
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
new file mode 100644
index 0000000..3e12fca
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
@@ -0,0 +1,89 @@
+/**
+ * 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.system;
+
+import java.util.ArrayList ;
+import java.util.List ;
+import java.util.ServiceLoader ;
+
+/** Implementation of {@link JenaSubsystemRegistry} for use in the simple 
+ * but common case of runing a a collection (classpath) of jars. 
+ */
+public class JenaSubsystemRegistryBasic implements JenaSubsystemRegistry {
+    
+    private List<JenaSubsystemLifecycle> registry = new ArrayList<>() ;
+    private Object registryLock = new Object() ;
+
+    public JenaSubsystemRegistryBasic() {
+    }
+     
+    @Override
+    public void load() {
+        synchronized (registryLock) {
+            // Find subsystems asking for initialization. 
+            ServiceLoader<JenaSubsystemLifecycle> sl = ServiceLoader.load(JenaSubsystemLifecycle.class) ;
+            sl.forEach(life-> {
+                if ( JenaSystem.DEBUG_INIT )
+                    System.err.println("  "+life.getClass().getSimpleName()) ;
+                add(life);
+            }) ;
+        }
+    }
+
+    @Override
+    public void add(JenaSubsystemLifecycle module) {
+        synchronized (registryLock) {
+            if ( ! registry.contains(module) )
+                registry.add(module);
+        }
+    }
+
+    @Override
+    public boolean isRegistered(JenaSubsystemLifecycle module) {
+        synchronized (registryLock) {
+            return registry.contains(module);
+        }
+    }
+
+    @Override
+    public void remove(JenaSubsystemLifecycle module) {
+        synchronized (registryLock) {
+            registry.remove(module);
+        }
+    }
+
+    @Override
+    public int size() {
+        synchronized (registryLock) {
+            return registry.size();
+        }
+    }
+
+    @Override
+    public boolean isEmpty() {
+        synchronized (registryLock) {
+            return registry.isEmpty();
+        }
+    }
+    
+    @Override
+    public List<JenaSubsystemLifecycle> snapshot() {
+        return new ArrayList<>(registry) ;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
new file mode 100644
index 0000000..48603f4
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
@@ -0,0 +1,175 @@
+/**
+ * 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.system;
+
+import java.util.Collections ;
+import java.util.Comparator ;
+import java.util.List ;
+import java.util.function.Consumer ;
+
+import org.apache.log4j.Logger ;
+
+/** Jena "system" - simple controls for ensuring components are loaded and initialized.
+ * <p>
+ * All initialization should be concurrent and thread-safe.  In particular,
+ * some subsystems need initialization some sort of order (e.g. ARQ before TDB).
+ * <p>
+ * This is achieved by "levels": levels less than 100 are considered "jena system levels" 
+ * and are reserved. 
+ * 
+ * <li>0 - here
+ * <li>10 - jena-core
+ * <li>20 - RIOT
+ * <li>30 - ARQ
+ * <li>40 - TDB
+ * <li>9999 - other
+ */
+public class JenaSystem {
+    
+    public static final boolean DEBUG_INIT = false ;
+    
+    // A correct way to manage without synchonized using the double checked locking pattern.
+    //   http://en.wikipedia.org/wiki/Double-checked_locking
+    //   http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html 
+    private static volatile boolean initialized = false ;
+    private static Object initLock = new Object() ;
+    
+    /** Initialize.
+     * This function is cheap to call when already initialized so can be called to be sure.
+     * By default, initialization happens by using {@code ServiceLoader.load} to find
+     * {@link JenaSubsystemLifecycle} objects.
+     */
+    public static void init() {
+        if ( initialized )
+            return ;
+        synchronized(initLock) {
+            if ( initialized )  {
+                if ( DEBUG_INIT )
+                    System.err.println("JenaSystem.init - return");
+                return ;
+            } 
+            // Catchs recursive calls, same thread.
+            initialized = true ;
+            if ( DEBUG_INIT )
+                System.err.println("JenaSystem.init - start");
+            
+            if ( get() == null )
+                set(new JenaSubsystemRegistryBasic()) ;
+            
+            get().load() ;
+            
+            JenaSystem.forEach( module -> {
+                if ( DEBUG_INIT )
+                    System.err.println("Init: "+module.getClass().getSimpleName());
+                module.start() ;
+            }) ;
+            if ( DEBUG_INIT )
+                System.err.println("JenaSystem.init - finish");
+        }
+    }
+
+    /** Shutdown subsystems */
+    public static void shutdown() {
+        if ( ! initialized ) 
+            return ;
+        synchronized(initLock) {
+            JenaSystem.forEachReverse(JenaSubsystemLifecycle::stop) ;
+            initialized = false ;
+        }
+    }
+    
+    private static class JenaInitLogger implements JenaSubsystemLifecycle {
+        private static Logger log = Logger.getLogger("Jena") ; 
+        @Override
+        public void start() {
+            log.info/*debug*/("Jena intialization");
+        }
+
+        @Override
+        public void stop() {
+            log.debug("Jena shutdown");
+        }
+
+        @Override
+        public int level() {
+            return 0;
+        }
+    }
+    
+    private static JenaSubsystemRegistry singleton = null;
+
+    public static void set(JenaSubsystemRegistry thing) {
+        singleton = thing;
+    }
+
+    public static JenaSubsystemRegistry get() {
+        return singleton;
+    }
+    
+    private static Comparator<JenaSubsystemLifecycle> comparator = (obj1, obj2) -> Integer.compare(obj1.level(), obj2.level()) ;
+    private static Comparator<JenaSubsystemLifecycle> reverseComparator = (obj1, obj2) -> -1 * Integer.compare(obj1.level(), obj2.level()) ;
+    
+    public static void add(JenaSubsystemLifecycle module) {
+       get().add(module) ;
+    }
+
+    public static boolean isRegistered(JenaSubsystemLifecycle module) {
+        return get().isRegistered(module);
+    }
+
+    public static void remove(JenaSubsystemLifecycle module) {
+        get().remove(module);
+    }
+
+    public static int size() {
+        return get().size();
+    }
+
+    public static boolean isEmpty() {
+        return get().isEmpty();
+    }
+
+    /** Call an action on each item in the registry.
+     * Calls are made sequentially and in level order.
+     * The exact order within a level is not specified; it is not registration order. 
+     * @param action
+     */
+    public static void forEach(Consumer<JenaSubsystemLifecycle> action) {
+        forEach(action, comparator);
+    }
+
+    /** Call an action on each item in the registry but in the reverse enumeration order.
+     * The exact order is not specified but call are made sequentially.
+     * The "reverse" is opposite order to {@link #forEach}, which may not be stable.
+     * It is not related to registration order.
+     * @param action
+     */
+    public static void forEachReverse(Consumer<JenaSubsystemLifecycle> action) {
+        forEach(action, reverseComparator);
+    }
+
+    private synchronized static void forEach(Consumer<JenaSubsystemLifecycle> action, Comparator<JenaSubsystemLifecycle> ordering) {
+        List<JenaSubsystemLifecycle> x = get().snapshot() ;
+        Collections.sort(x, ordering);
+        x.forEach(action);
+    }
+
+
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/java/org/apache/jena/util/FileManager.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/util/FileManager.java b/jena-core/src/main/java/org/apache/jena/util/FileManager.java
index 6be4906..1da9d56 100644
--- a/jena-core/src/main/java/org/apache/jena/util/FileManager.java
+++ b/jena-core/src/main/java/org/apache/jena/util/FileManager.java
@@ -23,10 +23,10 @@ import java.util.* ;
 
 import org.apache.jena.rdf.model.Model ;
 import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.rdf.model.impl.IO_Ctl ;
 import org.apache.jena.shared.JenaException ;
 import org.apache.jena.shared.NotFoundException ;
 import org.apache.jena.shared.WrappedIOException ;
+import org.apache.jena.system.JenaSystem ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
@@ -70,6 +70,8 @@ import org.slf4j.LoggerFactory ;
  
 public class FileManager
 {
+    // The case of the FileManager used first.
+    static { JenaSystem.init(); }
     /** Delimiter between path entries : because URI scheme names use : we only allow ; */
     public static final String PATH_DELIMITER = ";";
     public static final String filePathSeparator = java.io.File.separator ;
@@ -81,10 +83,6 @@ public class FileManager
     protected List<Locator> fmHandlers = new ArrayList<>() ;
     protected LocationMapper fmMapper = null ;
     
-    // This forces Jena to initialize and wire in RIOT if available.
-    // The global FileManager is reset. 
-    static { IO_Ctl.init() ; }
-    
     /** Get the global file manager.
      * @return the global file manager
      */

http://git-wip-us.apache.org/repos/asf/jena/blob/55a8eab3/jena-core/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-core/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-core/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
new file mode 100644
index 0000000..2755f65
--- /dev/null
+++ b/jena-core/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -0,0 +1,2 @@
+org.apache.jena.system.InitJenaCore
+


[8/8] jena git commit: JENA-1029: Comment and clean JenaSystem.

Posted by an...@apache.org.
JENA-1029: Comment and clean JenaSystem.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/68a76909
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/68a76909
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/68a76909

Branch: refs/heads/Jena-1029_subsystem
Commit: 68a769098846bee02a843ddf3fb77edbc491c1dd
Parents: 3e96cae
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Sep 18 08:59:56 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Sep 18 08:59:56 2015 +0100

----------------------------------------------------------------------
 .../apache/jena/system/JenaSubsystemRegistryBasic.java   | 11 +++++------
 .../src/main/java/org/apache/jena/system/JenaSystem.java | 10 +++++++++-
 2 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/68a76909/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
index 3e12fca..7a23b4f 100644
--- a/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSubsystemRegistryBasic.java
@@ -23,7 +23,10 @@ import java.util.List ;
 import java.util.ServiceLoader ;
 
 /** Implementation of {@link JenaSubsystemRegistry} for use in the simple 
- * but common case of runing a a collection (classpath) of jars. 
+ *  but common case of running Jena as a collection of jars
+ *  on the classpath. 
+ *  <p>
+ *  Uses {@link ServiceLoader} to find sub-systems. 
  */
 public class JenaSubsystemRegistryBasic implements JenaSubsystemRegistry {
     
@@ -38,11 +41,7 @@ public class JenaSubsystemRegistryBasic implements JenaSubsystemRegistry {
         synchronized (registryLock) {
             // Find subsystems asking for initialization. 
             ServiceLoader<JenaSubsystemLifecycle> sl = ServiceLoader.load(JenaSubsystemLifecycle.class) ;
-            sl.forEach(life-> {
-                if ( JenaSystem.DEBUG_INIT )
-                    System.err.println("  "+life.getClass().getSimpleName()) ;
-                add(life);
-            }) ;
+            sl.forEach(this::add) ;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/68a76909/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
index 8360f3b..5e8e9a8 100644
--- a/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
+++ b/jena-core/src/main/java/org/apache/jena/system/JenaSystem.java
@@ -57,6 +57,8 @@ public class JenaSystem {
     /** Initialize Jena.
      * <p>
      * This function is cheap to call when already initialized so can be called to be sure.
+     * A commonly used idom in jena is in static initailizers in key classes.
+     * <p> 
      * By default, initialization happens by using {@code ServiceLoader.load} to find
      * {@link JenaSubsystemLifecycle} objects.
      * See {@link #set} to intercept that choice.
@@ -79,8 +81,14 @@ public class JenaSystem {
                 set(new JenaSubsystemRegistryBasic()) ;
             
             get().load() ;
-            get().add(new JenaInitLevel0());
             
+            // Debug : what did we find?
+            if ( JenaSystem.DEBUG_INIT ) {
+                get().snapshot().forEach(mod->
+                    System.err.println("  "+mod.getClass().getSimpleName())) ;
+            }
+            get().add(new JenaInitLevel0()) ;
+
             JenaSystem.forEach( module -> {
                 if ( DEBUG_INIT )
                     System.err.println("Init: "+module.getClass().getSimpleName());


[3/8] jena git commit: Fix repeated typo.

Posted by an...@apache.org.
Fix repeated typo.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/0da50bfa
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/0da50bfa
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/0da50bfa

Branch: refs/heads/Jena-1029_subsystem
Commit: 0da50bfa6d08df240c7ed2f6ee11f931b8ba008a
Parents: df1f1f4
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Sep 18 00:18:47 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Sep 18 00:18:47 2015 +0100

----------------------------------------------------------------------
 .../model/impl/SecuredResourceImpl.java         | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/0da50bfa/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java
index e28815b..79f38c6 100644
--- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java
@@ -129,7 +129,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * one constructed by using
 	 * <code>this.getModel().createTypedLiteral(o)</code>.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -147,7 +147,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * one constructed by using
 	 * <code>this.getModel().createTypedLiteral(o)</code>.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -165,7 +165,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * one constructed by using
 	 * <code>this.getModel().createTypedLiteral(o)</code>.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -183,7 +183,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * one constructed by using
 	 * <code>this.getModel().createTypedLiteral(o)</code>.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -201,7 +201,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * from the other addLiteral methods in that the Literal is not turned into
 	 * a Literal.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -219,7 +219,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * one constructed by using
 	 * <code>this.getModel().createTypedLiteral(o)</code>.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -237,7 +237,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * one constructed by using
 	 * <code>this.getModel().createTypedLiteral(o)</code>.
 	 * 
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -261,7 +261,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * @param o
 	 *            The value of the property to be added.
 	 * @return This resource to allow cascading calls.
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -289,7 +289,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * @param o
 	 *            The value of the property to be added.
 	 * @return This resource to allow cascading calls.
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -315,7 +315,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * @param datatype
 	 *            The datatype
 	 * @return This resource to allow cascading calls.
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */
@@ -348,7 +348,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements
 	 * @param l
 	 *            the language of the property
 	 * @return This resource to allow cascading calls.
-	 * @throws UpdadeDeniedException
+	 * @throws UpdateDeniedException
 	 * @throws AddDeniedException
 	 * @throws AuthenticationRequiredException
 	 */