Skip to content

Commit

Permalink
Fuseki init. Split code out of constants class. Name fuseki/main init…
Browse files Browse the repository at this point in the history
… as InitFusekiMain
  • Loading branch information
afs committed Dec 14, 2024
1 parent 9111c88 commit 6994d89
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@

import org.apache.jena.atlas.lib.DateTimeUtils;
import org.apache.jena.atlas.lib.Version;
import org.apache.jena.fuseki.system.FusekiCore;
import org.apache.jena.query.ARQ;
import org.apache.jena.riot.system.stream.LocatorFTP;
import org.apache.jena.riot.system.stream.LocatorHTTP;
import org.apache.jena.riot.system.stream.StreamManager;
import org.apache.jena.sparql.util.Context;
import org.apache.jena.sparql.util.MappingRegistry;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.tdb1.TDB1;
import org.apache.jena.tdb1.transaction.TransactionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -103,6 +100,12 @@ public class Fuseki {
public static boolean outputJettyServerHeader = developmentMode;
public static boolean outputFusekiServerHeader = developmentMode;

/**
* Initialize is class.
* See also {@link FusekiCore} for Fuseki core initialization.
*/
public static void initConsts() {}

/** An identifier for the HTTP Fuseki server instance */
static public final String serverHttpName = NAME + " (" + VERSION + ")";

Expand Down Expand Up @@ -226,28 +229,6 @@ public static String serverStartedAt() {
return startDateTime;
}

private static boolean initialized = false;
/**
* Initialize an instance of the Fuseki server stack.
* This is not done via Jena's initialization mechanism
* but done explicitly to give more control.
* It is done after Jena initializes.
* Fuseki-main adds a Fuseki specific custom initialization
* round after this is run.
*/
public synchronized static void init() {
if ( initialized )
return;
initialized = true;
JenaSystem.init();
MappingRegistry.addPrefixMapping("fuseki", FusekiSymbolIRI);

TDB1.setOptimizerWarningFlag(false);
// Don't use TDB1 batch commits.
// This can be slower, but it less memory hungry and more predictable.
TransactionManager.QueueBatchSize = 0;
}

/**
* Get server global {@link org.apache.jena.sparql.util.Context}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.system;

import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.sparql.util.MappingRegistry;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.tdb1.TDB1;
import org.apache.jena.tdb1.transaction.TransactionManager;

/**
* Fuseki core initialization.
* <p>
* Initialize an instance of the Fuseki server core code.
* This is not done via Jena's initialization mechanism
* but done explicitly to give control.
* <p>
* It is done after Jena initializes.
* <p>
* {@code InitFusekiMain} is the code for Jena's initialization mechanism.
* It calls this class.
*/
public class FusekiCore {

private static boolean initialized = false;

public synchronized static void init() {
if ( initialized )
return;

// Avoid re-entrancy.
initialized = true;

JenaSystem.init();
// Touch the Fuseki class to make sure statics get initialized.
Fuseki.initConsts();
MappingRegistry.addPrefixMapping("fuseki", Fuseki.FusekiSymbolIRI);

// TDB1
TDB1.setOptimizerWarningFlag(false);
// Don't use TDB1 batch commits.
// This can be slower, but it less memory hungry and more predictable.
TransactionManager.QueueBatchSize = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.function.Function;
import java.util.function.Predicate;


import jakarta.servlet.Filter;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServlet;
Expand Down Expand Up @@ -59,11 +58,12 @@
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.query.Dataset;
import org.apache.jena.rdf.model.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
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.sys.JenaSystem;
import org.apache.jena.system.G;
import org.apache.jena.system.RDFDataException;
import org.apache.jena.web.HttpSC;
Expand Down Expand Up @@ -113,8 +113,7 @@

public class FusekiServer {
static {
JenaSystem.init();
Fuseki.init();
InitFusekiMain.init();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.jena.fuseki.main.sys.FusekiAutoModules;
import org.apache.jena.fuseki.main.sys.FusekiModules;
import org.apache.jena.fuseki.main.sys.FusekiServerArgsCustomiser;
import org.apache.jena.fuseki.main.sys.InitFusekiMain;
import org.apache.jena.fuseki.server.DataAccessPoint;
import org.apache.jena.fuseki.server.DataAccessPointRegistry;
import org.apache.jena.fuseki.server.FusekiCoreInfo;
Expand Down Expand Up @@ -157,7 +158,7 @@ public static FusekiServer build(String... args) {
*/
public static void run(String... argv) {
JenaSystem.init();
Fuseki.init();
InitFusekiMain.init();
new FusekiMain(argv).mainRun();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ public void execute(HttpAction action) {
FusekiLib.reload(server, model);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* A {@link SubsystemLifecycle} for Fuseki.
* This lifecycle is run after Jena system initialization.
* Jena system initialization includes system initialization of Fuseki itself
* in {@link InitFuseki}.
* in {@link InitFusekiMain}.
* This lifecycle is for extensions to an initialized Fuseki server
* and is used via {@link FusekiAutoModule}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.jena.cmd.Cmds;
import org.apache.jena.fuseki.main.cmds.FusekiMainCmd;
import org.apache.jena.fuseki.system.FusekiCore;
import org.apache.jena.sys.JenaSubsystemLifecycle;
import org.apache.jena.sys.JenaSystem;

Expand All @@ -28,7 +29,7 @@
* Level 101 - called during Jena system initialization
* and after Jena itself has initialized.
*/
public class InitFuseki implements JenaSubsystemLifecycle {
public class InitFusekiMain implements JenaSubsystemLifecycle {

private static volatile boolean initialized = false;

Expand All @@ -45,15 +46,21 @@ public static void init() {
if ( initialized ) {
return;
}
synchronized (InitFuseki.class) {

synchronized (InitFusekiMain.class) {
if ( initialized ) {
JenaSystem.logLifecycle("Fuseki.init - skip");
return;
}
initialized = true;
JenaSystem.logLifecycle("Fuseki.init - start");

// Ensure core constants are initialized first.
FusekiCore.init();
FusekiModules.init();

// Leave until known to be needed FusekiServer build with no specific FusekikModules given.
// FusekiModulesCtl.setup();
try {
Cmds.injectCmd("fuseki", a->FusekiMainCmd.main(a));
} catch (NoClassDefFoundError ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.apache.jena.fuseki.main.sys.InitFuseki
org.apache.jena.fuseki.main.sys.InitFusekiMain
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.main.FusekiLib;
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.fuseki.main.sys.InitFusekiMain;
import org.apache.jena.graph.Node;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.QuerySolution;
Expand All @@ -46,7 +47,6 @@
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.sse.SSE;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.system.Txn;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -63,7 +63,7 @@
*/

public abstract class AbstractTestFusekiSecurityAssembler {
static { JenaSystem.init(); }
static { InitFusekiMain.init(); }
static final String DIR = "testing/Access/";

private final String assemblerFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import org.apache.jena.fuseki.build.FusekiExt;
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.fuseki.main.sys.FusekiModule;
import org.apache.jena.fuseki.main.sys.InitFusekiMain;
import org.apache.jena.fuseki.server.Operation;
import org.apache.jena.fuseki.servlets.ActionService;
import org.apache.jena.fuseki.servlets.HttpAction;
import org.apache.jena.fuseki.system.FusekiLogging;
import org.apache.jena.http.HttpOp;
import org.apache.jena.riot.WebContent;
import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.web.HttpSC;

/**
Expand All @@ -46,8 +46,8 @@
public class ExFuseki_04_CustomOperation_Inline {

static {
JenaSystem.init();
FusekiLogging.setLogging();
InitFusekiMain.init();
}

public static void main(String...args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.fuseki.main.sys.FusekiModule;
import org.apache.jena.fuseki.main.sys.FusekiModules;
import org.apache.jena.fuseki.main.sys.InitFusekiMain;
import org.apache.jena.fuseki.server.Operation;
import org.apache.jena.fuseki.servlets.ActionService;
import org.apache.jena.fuseki.servlets.HttpAction;
Expand All @@ -35,7 +36,6 @@
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.WebContent;
import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sys.JenaSystem;
import org.apache.jena.web.HttpSC;

/**
Expand All @@ -48,8 +48,8 @@
public class ExFuseki_04_CustomOperation_Module {

static {
JenaSystem.init();
FusekiLogging.setLogging();
InitFusekiMain.init();
}

// Example usage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.FusekiException;
import org.apache.jena.fuseki.mgt.Template;
import org.apache.jena.fuseki.system.FusekiCore;
import org.apache.jena.fuseki.system.FusekiLogging;
import org.apache.jena.fuseki.webapp.FusekiEnv;
import org.apache.jena.fuseki.webapp.FusekiServerListener;
Expand Down Expand Up @@ -96,7 +97,7 @@ static class FusekiCmdInner extends CmdARQ {
static public void innerMain(String... argv) {
JenaSystem.init();
// Do explicitly so it happens after subsystem initialization.
Fuseki.init();
FusekiCore.init();
new FusekiCmdInner(argv).mainRun();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import org.apache.jena.fuseki.FusekiException;
import org.apache.jena.fuseki.server.DataAccessPointRegistry;
import org.apache.jena.fuseki.server.FusekiCoreInfo;
import org.apache.jena.fuseki.system.FusekiCore;
import org.apache.jena.fuseki.webapp.FusekiEnv;
import org.apache.jena.sys.JenaSystem;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.security.ConstraintMapping;
import org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler;
Expand Down Expand Up @@ -59,7 +61,10 @@ public class JettyFusekiWebapp {
// This class is becoming less important - it now sets up a Jetty server for in-process use
// either for the command line in development
// and in testing but not direct webapp deployments.
static { Fuseki.init(); }
static {
JenaSystem.init();
FusekiCore.init();
}

public static JettyFusekiWebapp instance = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.servlet.ServletContextListener;

import org.apache.jena.fuseki.system.FusekiLogging;
import org.apache.jena.fuseki.system.FusekiCore;
import org.apache.jena.sys.JenaSystem;

/** Setup the environment and logging.
Expand Down Expand Up @@ -49,6 +50,8 @@ public void contextInitialized(ServletContextEvent sce) {
}
}
JenaSystem.init();
FusekiCore.init();

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.jena.fuseki.server.DataService;
import org.apache.jena.fuseki.servlets.HttpAction;
import org.apache.jena.fuseki.servlets.ServletOps;
import org.apache.jena.fuseki.system.FusekiCore;
import org.apache.jena.graph.Graph;
import org.apache.jena.rdf.model.*;
import org.apache.jena.rdfs.RDFSFactory;
Expand All @@ -55,6 +56,7 @@
import org.apache.jena.riot.RDFParser;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.assembler.AssemblerUtils;
import org.apache.jena.sys.JenaSystem;

public class FusekiWebapp
{
Expand Down Expand Up @@ -122,7 +124,8 @@ public class FusekiWebapp
Path FUSEKI_HOME = FusekiEnv.FUSEKI_HOME;
Path FUSEKI_BASE = FusekiEnv.FUSEKI_BASE;

Fuseki.init();
JenaSystem.init();
FusekiCore.init();
Fuseki.configLog.info("FUSEKI_HOME="+ ((FUSEKI_HOME==null) ? "unset" : FUSEKI_HOME.toString()));
Fuseki.configLog.info("FUSEKI_BASE="+FUSEKI_BASE.toString());

Expand Down
Loading

0 comments on commit 6994d89

Please sign in to comment.