<commit_before>/*
 * 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.server;

import static java.lang.String.format ;
import static org.apache.jena.fuseki.Fuseki.serverLog ;

import java.io.FileInputStream ;
import java.util.EnumSet ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;

import javax.servlet.http.HttpServlet ;

import org.apache.jena.fuseki.Fuseki ;
import org.apache.jena.fuseki.FusekiException ;
import org.apache.jena.fuseki.mgt.ActionDataset ;
import org.apache.jena.fuseki.mgt.MgtFunctions ;
import org.apache.jena.fuseki.mgt.PageNames ;
import org.apache.jena.fuseki.servlets.* ;
import org.apache.jena.fuseki.validation.DataValidator ;
import org.apache.jena.fuseki.validation.IRIValidator ;
import org.apache.jena.fuseki.validation.QueryValidator ;
import org.apache.jena.fuseki.validation.UpdateValidator ;
import org.eclipse.jetty.http.MimeTypes ;
import org.eclipse.jetty.server.Connector ;
import org.eclipse.jetty.server.Server ;
import org.eclipse.jetty.server.nio.BlockingChannelConnector ;
import org.eclipse.jetty.servlet.DefaultServlet ;
import org.eclipse.jetty.servlet.ServletContextHandler ;
import org.eclipse.jetty.servlet.ServletHolder ;
import org.eclipse.jetty.xml.XmlConfiguration ;
import org.openjena.riot.WebContent ;

import org.eclipse.jetty.server.DispatcherType;
import org.eclipse.jetty.servlets.GzipFilter;


import com.hp.hpl.jena.sparql.util.Utils ;

public class SPARQLServer
{
    static { Fuseki.init() ; }
    
    private ServerConfig serverConfig ;
    
    private Server server = null ;
    private boolean verbose = false ;
    //private static int ThreadPoolSize = 100 ;
    
    public SPARQLServer(ServerConfig config)
    {
        this.serverConfig = config ;  
        
        // GZip compression
        // Note that regardless of this setting we'll always leave it turned off for the servlets
        // where it makes no sense to have it turned on e.g. update and upload
        
        ServletContextHandler context = buildServer(serverConfig.jettyConfigFile, config.enableCompression) ;
        // Build them all.
        for ( DatasetRef sDesc : serverConfig.services )
            configureOneDataset(context, sDesc,  config.enableCompression) ;
    }
    
    public void start()
    {
        String now = Utils.nowAsString() ;
        //serverLog.info(format("%s %s", Fuseki.NAME, Fuseki.VERSION)) ;
        serverLog.info(format("%s %s %s", Fuseki.NAME, Fuseki.VERSION, Fuseki.BUILD_DATE)) ;
        String jettyVersion = org.eclipse.jetty.server.Server.getVersion() ;
        serverLog.info(format("Jetty %s",jettyVersion)) ;
        String host = server.getConnectors()[0].getHost();
        if (host != null)
            serverLog.info("Incoming connections limited to " + host);
        serverLog.info(format("Started %s on port %d", now, server.getConnectors()[0].getPort())) ;

        try { server.start() ; }
        catch (java.net.BindException ex)
        { serverLog.error("SPARQLServer: Failed to start server: " + ex.getMessage()) ; System.exit(1) ; }
        catch (Exception ex)
        { serverLog.error("SPARQLServer: Failed to start server: " + ex.getMessage(), ex) ; System.exit(1) ; }
        
        ServletContextHandler context = (ServletContextHandler)server.getHandler() ;
    }

    public void stop()
    {
        String now = Utils.nowAsString() ;
        serverLog.info(format("Stopped %s on port %d", now, server.getConnectors()[0].getPort())) ;
        try { server.stop() ; }
        catch (Exception ex)
        { Fuseki.serverLog.warn("SPARQLServer: Exception while stopping server: " + ex.getMessage(), ex) ; }
    }
    
    public Server getServer() { return server ; }
    public List<DatasetRef> getDatasets() { return serverConfig.services ; }
    
    // Later : private and in constructor.
    private ServletContextHandler buildServer(String jettyConfig, boolean enableCompression)
    {
        if ( jettyConfig != null )
        {
            // --jetty-config=jetty-fuseki.xml
            // for detailed configuration of the server using Jetty features. 
            server = configServer(jettyConfig) ;
        }
        else 
            server = defaultServerConfig(serverConfig.port) ; <commit_msg>Add accessor for the server config.<commit_after>/*
 * 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.server;

import static java.lang.String.format ;
import static org.apache.jena.fuseki.Fuseki.serverLog ;

import java.io.FileInputStream ;
import java.util.EnumSet ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;

import javax.servlet.http.HttpServlet ;

import org.apache.jena.fuseki.Fuseki ;
import org.apache.jena.fuseki.FusekiException ;
import org.apache.jena.fuseki.mgt.ActionDataset ;
import org.apache.jena.fuseki.mgt.MgtFunctions ;
import org.apache.jena.fuseki.mgt.PageNames ;
import org.apache.jena.fuseki.servlets.* ;
import org.apache.jena.fuseki.validation.DataValidator ;
import org.apache.jena.fuseki.validation.IRIValidator ;
import org.apache.jena.fuseki.validation.QueryValidator ;
import org.apache.jena.fuseki.validation.UpdateValidator ;
import org.eclipse.jetty.http.MimeTypes ;
import org.eclipse.jetty.server.Connector ;
import org.eclipse.jetty.server.Server ;
import org.eclipse.jetty.server.nio.BlockingChannelConnector ;
import org.eclipse.jetty.servlet.DefaultServlet ;
import org.eclipse.jetty.servlet.ServletContextHandler ;
import org.eclipse.jetty.servlet.ServletHolder ;
import org.eclipse.jetty.xml.XmlConfiguration ;
import org.openjena.riot.WebContent ;

import org.eclipse.jetty.server.DispatcherType;
import org.eclipse.jetty.servlets.GzipFilter;


import com.hp.hpl.jena.sparql.util.Utils ;

public class SPARQLServer
{
    static { Fuseki.init() ; }
    
    private ServerConfig serverConfig ;
    
    private Server server = null ;
    private boolean verbose = false ;
    //private static int ThreadPoolSize = 100 ;
    
    public SPARQLServer(ServerConfig config)
    {
        this.serverConfig = config ;  
        
        // GZip compression
        // Note that regardless of this setting we'll always leave it turned off for the servlets
        // where it makes no sense to have it turned on e.g. update and upload
        
        ServletContextHandler context = buildServer(serverConfig.jettyConfigFile, config.enableCompression) ;
        // Build them all.
        for ( DatasetRef sDesc : serverConfig.services )
            configureOneDataset(context, sDesc,  config.enableCompression) ;
    }
    
    public void start()
    {
        String now = Utils.nowAsString() ;
        //serverLog.info(format("%s %s", Fuseki.NAME, Fuseki.VERSION)) ;
        serverLog.info(format("%s %s %s", Fuseki.NAME, Fuseki.VERSION, Fuseki.BUILD_DATE)) ;
        String jettyVersion = org.eclipse.jetty.server.Server.getVersion() ;
        serverLog.info(format("Jetty %s",jettyVersion)) ;
        String host = server.getConnectors()[0].getHost();
        if (host != null)
            serverLog.info("Incoming connections limited to " + host);
        serverLog.info(format("Started %s on port %d", now, server.getConnectors()[0].getPort())) ;

        try { server.start() ; }
        catch (java.net.BindException ex)
        { serverLog.error("SPARQLServer: Failed to start server: " + ex.getMessage()) ; System.exit(1) ; }
        catch (Exception ex)
        { serverLog.error("SPARQLServer: Failed to start server: " + ex.getMessage(), ex) ; System.exit(1) ; }
        
        ServletContextHandler context = (ServletContextHandler)server.getHandler() ;
    }

    public void stop()
    {
        String now = Utils.nowAsString() ;
        serverLog.info(format("Stopped %s on port %d", now, server.getConnectors()[0].getPort())) ;
        try { server.stop() ; }
        catch (Exception ex)
        { Fuseki.serverLog.warn("SPARQLServer: Exception while stopping server: " + ex.getMessage(), ex) ; }
    }
    
    public Server getServer() { return server ; }
    public List<DatasetRef> getDatasets() { return serverConfig.services ; }
    
    public ServerConfig getServerConfig()
    {
        return serverConfig ;
    }

    // Later : private and in constructor.
    private ServletContextHandler buildServer(String jettyConfig, boolean enableCompression)
    {
        if ( jettyConfig != null )
        {
            // --jetty-config=jetty-fuseki.xml
            // for detailed configuration of the server using Jetty features. 
            server = configServer(jettyConfig) ;
        }
        else 
            server = defaultServerConfig(serverConfig.port) ; 
{'fraction_non_alphanumeric': 0.10165832597389854, 'fraction_numerical': 0.0023550191345304682, 'mean_word_length': 3.16, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465593', 'n_tokens_mistral': 2944, 'n_tokens_neox': 2972, 'n_words': 764}