jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/2] jena git commit: Add comments and tidy code for Fuseki server initalization.
Date Fri, 05 Aug 2016 18:20:10 GMT
Add comments and tidy code for Fuseki server initalization.

Restrict access and/or renaem init() methods that are nowdays controleld
by the webapp booting up.

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

Branch: refs/heads/master
Commit: 660a545e91753dc931f5e814b3bd488aedc15029
Parents: 6e29cbe
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Aug 5 19:19:56 2016 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Aug 5 19:19:56 2016 +0100

----------------------------------------------------------------------
 .../fuseki/server/DataAccessPointRegistry.java    | 11 ++++++-----
 .../org/apache/jena/fuseki/server/FusekiEnv.java  |  2 +-
 .../apache/jena/fuseki/server/FusekiServer.java   | 17 ++++++-----------
 .../server/FusekiServerEnvironmentInit.java       |  3 ++-
 .../jena/fuseki/server/FusekiServerListener.java  | 18 +++++++++++++++---
 .../fuseki/server/ShiroEnvironmentLoader.java     |  4 ++--
 .../org/apache/jena/fuseki/build/TestBuilder.java |  8 ++++----
 7 files changed, 36 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
index 78dc1ba..9c602c3 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DataAccessPointRegistry.java
@@ -23,19 +23,20 @@ import org.apache.jena.fuseki.FusekiException ;
 
 public class DataAccessPointRegistry extends Registry<String, DataAccessPoint>
 {
-    public static void register(String name, DataAccessPoint accessPt) {
-        if ( get().isRegistered(name) )
+    // Add error checking.
+    public void register(String name, DataAccessPoint accessPt) {
+        if ( isRegistered(name) )
             throw new FusekiException("Already registered: "+name) ;
-        get().put(name, accessPt);
+        super.put(name, accessPt);
     }
     
     // Debugging
-    public static void print(String string) {
+    public void print(String string) {
         System.out.flush() ;
         if ( string == null )
             string = "DataAccessPointRegistry" ;
         System.out.println("== "+string) ;
-        DataAccessPointRegistry.get().forEach((k,ref)->{
+        this.forEach((k,ref)->{
             System.out.printf("  (key=%s, ref=%s)\n", k, ref.getName()) ;
             ref.getDataService().getOperations().forEach((opName)->{
                 ref.getDataService().getOperation(opName).forEach(ep->{

http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
index cb91ede..6ff51f0 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
@@ -106,7 +106,7 @@ public class FusekiEnv {
     public static final String   ENV_runArea     = "run" ;
     private static boolean       initialized     = false ;
     
-    /** Initialize the server */
+    /** Initialize the server : standalone and WAR versions : not embedded */
     public static synchronized void setEnvironment() {
         if ( initialized )
             return ;

http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
index 2ddd53c..e8e5467 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
@@ -98,15 +98,10 @@ public class FusekiServer
     public static Path        dirTemplates       = null ;
 
     private static boolean    initialized        = false ;
-    public static boolean     serverInitialized  = false ;
+    // Marks the end of successful initialization.
+    /*package*/static boolean serverInitialized  = false ;
 
-    /** For testing - reset the places which initialize once */
-    public synchronized static void reset() {
-        initialized = false ;
-        FusekiServer.initialized = false ;
-    }
-    
-    public synchronized static void init() {
+    /*package*/ synchronized static void formatBaseArea() {
         if ( initialized )
             return ;
         initialized = true ;
@@ -225,7 +220,7 @@ public class FusekiServer
     private static void enable(List<DataAccessPoint> datapoints) {
         for ( DataAccessPoint dap : datapoints ) {
             Fuseki.configLog.info("Register: "+dap.getName()) ;
-            DataAccessPointRegistry.register(dap.getName(), dap); 
+            DataAccessPointRegistry.get().register(dap.getName(), dap); 
         }
     }
 
@@ -321,7 +316,7 @@ public class FusekiServer
             //  1 - clean model, remove "fu:serviceUpdate", "fu:serviceUpload", "fu:serviceReadGraphStore",
"fu:serviceReadWriteGraphStore"
             //  2 - set a flag on DataAccessPoint
         }
-        DataAccessPoint dap = Builder.buildDataAccessPoint(subject, registry) ;
+        DataAccessPoint dap = FusekiBuilder.buildDataAccessPoint(subject, registry) ;
         return dap ;
     }
     
@@ -356,7 +351,7 @@ public class FusekiServer
     
     private static DataAccessPoint datasetDefaultConfiguration( String name, DatasetGraph
dsg, boolean allowUpdate) {
         name = DataAccessPoint.canonical(name) ;
-        DataService ds = Builder.buildDataService(dsg, allowUpdate) ;
+        DataService ds = FusekiBuilder.buildDataService(dsg, allowUpdate) ;
         DataAccessPoint dap = new DataAccessPoint(name, ds) ;
         return dap ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/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 51339b8..c19d241 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
@@ -25,7 +25,8 @@ import org.apache.jena.fuseki.FusekiLogging ;
 import org.apache.jena.system.JenaSystem ;
 
 /** Setup the enviroment and logging.
- *  Runs before the ShiroEnvironmentLoader.
+ *  Runs before the {@link ShiroEnvironmentLoader}.
+ *  The main configuration happens in {@link FusekiServerListener} which runs after {@link
ShiroEnvironmentLoader}.
  */
 public class FusekiServerEnvironmentInit implements ServletContextListener {
 

http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerListener.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerListener.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerListener.java
index ba79eb3..93738a2 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerListener.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServerListener.java
@@ -25,6 +25,15 @@ import javax.servlet.ServletContextListener ;
 import org.apache.jena.fuseki.Fuseki ;
 import org.apache.jena.tdb.StoreConnection ;
 
+/** Setup configurtation.
+ * The order is controled by {@code web.xml}:
+ * <ul>
+ * <li>{@link FusekiServerEnvironmentInit}
+ * <li>{@link ShiroEnvironmentLoader}
+ * <li>{@link FusekiServerListener}, the main configuration
+ * </ul>
+ */
+
 public class FusekiServerListener implements ServletContextListener {
 
     public FusekiServerListener() { }
@@ -43,7 +52,10 @@ public class FusekiServerListener implements ServletContextListener {
 //        Path currentRelativePath = Paths.get("");
 //        String s = currentRelativePath.toAbsolutePath().toString();
 //        confLog.info("dir1 = "+x+" : dir2 = "+s) ;
-        init() ;
+        
+        // Set the server wide state.
+        //servletContext.setAttribute(, DataAccessPointRegistry.get()) ;
+        serverInitialization() ;
     }
 
     @Override
@@ -55,13 +67,13 @@ public class FusekiServerListener implements ServletContextListener {
         StoreConnection.reset();
     }
 
-    public synchronized void init() {
+    private synchronized void serverInitialization() {
         if ( initialized )
             return ;
         initialized = true ;
 
         try {
-            FusekiServer.init() ; 
+            FusekiServer.formatBaseArea() ; 
             if ( ! FusekiServer.serverInitialized ) {
                 Fuseki.serverLog.error("Failed to initialize : Server not running") ;
                 return ;

http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
index 6942645..f963e8e 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/ShiroEnvironmentLoader.java
@@ -36,7 +36,7 @@ import org.apache.shiro.web.env.ResourceBasedWebEnvironment ;
 import org.apache.shiro.web.env.WebEnvironment ;
 
 /** A place to perform Fuseki-specific initialization of Apache Shiro.
- *  Runs after listener FusekiServerEnvironmentInit and before FusekiServerListener
+ *  Runs after listener {@link FusekiServerEnvironmentInit} and before {@link FusekiServerListener}.
  *  This means finding shiro.ini in multiple possible places, based on
  *  different deployment setups.
  */
@@ -47,7 +47,7 @@ public class ShiroEnvironmentLoader extends EnvironmentLoader implements
Servlet
     
     @Override
     public void contextInitialized(ServletContextEvent sce) {
-        FusekiServer.init() ; 
+        FusekiServer.formatBaseArea() ; 
         this.servletContext = sce.getServletContext() ;
         try { 
             // Shiro.

http://git-wip-us.apache.org/repos/asf/jena/blob/660a545e/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/build/TestBuilder.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/build/TestBuilder.java
b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/build/TestBuilder.java
index ff89e2d..bf4f4d8 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/build/TestBuilder.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/build/TestBuilder.java
@@ -39,16 +39,16 @@ public class TestBuilder {
 	@Test
 	public void testVerifySameDatasetObjectForSameDescription() {
 		
-		Dataset ds1 = Builder.getDataset(dsDesc1, registry);
-		Dataset ds2 = Builder.getDataset(dsDesc1, registry);
+		Dataset ds1 = FusekiBuilder.getDataset(dsDesc1, registry);
+		Dataset ds2 = FusekiBuilder.getDataset(dsDesc1, registry);
 		assertEquals(ds1, ds2);
 	}
 	
 	@Test
 	public void testVerifyDifferentDatasetObjectsForDifferentDescriptions() {
 		
-		Dataset ds1 = Builder.getDataset(dsDesc1, registry);
-		Dataset ds2 = Builder.getDataset(dsDesc2, registry);
+		Dataset ds1 = FusekiBuilder.getDataset(dsDesc1, registry);
+		Dataset ds2 = FusekiBuilder.getDataset(dsDesc2, registry);
 		assertNotEquals(ds1, ds2);		
 	}
 	


Mime
View raw message