blob: 2947279c2d57be4a1876713df6ce80a19527fd1a [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<title>Apache Jena - Fuseki Modules</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/css/bootstrap-extension.css" rel="stylesheet" type="text/css">
<link href="/css/jena.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="/images/favicon.ico" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script src="/js/jena-navigation.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/js/improve.js" type="text/javascript"></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/index.html">
<img class="logo-menu" src="/images/jena-logo/jena-logo-notext-small.png" alt="jena logo">Apache Jena</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li id="homepage"><a href="/index.html"><span class="glyphicon glyphicon-home"></span> Home</a></li>
<li id="download"><a href="/download/index.cgi"><span class="glyphicon glyphicon-download-alt"></span> Download</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-book"></span> Learn <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Tutorials</li>
<li><a href="/tutorials/index.html">Overview</a></li>
<li><a href="/documentation/fuseki2/index.html">Fuseki Triplestore</a></li>
<li><a href="/documentation/notes/index.html">How-To's</a></li>
<li><a href="/documentation/query/manipulating_sparql_using_arq.html">Manipulating SPARQL using ARQ</a></li>
<li><a href="/tutorials/rdf_api.html">RDF core API tutorial</a></li>
<li><a href="/tutorials/sparql.html">SPARQL tutorial</a></li>
<li><a href="/tutorials/using_jena_with_eclipse.html">Using Jena with Eclipse</a></li>
<li class="divider"></li>
<li class="dropdown-header">References</li>
<li><a href="/documentation/index.html">Overview</a></li>
<li><a href="/documentation/query/index.html">ARQ (SPARQL)</a></li>
<li><a href="/documentation/assembler/index.html">Assembler</a></li>
<li><a href="/documentation/tools/index.html">Command-line tools</a></li>
<li><a href="/documentation/rdfs/">Data with RDFS Inferencing</a></li>
<li><a href="/documentation/geosparql/index.html">GeoSPARQL</a></li>
<li><a href="/documentation/inference/index.html">Inference API</a></li>
<li><a href="/documentation/javadoc.html">Javadoc</a></li>
<li><a href="/documentation/ontology/">Ontology API</a></li>
<li><a href="/documentation/permissions/index.html">Permissions</a></li>
<li><a href="/documentation/extras/querybuilder/index.html">Query Builder</a></li>
<li><a href="/documentation/rdf/index.html">RDF API</a></li>
<li><a href="/documentation/rdfconnection/">RDF Connection - SPARQL API</a></li>
<li><a href="/documentation/io/">RDF I/O</a></li>
<li><a href="/documentation/rdfstar/index.html">RDF-star</a></li>
<li><a href="/documentation/shacl/index.html">SHACL</a></li>
<li><a href="/documentation/shex/index.html">ShEx</a></li>
<li><a href="/documentation/jdbc/index.html">SPARQL over JDBC</a></li>
<li><a href="/documentation/tdb/index.html">TDB</a></li>
<li><a href="/documentation/tdb2/index.html">TDB2</a></li>
<li><a href="/documentation/query/text-query.html">Text Search</a></li>
</ul>
</li>
<li class="drop down">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-book"></span> Javadoc <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/documentation/javadoc.html">All Javadoc</a></li>
<li><a href="/documentation/javadoc/arq/">ARQ</a></li>
<li><a href="/documentation/javadoc_elephas.html">Elephas</a></li>
<li><a href="/documentation/javadoc/fuseki2/">Fuseki</a></li>
<li><a href="/documentation/javadoc/geosparql/">GeoSPARQL</a></li>
<li><a href="/documentation/javadoc/jdbc/">JDBC</a></li>
<li><a href="/documentation/javadoc/jena/">Jena Core</a></li>
<li><a href="/documentation/javadoc/permissions/">Permissions</a></li>
<li><a href="/documentation/javadoc/extras/querybuilder/">Query Builder</a></li>
<li><a href="/documentation/javadoc/shacl/">SHACL</a></li>
<li><a href="/documentation/javadoc/tdb/">TDB</a></li>
<li><a href="/documentation/javadoc/text/">Text Search</a></li>
</ul>
</li>
<li id="ask"><a href="/help_and_support/index.html"><span class="glyphicon glyphicon-question-sign"></span> Ask</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-bullhorn"></span> Get involved <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/getting_involved/index.html">Contribute</a></li>
<li><a href="/help_and_support/bugs_and_suggestions.html">Report a bug</a></li>
<li class="divider"></li>
<li class="dropdown-header">Project</li>
<li><a href="/about_jena/about.html">About Jena</a></li>
<li><a href="/about_jena/architecture.html">Architecture</a></li>
<li><a href="/about_jena/citing.html">Citing</a></li>
<li><a href="/about_jena/team.html">Project team</a></li>
<li><a href="/about_jena/contributions.html">Related projects</a></li>
<li><a href="/about_jena/roadmap.html">Roadmap</a></li>
<li class="divider"></li>
<li class="dropdown-header">ASF</li>
<li><a href="http://www.apache.org/">Apache Software Foundation</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a></li>
<li><a href="http://www.apache.org/licenses/LICENSE-2.0">License</a></li>
<li><a href="http://www.apache.org/security/">Security</a></li>
<li><a href="http://www.apache.org/foundation/thanks.html">Thanks</a></li>
</ul>
</li>
<li id="edit"><a href="https://github.com/apache/jena-site/edit/main/source/documentation/fuseki2/fuseki-modules.md" title="Edit this page on GitHub"><span class="glyphicon glyphicon-pencil"></span> Edit this page</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="breadcrumbs">
<ol class="breadcrumb">
<li><a href='/documentation'>DOCUMENTATION</a></li>
<li><a href='/documentation/fuseki2'>FUSEKI2</a></li>
<li class="active">FUSEKI MODULES</li>
</ol>
</div>
<h1 class="title">Fuseki Modules</h1>
<p><em>Fuseki modules</em> are a mechanism to include extension code into a Fuseki
server. Modules are invoked during the process of building a <a href="./fuseki-main.html">Fuseki
Main</a> server. The module can modify the server
configuration, add new functionality, or react to a server being built and
started.</p>
<p>This feature was added in Jena version 4.3.0. They are an expeirmental feature
that will evolve based on experineace and use cases.</p>
<p>Fuseki Modules are loaded use the JDK
<a href="https://www.baeldung.com/java-spi">ServiceLoader</a> by being placing a jar file on the classpath,
together with any additional dependencies. The service loader looks for files
<code>META-INF/services/org.apache.jena.fuseki.main.sys.FusekiModule</code> in the jar
file.
This is often done by placing the file in the development code in
<code>src/main/resources/META-INF/services/</code>).
The file containing a line with the implementation full class name. If
<a href="../notes/jena-repack.html">repacking</a> Fuseki with the maven-shade-plugin, make
sure the <code>ServicesResourceTransformer</code> is used. The module must have a no
argument constructor.</p>
<p>If using Fuseki as an <a href="./fuseki-embedded.html">embedded server</a>, the module is
added in code as:</p>
<pre><code> FusekiModule module = new MyModule();
FusekiModules.add(module);
</code></pre><p>The method <code>start</code> is called when the module is loaded. Custom operations can
be globally registered at this point (see the <a href="https://github.com/apache/jena/tree/main/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples">Fuseki
examples</a> directory).</p>
<p>The module lifecycle during creating a Fuseki server is:</p>
<ul>
<li><code>configuration</code> - access and modify the setup.
This is called after the server has been configured, just before the server is built.</li>
<li><code>server</code> - access the built server</li>
<li><code>serverBeforeStarting</code> - about to call &ldquo;server.start()&rdquo;</li>
<li><code>serverAfterStarting</code> - just after calling &ldquo;server.start()&rdquo;</li>
<li><code>serverStopped</code> - called as the server stop
(note, this is not always called because a server can simply exit the JVM).</li>
</ul>
<p>A Fuseki module does not need to implement all these steps, the default for all
of them is &ldquo;do nothing&rdquo;. Usually, an extension will only be interested in
certain stpes, like the configuration and registry information of
<code>configuration</code>.</p>
<p>During the configuration step, the Fuskei configuration file for the server is
available. If the server is built programmatically without a configuration file,
this is null.</p>
<p>The configuration file can contain RDF information to build resources (e.g.
contains assembler descriptions not directly linked to the server).</p>
<p>There is an <a href="https://github.com/apache/jena/blob/main/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/ExFusekiMain_3_FusekiModule.java">example Fuseki
Module</a>
in the Fuseki examples directory.</p>
<p><code>FusekiModule</code> interface:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * Module interface for Fuseki.
</span><span style="color:#080;font-style:italic"> * &lt;p&gt;
</span><span style="color:#080;font-style:italic"> * A module is additional code, usually in a separate jar,
</span><span style="color:#080;font-style:italic"> * but can also be part of the application code.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">interface</span> <span style="color:#00f">FusekiModule</span> <span style="color:#a2f;font-weight:bold">extends</span> SubsystemLifecycle <span style="color:#666">{</span>
<span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * Unique (within this server) name to identify this module.
</span><span style="color:#080;font-style:italic"> * The default is to generate an UUID.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> String <span style="color:#00a000">name</span><span style="color:#666">();</span>
<span style="color:#080;font-style:italic">/** Module loaded */</span>
<span style="color:#a2f">@Override</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">start</span><span style="color:#666">()</span> <span style="color:#666">{}</span>
<span style="color:#080;font-style:italic">// ---- Build cycle
</span><span style="color:#080;font-style:italic"></span>
<span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * Called at the start of &#34;build&#34; step. The builder has been set according to the
</span><span style="color:#080;font-style:italic"> * configuration. The &#34;configModel&#34; parameter is set if a configuration file was
</span><span style="color:#080;font-style:italic"> * used otherwise it is null.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">configuration</span><span style="color:#666">(</span>FusekiServer<span style="color:#666">.</span><span style="color:#b44">Builder</span> builder<span style="color:#666">,</span> DataAccessPointRegistry dapRegistry<span style="color:#666">,</span> Model configModel<span style="color:#666">)</span> <span style="color:#666">{</span>
dapRegistry<span style="color:#666">.</span><span style="color:#b44">accessPoints</span><span style="color:#666">().</span><span style="color:#b44">forEach</span><span style="color:#666">(</span>accessPoint<span style="color:#666">-&gt;</span>configDataAccessPoint<span style="color:#666">(</span>builder<span style="color:#666">,</span> accessPoint<span style="color:#666">,</span> configModel<span style="color:#666">));</span>
<span style="color:#666">}</span>
<span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * This method is called for each {@link DataAccessPoint}
</span><span style="color:#080;font-style:italic"> * by the default implementation of {@link #configuration}.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">configDataAccessPoint</span><span style="color:#666">(</span>FusekiServer<span style="color:#666">.</span><span style="color:#b44">Builder</span> builder<span style="color:#666">,</span> DataAccessPoint dap<span style="color:#666">,</span> Model configModel<span style="color:#666">)</span> <span style="color:#666">{}</span>
<span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * Built, not started, about to be returned to the builder caller.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">server</span><span style="color:#666">(</span>FusekiServer server<span style="color:#666">)</span> <span style="color:#666">{</span> <span style="color:#666">}</span>
<span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * Server starting - called just before server.start happens.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">serverBeforeStarting</span><span style="color:#666">(</span>FusekiServer server<span style="color:#666">)</span> <span style="color:#666">{</span> <span style="color:#666">}</span>
<span style="color:#080;font-style:italic">/**
</span><span style="color:#080;font-style:italic"> * Server started - called just after server.start happens, and before server
</span><span style="color:#080;font-style:italic"> * .start() returns to the application.
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">serverAfterStarting</span><span style="color:#666">(</span>FusekiServer server<span style="color:#666">)</span> <span style="color:#666">{</span> <span style="color:#666">}</span>
<span style="color:#080;font-style:italic">/** Server stopping.
</span><span style="color:#080;font-style:italic"> * Do not rely on this to clear up external resources.
</span><span style="color:#080;font-style:italic"> * Usually there is no stop phase and the JVM just exits or is killed externally.
</span><span style="color:#080;font-style:italic"> *
</span><span style="color:#080;font-style:italic"> */</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">serverStopped</span><span style="color:#666">(</span>FusekiServer server<span style="color:#666">)</span> <span style="color:#666">{</span> <span style="color:#666">}</span>
<span style="color:#080;font-style:italic">/** Module unloaded */</span>
<span style="color:#a2f">@Override</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">default</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">stop</span><span style="color:#666">()</span> <span style="color:#666">{}</span>
<span style="color:#666">}</span>
</code></pre></div>
</div>
</div>
</div>
<footer class="footer">
<div class="container" style="font-size:80%" >
<p>
Copyright &copy; 2011&ndash;2022 The Apache Software Foundation, Licensed under the
<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
</p>
<p>
Apache Jena, Jena, the Apache Jena project logo, Apache and the Apache feather logos are trademarks of
The Apache Software Foundation.
<br/>
<a href="https://privacy.apache.org/policies/privacy-policy-public.html"
>Apache Software Foundation Privacy Policy</a>.
</p>
</div>
</footer>
<script type="text/javascript">
var link = $('a[href="' + this.location.pathname + '"]');
if (link != undefined)
link.parents('li,ul').addClass('active');
</script>
</body>
</html>